changed stick man to dust car, renamed variables

This commit is contained in:
majkellll 2023-03-13 08:49:34 +01:00
parent 4c385d0674
commit 58437a4854
4 changed files with 8 additions and 8 deletions

View File

@ -4,9 +4,9 @@ class GameContext:
dust_car_speed = 20 dust_car_speed = 20
dust_car_position_x = 0 dust_car_position_x = 0
dust_car_position_y = 0 dust_car_position_y = 0
stick_man_pygame = None dust_car_pygame = None
stick_man_pil = None dust_car_pil = None
canvas = None canvas = None
def startup(game_context: GameContext): def startup(game_context: GameContext):
game_context.canvas.blit(game_context.stick_man_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y)) game_context.canvas.blit(game_context.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))

View File

@ -8,7 +8,7 @@ def handle_game_event(event, game_context: GameContext):
def dust_car_movement(event, game_context:GameContext): def dust_car_movement(event, game_context:GameContext):
if event.type != pygame.KEYDOWN: if event.type != pygame.KEYDOWN:
return return
(width, height) = game_context.stick_man_pil.size (width, height) = game_context.dust_car_pil.size
if event.key == pygame.K_LEFT: if event.key == pygame.K_LEFT:
pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height)) pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height))
game_context.dust_car_position_x -= game_context.dust_car_speed game_context.dust_car_position_x -= game_context.dust_car_speed
@ -21,4 +21,4 @@ def dust_car_movement(event, game_context:GameContext):
elif event.key == pygame.K_DOWN: elif event.key == pygame.K_DOWN:
pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height)) pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height))
game_context.dust_car_position_y += game_context.dust_car_speed game_context.dust_car_position_y += game_context.dust_car_speed
game_context.canvas.blit(game_context.stick_man_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y)) game_context.canvas.blit(game_context.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

View File

@ -9,11 +9,11 @@ pygame.init()
canvas = pygame.display.set_mode((800, 800)) canvas = pygame.display.set_mode((800, 800))
pygame.display.set_caption("Inteligentna śmieciarka") pygame.display.set_caption("Inteligentna śmieciarka")
stick_man_pil = Image.open('imgs/stickMan.jpg') dust_car_pil = Image.open('imgs/dust_car.png')
game_context = GameContext() game_context = GameContext()
game_context.stick_man_pil = stick_man_pil game_context.dust_car_pil = dust_car_pil
game_context.stick_man_pygame = pygame.image.frombuffer(stick_man_pil.tobytes(), stick_man_pil.size, 'RGB') game_context.dust_car_pygame = pygame.image.frombuffer(dust_car_pil.tobytes(), dust_car_pil.size, 'RGB')
game_context.canvas = canvas game_context.canvas = canvas
startup(game_context) startup(game_context)