import sys import pygame class Colors(): BLACK = 0, 0, 0 WHITE = 255, 255, 255 RED = 255, 0, 0 GREEN = 0, 255, 0 DEFAULT_COLOR = Colors.WHITE def default_color(func): def wrap(*args, **kwargs): if 'color' not in kwargs: kwargs['color'] = DEFAULT_COLOR result = func(*args, **kwargs) return result return wrap class GridDraw(): def __init__( self, width = None, height = None, tiles_x = None, tiles_y = None, background = None ): self.width = width if width != None else 100 self.height = height if height != None else 100 self.tiles_x = tiles_x if tiles_x != None else 10 self.tiles_y = tiles_y if tiles_y != None else 10 self.tile_width = self.width / self.tiles_x self.tile_height = self.height / self.tiles_y self.background = background if background != None else Colors.BLACK self.sprites = { 'VACUUM': pygame.transform.scale(pygame.image.load('media/sprites/vacuum.png'), (self.tile_width, self.tile_height)), 'WALL': pygame.transform.scale(pygame.image.load('media/sprites/wall.png'), (self.tile_width, self.tile_height)), 'TILE': pygame.transform.scale(pygame.image.load('media/sprites/tile.jpeg'), (self.tile_width, self.tile_height)), 'PEEL': pygame.transform.scale(pygame.image.load('media/sprites/peel.webp'), (self.tile_width, self.tile_height)), } pygame.init() self.screen = pygame.display.set_mode((self.width, self.height)) def start_draw(self): self.screen.fill(Colors.BLACK) def end_draw(self, delay = None): pygame.display.flip() delay = delay if delay != None else 10 pygame.time.delay(delay) @default_color def line(self, x_1, y_1, x_2, y_2, color = None): pygame.draw.line(self.screen, color, (x_1, y_1), (x_2, y_2)) @default_color def board(self, tiles_x = None, tiles_y = None, color = None): tiles_x = tiles_x if tiles_x != None else self.tiles_x tiles_y = tiles_y if tiles_y != None else self.tiles_y tiles_width = self.width / tiles_x tiles_height = self.height / tiles_y for i in range(1, tiles_x): self.line(tiles_width * i, 0, tiles_width * i, self.height, color=color) for i in range(1, tiles_y): self.line(0, tiles_height * i, self.width, tiles_height * i, color=color) @default_color def circle(self, x, y, radius, color = None): pygame.draw.circle(self.screen, color, (x, y), radius) def draw_sprite(self, tile_x, tile_y, sprite): self.screen.blit( self.sprites[sprite], (tile_x * self.tile_width, tile_y * self.tile_height) ) def fill_grid_with_sprite(self, sprite): for tile_x in range(self.tiles_x): for tile_y in range(self.tiles_y): self.draw_sprite(tile_x, tile_y, sprite)