bfs #19
@ -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()
|
||||
|
@ -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
|
@ -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)
|
||||
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)
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user