def tile_status_changed(self, status: SpaceStatusEnum, is_hotspot: bool): new_surf = pygame.Surface([ self._non_highlight_image.get_width(), self._non_highlight_image.get_height() ]) self._non_highlight_image = self._blank_image.copy() new_surf = pygame.Surface.convert_alpha(new_surf) new_surf.fill((0, 0, 0, 0), None, pygame.BLEND_RGBA_MULT) if status == SpaceStatusEnum.FIRE: image_file = FileImporter.import_image( "media/All Markers/fire.png") new_surf.blit(image_file, (0, 0)) elif status == SpaceStatusEnum.SMOKE: image_file = FileImporter.import_image( "media/All Markers/smoke.png") new_surf.blit(image_file, (0, 0)) if is_hotspot: hs_img = FileImporter.import_image( "media/all_markers/hot_spot.png") new_surf.blit(hs_img, (0, 0)) self._non_highlight_image.blit(new_surf, (0, 0))
def __init__(self, poi: POIModel): super().__init__() self.image = FileImporter.import_image('media/all_markers/poi128.png') self.small_image = FileImporter.import_image( "media/all_markers/poi.png") self.rect = self.image.get_rect() self.poi_model = poi self.row = poi.row self.column = poi.column self.poi_model.add_observer(self) self.tile_sprite = GameBoard.instance().grid.grid[poi.column][poi.row] self.counter = 80
def _render(self): # If self.background is an instance of Tuple, we assign that RGB tuple as the background color # Otherwise, self.background is an imported image (Surface) so we try to import it and assign as the background self.image = pygame.Surface([self.width, self.height]) self.rect = self.image.get_rect() if isinstance(self.background, Tuple): self.rect = pygame.draw.rect(self.image, self.background, self.rect, self.outer_width) else: self.rect = pygame.draw.rect(self.image, (0, 0, 0), self.rect, self.outer_width) image_file = FileImporter.import_image(self.background) image_file = pygame.transform.scale(image_file, (self.width, self.height)) self.image.blit(image_file, (0, 0)) pygame.draw.rect(self.image, Color.YELLOW, [0, 0, self.width, self.height], 11) self.rect.x = self.x self.rect.y = self.y for btn in self._btn_list: # Not ideal but the only way I know to re-render btn._render() for s in self._stats_list: s._render()
def player_role_changed(self, role: PlayerRoleEnum): if self.associated_player.role == PlayerRoleEnum.DOGE: self.associated_png = 'media/all_markers/DogePlayer.png' else: self.associated_png = self._associate_image(self.associated_player.color) self.image = FileImporter.import_image(self.associated_png)
def victim_state_changed(self, state: VictimStateEnum): if state == VictimStateEnum.LOST: self.kill() elif state == VictimStateEnum.RESCUED: self.kill() elif state == VictimStateEnum.TREATED: treat = FileImporter.import_image("media/all_markers/treated.png") self.image.blit(treat, (0, 0))
def __init__(self, row: int, column: int): super().__init__() self.image = FileImporter.import_image("media/all_markers/victim.png") self.rect = self.image.get_rect() self.row = row self.column = column self.tile_sprite = GameBoard.instance().grid.grid[column][row]
def __init__(self, poi: POIModel): super().__init__() self.image = FileImporter.import_image( "media/all_markers/false_alarm.png") self.rect = self.image.get_rect() self.poi_model = poi self.row = poi.row self.column = poi.column self.tile_sprite = GameBoard.instance().grid.grid[poi.column][poi.row]
def __init__(self, orientation: VehicleOrientationEnum, tile_sprite: TileSprite): super().__init__() self.image = FileImporter.import_image("media/Vehicles/Ambulance.png") self.rect = self.image.get_rect() self.tile_sprite = tile_sprite self.row = tile_sprite.row self.column = tile_sprite.column self.orientation = orientation if self.orientation == VehicleOrientationEnum.VERTICAL: self.image = pygame.transform.rotate(self.image, 90) self.rect = self.image.get_rect()
def __init__(self, current_player: PlayerModel, tile_model: TileModel, grid: GridSprite): super().__init__() self.grid = grid self.tile_model = tile_model self.tile_sprite = grid.grid[tile_model.column][tile_model.row] self.rect = self.tile_sprite.rect self.associated_player = current_player self.associated_player.add_observer(self) if self.associated_player.role == PlayerRoleEnum.DOGE: self.associated_png = 'media/all_markers/DogePlayer.png' else: self.associated_png = self._associate_image(self.associated_player.color) self.image = FileImporter.import_image(self.associated_png)
def __init__(self, current_player: PlayerModel): if GameBoard._instance: raise Exception("GameBoard is a singleton") super().__init__() self.image = pygame.Surface( (MainConst.SCREEN_RESOLUTION[0], MainConst.SCREEN_RESOLUTION[1])) self.rect = self.image.get_rect() self.grid = GridSprite(x_coord=self.rect.left, y_coord=self.rect.top, current_player=current_player) self.background = FileImporter.import_image( "media/backgrounds/WoodBack.jpeg") self.top_ui = pygame.sprite.Group() GameBoard._instance = self
def _render(self): self.image = pygame.Surface([self.width, self.height]) self.rect = self.image.get_rect() self.rect.x = self.x self.rect.y = self.y if isinstance(self.background, Tuple): pygame.draw.ellipse(self.image, self.background, self.rect, self.outer_width) else: self.image = self.image.convert_alpha(pygame.display.get_surface()) self.image.fill((0, 0, 0, 0), None, pygame.BLEND_RGBA_MULT) image_file = FileImporter.import_image(self.background) self.image.blit(image_file, self.image) if self.txt_obj: self.txt_obj.set_pos(self.rect, self.txt_pos) self.image.blit(self.txt_obj.text_surf, self.txt_obj.text_rect)
def __init__(self, filename: str, cols: int, rows: int): try: self._sheet = FileImporter.import_image(filename) except pygame.error as e: print("Unable to load spritesheet image:", filename) raise e self._num_cols = cols self._num_rows = rows self._total_cells = cols * rows self.rect = self._sheet.get_rect() width = self._cell_width = int(self.rect.width / cols) height = self._cell_height = int(self.rect.height / rows) # Index to loop through the animation self._index = 0.0 # Create a list of rects self._cell_rects = [[(i * width, j * height, width, height) for i in range(cols)] for j in range(rows)] self.cell_images = self._load_images(self._cell_rects)
def __init__(self, tile_model: TileModel): super().__init__() self.grid: GridSprite = GameBoard.instance().grid self.tile_sprite = self.grid.grid[tile_model.column][tile_model.row] self.rect = self.tile_sprite.rect self.image = FileImporter.import_image("media/all_markers/hazmat.png")