Beispiel #1
0
    def _handle_player_collide_item(self, player: Player, dropped_item: DroppedItem,
                                    data, arbiter: pymunk.Arbiter) -> bool :
        """Callback to handle collision between the player and a (dropped) item. If the player has sufficient space in
        their to pick up the item, the item will be removed from the game world.

        Parameters:
            player (Player): The player that was involved in the collision
            dropped_item (DroppedItem): The (dropped) item that the player collided with
            data (dict): data that was added with this collision handler (see data parameter in
                         World.add_collision_handler)
            arbiter (pymunk.Arbiter): Data about a collision
                                      (see http://www.pymunk.org/en/latest/pymunk.html#pymunk.Arbiter)
                                      NOTE: you probably won't need this
        Return:
             bool: False (always ignore this type of collision)
                   (more generally, collision callbacks return True iff the collision should be considered valid; i.e.
                   returning False makes the world ignore the collision)
        """

        dropped_item.collect(self._player)
        self._world.remove_item(dropped_item)
        if dropped_item.get_id() == "star" :
            self._player.set_invincible(True)
            self._start_time = time.time()
        if dropped_item.get_id() == "flower":
            self._powerup.set_powerup(True)
        return False
Beispiel #2
0
 def _draw_physical_item(self, instance: DroppedItem, shape: pymunk.Shape,
                         view: tk.Canvas, offset: Tuple[int,
                                                        int]) -> List[int]:
     image = self.load_image(self._item_images[instance.get_id()])
     return [
         view.create_image(shape.bb.center().x + offset[0],
                           shape.bb.center().y,
                           image=image,
                           tags="item")
     ]
Beispiel #3
0
def create_item(world: World, item_id: str, x: int, y: int, *args):
    """Create a new item instance and add it to the world based on the item_id.

    Parameters:
        world (World): The world where the item should be added to.
        item_id (str): The item identifier of the item to create.
        x (int): The x coordinate of the item.
        y (int): The y coordinate of the item.
    """
    item_id = ITEMS[item_id]
    if item_id == "coin":
        item = Coin()
    else:
        item = DroppedItem(item_id)

    world.add_item(item, x * BLOCK_SIZE, y * BLOCK_SIZE)