25 lines
1.4 KiB
Python
25 lines
1.4 KiB
Python
import pygame
|
|
from gameContext import GameContext
|
|
|
|
def handle_game_event(event, game_context: GameContext):
|
|
dust_car_movement(event, game_context)
|
|
return
|
|
|
|
def dust_car_movement(event, game_context:GameContext):
|
|
if event.type != pygame.KEYDOWN:
|
|
return
|
|
(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
|
|
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.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))
|