79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
from gameContext import GameContext
|
|
from city import City
|
|
from PIL import Image
|
|
import pygame
|
|
from typing import Tuple, List
|
|
from street import Street, StreetType
|
|
from garbageTruck import GarbageTruck
|
|
from garbageCan import GarbageCan
|
|
from speedBump import SpeedBump
|
|
from landfill import Landfill
|
|
|
|
|
|
def startup(game_context: GameContext):
|
|
render_background(game_context)
|
|
game_context.city = create_city()
|
|
game_context.city.render_city(game_context)
|
|
car = create_dust_car(game_context)
|
|
car.render(game_context)
|
|
game_context.dust_car = car
|
|
_create_landfill(game_context)
|
|
|
|
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")
|
|
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()
|
|
trashcans = create_trashcans()
|
|
bumps = create_speed_bumps()
|
|
for s in streets:
|
|
city.add_street(s)
|
|
for t in trashcans:
|
|
city.add_can(t)
|
|
for b in bumps:
|
|
city.add_bump(b)
|
|
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
|
|
|
|
def create_trashcans() -> List[GarbageCan]:
|
|
trashcans = []
|
|
trashcans.append(GarbageCan((9, 4)))
|
|
trashcans.append(GarbageCan((9, 15)))
|
|
trashcans.append(GarbageCan((12, 22)))
|
|
trashcans.append(GarbageCan((3, 24)))
|
|
trashcans.append(GarbageCan((17, 9)))
|
|
trashcans.append(GarbageCan((24, 17)))
|
|
trashcans.append(GarbageCan((26, 4)))
|
|
return trashcans
|
|
|
|
def create_speed_bumps() -> List[SpeedBump]:
|
|
bumps = []
|
|
bumps.append(SpeedBump((10, 9)))
|
|
bumps.append(SpeedBump((12, 16)))
|
|
return bumps
|
|
|
|
|
|
def _create_landfill(game_context: GameContext) -> None:
|
|
landfil_position = (23,24)
|
|
landfill = Landfill(landfil_position)
|
|
game_context.landfill = landfill
|
|
landfill.render(game_context) |