Пример #1
0
    def explosion(self, origin_tile: TileModel):
        FileImporter.play_music(EXPLOSION_SOUND, 1)
        logger.info(f"Explosion occurred on {origin_tile}")
        game_state = GameStateModel.instance()
        tile_sprite = GameBoard.instance().grid.grid[origin_tile.column][
            origin_tile.row]
        tile_sprite.explosion = True

        for direction, obstacle in origin_tile.adjacent_edge_objects.items():
            # fire does not move to the neighbouring tile
            # damaging wall present along the tile
            if isinstance(
                    obstacle, WallModel
            ) and obstacle.wall_status != WallStatusEnum.DESTROYED:
                obstacle.inflict_damage()
                game_state.damage = game_state.damage + 1

            # fire does not move to the neighbouring tile
            # removing door that borders the tile
            elif isinstance(obstacle, DoorModel):
                obstacle.destroy_door()

            # fire can move to the neighbouring tile
            # if the neighbouring tile is on fire, a shockwave is created
            # else it is just set on fire.
            else:
                nb_tile = origin_tile.get_tile_in_direction(direction)
                if not isinstance(nb_tile, NullModel):
                    if nb_tile.space_status == SpaceStatusEnum.FIRE:
                        self.shockwave(nb_tile, direction)
                    else:
                        nb_tile.space_status = SpaceStatusEnum.FIRE
Пример #2
0
    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))
Пример #3
0
    def execute(self, *args, **kwargs):
        logger.info("Executing Fire Deck Gun Event")

        self.game: GameStateModel = GameStateModel.instance()

        if isinstance(self.target_tile, NullModel):
            self._set_target_tile()

        self.target_tile.space_status = SpaceStatusEnum.SAFE

        FileImporter.play_music(SPLASH_SOUND, 1)
        tile_sprite = GameBoard.instance().grid.grid[self.target_tile.column][
            self.target_tile.row]
        tile_sprite.fire_deck_gun = True

        directions = ["North", "East", "West", "South"]
        for dirn in directions:
            has_obstacle = self.target_tile.has_obstacle_in_direction(dirn)
            obstacle = self.target_tile.get_obstacle_in_direction(dirn)
            # If there is no obstacle in the given direction or there is an
            # open door, set the status of the space in that direction to Safe.
            if not has_obstacle or (isinstance(obstacle, DoorModel) and obstacle.door_status == DoorStatusEnum.OPEN)\
                    or (isinstance(obstacle, WallModel) and obstacle.wall_status == WallStatusEnum.DESTROYED):
                nb_tile: TileModel = self.target_tile.get_tile_in_direction(
                    dirn)
                nb_tile.space_status = SpaceStatusEnum.SAFE
                tile_sprite = GameBoard.instance().grid.grid[nb_tile.column][
                    nb_tile.row]
                tile_sprite.fire_deck_gun = True

        if self.player.role == PlayerRoleEnum.DRIVER:
            self.player.ap = self.player.ap - 2
        else:
            self.player.ap = self.player.ap - 4
Пример #4
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
Пример #5
0
    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()
Пример #6
0
 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))
Пример #7
0
    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)
Пример #8
0
        def next(self, next_scene: callable, *args):
            """Switch to the next logical scene. args is assumed to be: [SceneClass]
                Its not pretty, but it makes sure that ONLY THE CURRENT SCENE EXISTS IN THE GAME STATE

                Basically, Nuri, when you need to make a new scene, add it here as a condition.
                The way it works is that if an argument was passed, it assumes the argument is a reference to a class
                (not object!! JoinScene vs JoinScene()). It then instantiates the class.

                Then, all the conditions are checked. If there were no args, instantiate the next scene, otherwise use
                the one in args (next_scene). Then, attach all your buttons for that scene.
            """
            # Step one: Create the next scene.
            if args and isinstance(args[0], PlayerModel):
                self._current_player = args[0]
            self._active_scene = next_scene(self.screen, *args)

            FileImporter.play_audio(BUTTON_CLICK_SOUND, fade_ms=10)
Пример #9
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]
Пример #10
0
 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]
Пример #11
0
    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()
Пример #12
0
    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)
Пример #13
0
 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
Пример #14
0
    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)
Пример #15
0
    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)
Пример #16
0
 def change_bg_image(self, file_path: str):
     if FileImporter.file_exists(file_path):
         self.background = file_path
         self._render()
     else:
         raise Exception("File not found!")
Пример #17
0
 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")