sztuczna_inteligencja_2023_.../gameEventHandler.py

25 lines
1.4 KiB
Python
Raw Normal View History

2023-03-09 19:44:02 +01:00
import pygame
2023-03-12 16:08:54 +01:00
from gameContext import GameContext
2023-03-09 19:44:02 +01:00
2023-03-12 16:08:54 +01:00
def handle_game_event(event, game_context: GameContext):
2023-03-12 16:47:18 +01:00
dust_car_movement(event, game_context)
2023-03-12 16:08:54 +01:00
return
2023-03-12 16:47:18 +01:00
def dust_car_movement(event, game_context:GameContext):
if event.type != pygame.KEYDOWN:
return
(width, height) = game_context.stick_man_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
elif event.key == pygame.K_RIGHT:
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
elif event.key == pygame.K_UP:
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
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))