sztuczna_inteligencja_2023_.../startup.py

79 lines
2.6 KiB
Python
Raw Normal View History

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-05-13 19:30:00 +02:00
from speedBump import SpeedBump
2023-05-11 20:12:41 +02:00
from landfill import Landfill
2023-04-23 15:37:22 +02:00
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
2023-05-11 20:12:41 +02:00
_create_landfill(game_context)
2023-04-22 16:36:13 +02:00
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:40:34 +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-05-13 19:30:00 +02:00
bumps = create_speed_bumps()
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:
2023-05-13 23:06:42 +02:00
city.add_can(t)
2023-05-13 19:30:00 +02:00
for b in bumps:
city.add_bump(b)
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)))
2023-05-11 20:12:41 +02:00
return trashcans
2023-05-13 19:30:00 +02:00
def create_speed_bumps() -> List[SpeedBump]:
bumps = []
2023-05-13 19:41:19 +02:00
bumps.append(SpeedBump((10, 9)))
2023-05-13 19:30:00 +02:00
bumps.append(SpeedBump((12, 16)))
return bumps
2023-05-11 20:12:41 +02:00
def _create_landfill(game_context: GameContext) -> None:
landfil_position = (23,24)
landfill = Landfill(landfil_position)
game_context.landfill = landfill
landfill.render(game_context)