コード例 #1
0
ファイル: pacman.py プロジェクト: Chukobyte/PacmanClone
 def pellete_counter(self, value):
     self._pellete_counter = value
     # 244 - 70 = 174, 244 - 170 = 74
     if self._pellete_counter == 174 or self._pellete_counter == 74:
         # Spawn fruit
         fruit_entity_id = global_obj.player_stats.get_level_fruit_entity_id(
         )
         if fruit_entity_id:
             game.create_sprite_entity(
                 entity_id=fruit_entity_id,
                 texture_id=fruit_entity_id,
                 position=(global_obj.level_grid.board_position.x +
                           (13 * 16) + 4,
                           global_obj.level_grid.board_position.y +
                           (17 * 16) - 8),
                 layer=5,
                 width=20,
                 height=16,
                 collider_tag="fruit",
                 script_class=("scripts.fruit", "Fruit"))
     elif self._pellete_counter <= 0:
         game.play_animation(entity_id=self.entity_id,
                             animation_name="idle")
         game.emit_signal(entity_id=self.entity_id,
                          signal_id=self.level_cleared_signal_id)
コード例 #2
0
ファイル: stats.py プロジェクト: Chukobyte/ByteEngine
    def level(self, value):
        self._level = value
        if self._level > 0 and self.is_in_valid_playing_state():
            for index in range(min(self._level, 8)):
                current_level = index + 1
                fruit_entity_id = ""
                if current_level == 1:
                    fruit_entity_id = "cherry"
                elif current_level == 2:
                    fruit_entity_id = "strawberry"
                elif current_level == 3:
                    fruit_entity_id = "orange"
                elif current_level == 4:
                    fruit_entity_id = "apple"
                elif current_level == 5:
                    fruit_entity_id = "melon"
                elif current_level == 6:
                    fruit_entity_id = "galaxy_boss"
                elif current_level == 7:
                    fruit_entity_id = "bell"
                elif current_level == 8:
                    fruit_entity_id = "key"

                if fruit_entity_id:
                    game.create_sprite_entity(
                        entity_id=f"{fruit_entity_id}_level",
                        texture_id=fruit_entity_id,
                        position=(
                            384 - (36 * index),
                            global_obj.level_grid.board_position.y + 496,
                        ),
                        layer=5,
                        width=16,
                        height=16,
                    )
コード例 #3
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)
コード例 #4
0
ファイル: main.py プロジェクト: Chukobyte/PacmanClone
    def create_level_pellets(self):
        index = 0
        offset_x = 10
        offset_y = 6
        for x, y in global_obj.level_grid.get_pellete_spaces():
            position_x = (
                x * 16) + global_obj.level_grid.board_position.x + offset_x
            position_y = (
                y * 16) + global_obj.level_grid.board_position.y + offset_y
            game.create_sprite_entity(
                entity_id=f"pellete-{index}",
                texture_id="pellete",
                position=(position_x, position_y),
                layer=2,
                width=2,
                height=2,
                clickable=False,
                fixed=False,
                collider_tag="pellete",
            )
            index += 1

        index = 0
        offset_x = 4
        offset_y = 0
        for x, y in global_obj.level_grid.get_power_pellete_spaces():
            position_x = (
                x * 16) + global_obj.level_grid.board_position.x + offset_x
            position_y = (
                y * 16) + global_obj.level_grid.board_position.y + offset_y
            power_pellete_entity_id = f"power_pellete-{index}"
            game.create_sprite_entity(
                entity_id=power_pellete_entity_id,
                texture_id="power_pellete",
                position=(position_x, position_y),
                layer=2,
                width=8,
                height=8,
                clickable=False,
                fixed=False,
                collider_tag="power_pellete",
            )
            self.power_pellete_ids.append(power_pellete_entity_id)
            game.set_entity_visibility(entity_id=power_pellete_entity_id,
                                       visible=False)
            index += 1
コード例 #5
0
ファイル: example_class.py プロジェクト: Chukobyte/ByteEngine
    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",
        )