示例#1
0
 def _on_start_timer_timeout(self):
     global_obj.player_stats.lives -= 1
     global_obj.game_started = True
     global_obj.game_paused = False
     global_obj.game_state = GameState.PLAYING
     game.delete_entity(entity_id="game_status_label")
     game.play_music(music_id="siren1")
示例#2
0
 def lives(self, value):
     previous_size = self._lives
     self._lives = value
     if self.is_in_valid_playing_state():
         if self._lives >= previous_size:
             for i in range(self._lives):
                 live_index = i
                 entity_index = f"{self.LIVES_ENTITY_ID}_{live_index}"
                 game.create_sprite_entity(
                     entity_id=entity_index,
                     texture_id="pacman-life",
                     position=(
                         36 + (36 * i),
                         global_obj.level_grid.board_position.y + 496
                     ),
                     layer=5,
                     width=16,
                     height=16,
                 )
         elif self._lives < previous_size:
             for i in range(previous_size - self._lives):
                 live_index = i + self._lives
                 entity_index = f"{self.LIVES_ENTITY_ID}_{live_index}"
                 index_id = entity_index
                 game.delete_entity(entity_id=index_id)
示例#3
0
 def _on_show_entities_timer_timeout(self):
     game.delete_entity(entity_id="player_one_display_label")
     self.set_all_entities_visibility(True)
示例#4
0
    def __process__(self, delta_time):
        if global_obj.game_started and not global_obj.game_paused:
            collided_entity_id, collider_tag = game.check_entity_collision(
                entity_id=self.entity_id, offset_position=(0, 0))
            if collided_entity_id:
                if collider_tag == "pellete":
                    game.delete_entity(entity_id=collided_entity_id)
                    global_obj.player_stats.score += 10
                    global_obj.player_stats.pelletes += 1
                    self.pellete_counter -= 1
                    game.play_sound(sound_id="pacman-chomp")
                elif collider_tag == "power_pellete":
                    game.delete_entity(entity_id=collided_entity_id)
                    global_obj.player_stats.score += 50
                    global_obj.player_stats.pelletes += 1
                    self.pellete_counter -= 1
                    self.ghost_eaten_score = 0
                    game.emit_signal(
                        entity_id=self.entity_id,
                        signal_id=self.power_pellete_eaten_signal_id,
                    )
                elif collider_tag == "enemy":
                    collided_ghost = scene_tree.get_entity(collided_entity_id)
                    if collided_ghost.state == State.FRIGHTENED:
                        if self.ghost_eaten_score == 0:
                            self.ghost_eaten_score = 200
                        else:
                            self.ghost_eaten_score *= 2
                        global_obj.player_stats.score += self.ghost_eaten_score
                        collided_ghost.eaten(self.ghost_eaten_score)
                        game.start_timer(timer_id=self.eaten_freeze_timer_id)
                        global_obj.game_paused = True
                        game.play_sound(sound_id="pacman-eat-ghost")
                    elif (collided_ghost.state == State.CHASE
                          or collided_ghost.state == State.SCATTER):
                        game.stop_animation(entity_id=self.entity_id)
                        game.emit_signal(entity_id=self.entity_id,
                                         signal_id=self.lose_life_signal_id)
                elif collider_tag == "fruit":
                    fruit_entity = scene_tree.get_entity(collided_entity_id)
                    if not fruit_entity.collected:
                        global_obj.player_stats.score += global_obj.player_stats.get_fruit_score(
                            collided_entity_id)
                        fruit_entity.eaten()

            # Input - determines direction pacman wants to turn
            if game.is_action_pressed(action="left"):
                self.direction_to_turn = Direction.left
            elif game.is_action_pressed(action="right"):
                self.direction_to_turn = Direction.right
            elif game.is_action_pressed(action="up"):
                self.direction_to_turn = Direction.up
            elif game.is_action_pressed(action="down"):
                self.direction_to_turn = Direction.down

            # Determine speed
            if game.has_timer_stopped(timer_id=self.turn_speed_up_timer_id):
                self.speed = 100
            else:
                self.speed = 150
            self.accumulated_delta += delta_time * self.speed
            while self.accumulated_delta >= 1.0:
                self.accumulated_delta -= 1.0
                self.move(self.velocity, 1.0)

            self.update_animations()

            # Play movement sound
            if abs(self.velocity.x) > 0 or abs(self.velocity.y) > 0:
                if game.has_timer_stopped(timer_id=self.chomp_timer_id):
                    pass
                    # game.start_timer(timer_id=self.chomp_timer_id)
            else:
                self.accumulated_delta = 0.0
        elif (global_obj.game_paused
              and global_obj.game_state == GameState.PACMAN_LOSE_LIFE):
            pass
        else:
            game.stop_animation(entity_id=self.entity_id)

        if game.is_action_just_pressed(action="exit_game"):
            game.quit()
示例#5
0
 def _on_fruit_timer_timeout(self):
     game.delete_entity(entity_id=self.entity_id)
示例#6
0
    def __create__(self):
        # Vars
        self.speed = 100

        # Play Music
        game.stop_music()
        game.pause_music()
        game.resume_music()
        game.play_music(music_id="dd-music")

        # Create Text Label Entity
        text_label_entity_id = "test_text"
        game.create_label_entity(
            entity_id=text_label_entity_id,
            text="Test",
            position=(100, 100),
            font_id="charriot",
            layer=2,
            fixed=False,
            wrap_length=800,
            color=(100, 100, 100),
        )

        # Update Label Text
        game.update_label_entity_text(entity_id=text_label_entity_id, text="New Text!")

        # Create sprite entity
        helicopter_entity_id = "helicopter"
        game.create_sprite_entity(
            entity_id=helicopter_entity_id,
            texture_id="chopper",
            position=(400, 400),
            layer=3,
            width=32,
            height=32,
            clickable=False,
            fixed=False,
            collider_tag="",  # Emtpy as default set to add collider
        )

        # Setup signal for animation finished
        game.subscribe_to_signal(
            source_id=f"{helicopter_entity_id}_animation",
            signal_id="animation_finished",
            subscriber_entity_id=self.entity_id,
            function_name="_on_helicopter_animation_finished",
        )
        # Setup signal for animation frame changed
        game.subscribe_to_signal(
            source_id=f"{helicopter_entity_id}_animation",
            signal_id="frame_changed",
            subscriber_entity_id=self.entity_id,
            function_name="_on_helicopter_frame_changed",
        )

        # Delete sprite entity (after creation)
        delete_entity_id = "delete_entity"
        game.create_sprite_entity(
            entity_id=delete_entity_id,
            texture_id="chopper",
            position=(100, 100),
            layer=3,
            width=32,
            height=32,
            clickable=False,
            fixed=False,
        )
        game.delete_entity(entity_id=delete_entity_id)

        # Create timer
        self.counted_seconds = 0
        self.count_timer_id = "count_timer"
        game.create_timer(
            timer_id=self.count_timer_id, time=1.0, loops=True, start_on_creation=True
        )
        # Stop Timer
        game.stop_timer(self.count_timer_id)
        # Start Timer
        game.start_timer(self.count_timer_id)

        # Connect signal
        game.subscribe_to_signal(
            source_id=self.count_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_test_timer_timeout",
        )