add method for rendering img in cell

This commit is contained in:
Pawel Felcyn 2023-04-03 15:29:22 +02:00
parent 5976f41f12
commit 9f0cdbc5ff

View File

@ -1,3 +1,4 @@
from typing import Tuple
import pygame import pygame
from PIL import Image from PIL import Image
@ -8,6 +9,14 @@ class GameContext:
dust_car_pygame = None dust_car_pygame = None
dust_car_pil = None dust_car_pil = None
canvas = None canvas = None
_cell_size: int = 30
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))
def startup(game_context: GameContext): def startup(game_context: GameContext):
render_background(game_context) render_background(game_context)