sztuczna_inteligencja_2023_.../gameContext.py
2023-05-13 23:06:42 +02:00

37 lines
1000 B
Python

from typing import Tuple, List, Dict
import pygame
from PIL import Image
from gridCellType import GridCellType
class GameContext:
dust_car_speed = 20
dust_car_position_x = 0
dust_car_position_y = 0
dust_car_pygame = None
dust_car_pil = None
canvas = None
_cell_size: int = 30
city = None
grid: Dict[Tuple[int, int], GridCellType] = {}
dust_car = None
landfill = None
def __init__(self) -> None:
self._init_grid()
def _init_grid(self) -> None:
for i in range(1, 28):
for j in range(1, 28):
self.grid[(i, j)] = GridCellType.NOTHING
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))