Merge pull request 'changed stick man to dust car, renamed variables' (#5) from changing_stick_man_to_dust_car into master

Reviewed-on: #5
This commit is contained in:
Paweł Felcyn 2023-03-13 09:53:56 +01:00
commit dd54ef193f
4 changed files with 8 additions and 8 deletions

View File

@ -4,9 +4,9 @@ class GameContext:
dust_car_speed = 20
dust_car_position_x = 0
dust_car_position_y = 0
stick_man_pygame = None
stick_man_pil = None
dust_car_pygame = None
dust_car_pil = None
canvas = None
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):
if event.type != pygame.KEYDOWN:
return
(width, height) = game_context.stick_man_pil.size
(width, height) = game_context.dust_car_pil.size
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))
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:
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.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))
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.stick_man_pil = stick_man_pil
game_context.stick_man_pygame = pygame.image.frombuffer(stick_man_pil.tobytes(), stick_man_pil.size, 'RGB')
game_context.dust_car_pil = dust_car_pil
game_context.dust_car_pygame = pygame.image.frombuffer(dust_car_pil.tobytes(), dust_car_pil.size, 'RGB')
game_context.canvas = canvas
startup(game_context)