sztuczna_inteligencja_2023_.../gameContext.py

37 lines
1000 B
Python
Raw Normal View History

2023-04-22 12:04:08 +02:00
from typing import Tuple, List, Dict
2023-03-12 16:47:18 +01:00
import pygame
2023-04-03 15:08:26 +02:00
from PIL import Image
2023-04-22 12:04:08 +02:00
from gridCellType import GridCellType
2023-03-12 16:47:18 +01:00
2023-03-12 16:08:54 +01:00
class GameContext:
2023-03-12 16:47:18 +01:00
dust_car_speed = 20
2023-03-12 16:08:54 +01:00
dust_car_position_x = 0
dust_car_position_y = 0
dust_car_pygame = None
dust_car_pil = None
2023-03-12 16:47:18 +01:00
canvas = None
2023-04-03 15:29:22 +02:00
_cell_size: int = 30
2023-04-03 19:26:56 +02:00
city = None
2023-04-22 12:04:08 +02:00
grid: Dict[Tuple[int, int], GridCellType] = {}
2023-04-22 16:36:13 +02:00
dust_car = None
2023-05-11 20:12:41 +02:00
landfill = None
2023-05-13 23:06:42 +02:00
2023-04-22 12:04:08 +02:00
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
2023-04-03 15:29:22 +02:00
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))
2023-03-12 16:47:18 +01:00
2023-04-03 15:08:26 +02:00