from typing import Tuple import pygame from PIL import Image 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 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): render_background(game_context) game_context.canvas.blit(game_context.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y)) 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))