2023-04-03 19:26:56 +02:00
|
|
|
from gameContext import GameContext
|
|
|
|
from city import City
|
|
|
|
from PIL import Image
|
|
|
|
import pygame
|
|
|
|
from typing import Tuple, List
|
|
|
|
from street import Street, StreetType
|
2023-04-22 16:36:13 +02:00
|
|
|
from garbageTruck import GarbageTruck
|
2023-04-23 15:37:22 +02:00
|
|
|
from garbageCan import GarbageCan
|
|
|
|
|
2023-04-03 19:26:56 +02:00
|
|
|
|
|
|
|
def startup(game_context: GameContext):
|
|
|
|
render_background(game_context)
|
|
|
|
game_context.city = create_city()
|
|
|
|
game_context.city.render_city(game_context)
|
2023-04-22 16:36:13 +02:00
|
|
|
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))
|
2023-04-03 19:26:56 +02:00
|
|
|
|
|
|
|
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:
|
2023-04-23 15:37:22 +02:00
|
|
|
city: City = City()
|
2023-04-03 19:26:56 +02:00
|
|
|
streets = create_streets()
|
2023-04-23 15:37:22 +02:00
|
|
|
trashcans = create_trashcans()
|
2023-04-03 19:26:56 +02:00
|
|
|
for s in streets:
|
|
|
|
city.add_street(s)
|
2023-04-23 15:37:22 +02:00
|
|
|
for t in trashcans:
|
|
|
|
city.add_node(t)
|
2023-04-03 19:26:56 +02:00
|
|
|
return city
|
|
|
|
|
|
|
|
def create_streets() -> List[Street]:
|
|
|
|
streets = []
|
2023-04-03 19:51:06 +02:00
|
|
|
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))
|
2023-04-23 15:37:22 +02:00
|
|
|
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
|