diff --git a/gameContext.py b/gameContext.py index 37939b0..b454bd2 100644 --- a/gameContext.py +++ b/gameContext.py @@ -13,6 +13,7 @@ class GameContext: _cell_size: int = 30 city = None grid: Dict[Tuple[int, int], GridCellType] = {} + dust_car = None def __init__(self) -> None: self._init_grid() diff --git a/gameEventHandler.py b/gameEventHandler.py index 479fb9e..85131c1 100644 --- a/gameEventHandler.py +++ b/gameEventHandler.py @@ -2,23 +2,4 @@ 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)) + pass \ No newline at end of file diff --git a/garbageTruck.py b/garbageTruck.py index 8f578d9..5584adc 100644 --- a/garbageTruck.py +++ b/garbageTruck.py @@ -1,6 +1,7 @@ from typing import List, Tuple - +from agentOrientation import AgentOrientation from garbage import RecognizedGarbage +from gameContext import GameContext class GarbageTruck: position: Tuple[int, int] @@ -9,8 +10,9 @@ class GarbageTruck: glass: List[RecognizedGarbage] bio: List[RecognizedGarbage] mixed: List[RecognizedGarbage] - truckSpritePath = 'imgs/dust_car.png' - def __init__(self, position: List[int, int]) -> None: + orientation: AgentOrientation = AgentOrientation.RIGHT + + def __init__(self, position: Tuple[int, int]) -> None: self.position = position self.paper = [] self.plastic_and_metal = [] @@ -33,4 +35,16 @@ class GarbageTruck: self.bio.append(RecognizedGarbage) elif RecognizedGarbage.garbage_type == 5: - self.mixed.append(RecognizedGarbage) \ No newline at end of file + self.mixed.append(RecognizedGarbage) + + def render(self, game_context: GameContext) -> None: + path = None + if self.orientation == AgentOrientation.LEFT: + path = 'imgs/dust_car_left.png' + elif self.orientation == AgentOrientation.RIGHT: + path = 'imgs/dust_car_right.png' + elif self.orientation == AgentOrientation.UP: + path = 'imgs/dust_car_up.png' + elif self.orientation == AgentOrientation.DOWN: + path = 'imgs/dust_car_down.png' + game_context.render_in_cell(self.position, path) \ No newline at end of file diff --git a/startup.py b/startup.py index 64fe804..607bb9f 100644 --- a/startup.py +++ b/startup.py @@ -4,12 +4,18 @@ from PIL import Image import pygame from typing import Tuple, List from street import Street, StreetType +from garbageTruck import GarbageTruck def startup(game_context: GameContext): render_background(game_context) game_context.city = create_city() game_context.city.render_city(game_context) - game_context.canvas.blit(game_context.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y)) + car = create_dust_car(game_context) + car.render(game_context) + game_context.dust_car = car + +def create_dust_car(game_context: GameContext) -> GarbageTruck: + return GarbageTruck((3, 3)) def render_background(game_context: GameContext): bg_img = Image.open("imgs/background.jpg")