Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Moving tutorial

This is code to moving block in one part made with pygame.

It's written simply in one function to avoid confusion and to give idea to make basic games like snake game.

Code:-

import pygame

pygame.init()

dis = pygame.display.set_mode((500, 500))

caption = pygame.display.set_caption('mooooove')

x = 100

y = 100

xx_change = 0

yy_change = 0

clock = pygame.time.Clock()

run = True

while run :

    

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            run = False

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_DOWN:

                yy_change = 10

                xx_change = 0

            if event.key == pygame.K_UP:

                yy_change = -10

                xx_change = 0

            if event.key == pygame.K_LEFT:

                yy_change = 0

                xx_change = -10

            if event.key == pygame.K_RIGHT:

                yy_change = 0

                xx_change = 10

    x += xx_change

    y += yy_change

    dis.fill((225, 225, 225))

    pygame.draw.rect(dis, (0, 225, 225), (x, y, 10, 10))

    

    pygame.display.update()

    

    clock.tick(10)

pygame.quit()

It is a guide for beginners to make simple games .

Colors are written in RGB format.

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.