Compare commits

..

No commits in common. "984140687848615101d1cf6c05fb8a0b2ef0397d" and "5976f41f12164eee328d03214692c377d513c765" have entirely different histories.

7 changed files with 27 additions and 87 deletions

32
city.py
View File

@ -1,19 +1,17 @@
from typing import List
from typing import List, Tuple
from garbageCan import GarbageCan
from street import Street
from gameContext import GameContext
class Node:
garbageCan: GarbageCan
id: int
def __init__(self, id: int, can: GarbageCan) -> None:
self.id
self.id = id
self.can = can
class City:
nodes: List[Node]
streets: List[Street]
streets: List[Tuple[int, int]]
def __init__(self) -> None:
self.nodes = []
@ -22,12 +20,20 @@ class City:
def add_node(self, node: Node) -> None:
self.nodes.append(node)
def add_street(self, street: Street) -> None:
self.streets.append(street)
def add_street(self, street: Tuple[int, int]) -> None:
firstFound: bool = False
secondFound: bool = False
def render_city(self, game_context: GameContext) -> None:
self._render_streets(game_context)
def _render_streets(self, game_context: GameContext) -> None:
for street in self.streets:
street.render(game_context)
for node in self.nodes:
if firstFound and secondFound:
break
if node.id == street.__getitem__(0):
firstFound = True
continue
if node.id == street.__getitem__(1):
secondFound = True
if not firstFound or not secondFound:
return
self.streets.append(street)

View File

@ -1,4 +1,3 @@
from typing import Tuple, List
import pygame
from PIL import Image
@ -9,14 +8,12 @@ class GameContext:
dust_car_pygame = None
dust_car_pil = None
canvas = None
_cell_size: int = 30
city = None
def render_in_cell(self, cell: Tuple[int, int], img_path: str):
img = Image.open(img_path)
pygame_img = pygame.image.frombuffer(img.tobytes(), (self._cell_size,self._cell_size), 'RGB')
start_x = (cell[0] - 1) * self._cell_size
start_y = (cell[1] - 1) * self._cell_size
self.canvas.blit(pygame_img, (start_x, start_y))
def startup(game_context: GameContext):
render_background(game_context)
game_context.canvas.blit(game_context.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))
def render_background(game_context: GameContext):
bg_img = Image.open("imgs/background.jpg")
pygame_bg_image = pygame.image.frombuffer(bg_img.tobytes(), bg_img.size, 'RGB')
game_context.canvas.blit(pygame_bg_image, (0, 0))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 B

View File

@ -1,7 +1,7 @@
import pygame
from gameEventHandler import handle_game_event
from gameContext import GameContext
from startup import startup
from gameContext import startup
from PIL import Image
pygame.init()

View File

@ -1,38 +0,0 @@
from gameContext import GameContext
from city import City
from PIL import Image
import pygame
from typing import Tuple, List
from street import Street, StreetType
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))
def render_background(game_context: GameContext):
bg_img = Image.open("imgs/background.jpg")
pygame_bg_image = pygame.image.frombuffer(bg_img.tobytes(), bg_img.size, 'RGB')
game_context.canvas.blit(pygame_bg_image, (0, 0))
def create_city() -> City:
city: City = City()
streets = create_streets()
for s in streets:
city.add_street(s)
return city
def create_streets() -> List[Street]:
streets = []
streets.append(Street(3, 30, 3, StreetType.HORIZONTAL))
streets.append(Street(4, 15, 10, StreetType.VERTICAL))
streets.append(Street(4, 10, 25, StreetType.VERTICAL))
streets.append(Street(11, 24, 10, StreetType.HORIZONTAL))
streets.append(Street(4, 9, 18, StreetType.VERTICAL))
streets.append(Street(1, 30, 16, StreetType.HORIZONTAL))
streets.append(Street(17, 30, 2, StreetType.VERTICAL))
streets.append(Street(3, 25, 23, StreetType.HORIZONTAL))
streets.append(Street(17, 30, 13, StreetType.VERTICAL))
streets.append(Street(17, 23, 25, StreetType.VERTICAL))
return streets

View File

@ -1,25 +0,0 @@
from enum import Enum
from typing import Tuple
from gameContext import GameContext
class StreetType (Enum):
VERTICAL = 0
HORIZONTAL = 1
class Street:
street_type: StreetType
start_cell: int
end_cell: int
row_or_column: int
def __init__(self, start_cell: int, end_cell: int, row_or_column: int, street_type: StreetType) -> None:
self.start_cell = start_cell
self.end_cell = end_cell
self.street_type = street_type
self.row_or_column = row_or_column
def render(self, game_context: GameContext) -> None:
for i in range(self.start_cell, self.end_cell + 1):
img_str: str = 'imgs/street_vertical.png' if self.street_type == StreetType.VERTICAL else 'imgs/street_horizontal.png'
cell: Tuple[int, int] = (self.row_or_column, i) if self.street_type == StreetType.VERTICAL else (i, self.row_or_column)
game_context.render_in_cell(cell, img_str)