示例#1
0
文件: scroll_map.py 项目: kztd/pgz
    def remove_sprite(self, sprite: pygame.sprite.Sprite) -> None:
        """Remove sprite/actor from the map.

        Args:
            sprite (pygame.sprite.Sprite): sprite object to remove
        """
        sprite.remove(self._map_group)
示例#2
0
 def activate(self, player: pygame.sprite.Sprite):
     if not self.activated:
         self.sound.play()
         self.activated = True
         player.add_money(self.price)
         self.spawn_particles(player)
         self.delete()
示例#3
0
 def spawn_particles(self, player: pygame.sprite.Sprite):
     color = random.choice(self.colors)
     direction = -1 if player.facing_right else 1
     x = player.x + player.rect.w - (player.rect.w +
                                     5) * player.facing_right + 8
     y = player.y + 50
     player.spawn_particles(x, y, color, amount=5, direction=direction)
     player.spawn_glowing_particles(x, y, direction=direction, lifespan=240)
示例#4
0
 def calculate_bullets_collisions(self, coll: pygame.sprite.Sprite):
     """метод для обработки столкновений пуль с объектом"""
     if (collisions := self.bullets.get_collisions(coll)):
         coll.take_damage(self.damage)
         for collision in collisions:
             self.spawn_explosion(*collision.pos,
                                  coll.blood_colors,
                                  radius=(2, 12))
             collision.delete()
示例#5
0
 def activate(self, player: pygame.sprite.Sprite):
     self.delete()
     self.sound.play()
     for _ in range(20):
         color = random.choice(self.colors)
         player.spawn_particles(amount=2,
                                momentum=random.randrange(0, 3),
                                radius=random.randrange(4, 10),
                                color=color)
示例#6
0
 def spawn_particles(self, player: pygame.sprite.Sprite):
     x = self.rect.center[0] - 3 + 6 * player.facing_right
     y = self.bottom - 5
     for _ in range(20):
         player.spawn_glowing_particles(x,
                                        y,
                                        amount=2,
                                        momentum=random.randrange(2, 6),
                                        radius=random.randrange(4, 12))
示例#7
0
def flip(sprite: pg.sprite.Sprite, orig_image, x_reflect: bool,
         y_reflect: bool):
    """Flips (reflects) the image for a sprite either horizontally, vertically, or both.

    :param sprite: The pygame Sprite whose image we're flipping.
    :param orig_image: A pygame Surface representing the image we will flip.
    :param x_reflect: A boolean indicating if the image should be flipped horizontally.
    :param y_reflect: A boolean indicating if the image should be flipped vertically.
    :return: None; operations done in-place.
    """
    old_center = sprite.rect.center
    sprite.image = pg.transform.flip(orig_image, x_reflect, y_reflect)
    sprite.rect = sprite.image.get_rect()
    sprite.rect.center = old_center
示例#8
0
    def check_if_pawn_is_jumping_over(self, newPawnTile: pygame.sprite.Sprite):
        distanceX = abs(newPawnTile.get_tile_center_x() -
                        self.get_tile_center_x())
        distanceY = abs(newPawnTile.get_tile_center_y() -
                        self.get_tile_center_y())

        if (distanceX == (newPawnTile.image.get_width() * 2)) ^ (distanceY == (
                newPawnTile.image.get_height() * 2)):
            if (distanceX == newPawnTile.image.get_width()) or (
                    distanceY == newPawnTile.image.get_height()):
                return False
            return True
        else:
            return False
示例#9
0
    def check_if_pawn_is_moving_to_the_nearest_tile(
            self, newPawnTile: pygame.sprite.Sprite):
        distanceX = abs(newPawnTile.get_tile_center_x() -
                        self.get_tile_center_x())
        distanceY = abs(newPawnTile.get_tile_center_y() -
                        self.get_tile_center_y())

        if (distanceX == newPawnTile.image.get_width()) ^ (
                distanceY == newPawnTile.image.get_height()):
            if (distanceX > newPawnTile.image.get_width()) or (
                    distanceY > newPawnTile.image.get_height()):
                return False
            return True
        else:
            return False
示例#10
0
 def update(self, sprite: pygame.sprite.Sprite):
     if len(self.animation) > 1:
         self.count += 1
         if self.count == self.speed:
             self.index += 1
             if self.index == len(self.animation):
                 self.index = 0
             sprite.image = self.animation[self.index]
             self.count = 0
示例#11
0
    def double_jump(self, newPawnTile: pygame.sprite.Sprite,
                    pawnsSprintTable: pygame.sprite.Group):
        distanceX = newPawnTile.get_tile_center_x() - self.get_tile_center_x()
        distanceY = newPawnTile.get_tile_center_y() - self.get_tile_center_y()

        if distanceX != 0:
            if distanceX > 0:
                pawnInBettwenX = newPawnTile.get_tile_center_x_for_drawing_pawn(
                    self) - newPawnTile.image.get_width()
                for pawn in pawnsSprintTable:
                    if pawn.rect.x == pawnInBettwenX and pawn.rect.y == self.rect.y:
                        return True
            else:
                pawnInBettwenX = newPawnTile.get_tile_center_x_for_drawing_pawn(
                    self) + newPawnTile.image.get_width()
                for pawn in pawnsSprintTable:
                    if pawn.rect.x == pawnInBettwenX and pawn.rect.y == self.rect.y:
                        return True
        else:
            if distanceY > 0:
                pawnInBettwenY = newPawnTile.get_tile_center_y_for_drawing_pawn(
                    self) - newPawnTile.image.get_height()
                for pawn in pawnsSprintTable:
                    if pawn.rect.y == pawnInBettwenY and pawn.rect.x == self.rect.x:
                        return True
            else:
                pawnInBettwenY = newPawnTile.get_tile_center_y_for_drawing_pawn(
                    self) + newPawnTile.image.get_height()
                for pawn in pawnsSprintTable:
                    if pawn.rect.y == pawnInBettwenY and pawn.rect.x == self.rect.x:
                        return True
示例#12
0
    def apply_powerup(self, character: pg.sprite.Sprite):
        """
        Calls Character functions that handle the powerup effects
        :param character: pg.sprite.Sprite (Character)
        """
        Timer(self.game,
              5,
              100,
              100,
              DEFAULT_FONT_NAME,
              25,
              True,
              _type=self.type)
        if self.type in ['purple', 'yellow', 'white']:
            Timer(self.game,
                  POWERUP_EFFECT[self.type],
                  15,
                  20,
                  DEFAULT_FONT_NAME,
                  25,
                  _type=self.type)

        if self.type == 'red':
            character.heal(POWERUP_EFFECT[self.type])
            character.image_code = 2
        if self.type == 'pink':
            character.heal(POWERUP_EFFECT[self.type])
            character.image_code = 3
        if self.type == 'purple':
            character.double_shot(POWERUP_EFFECT[self.type])
            character.image_code = 4
        if self.type == 'blue':
            character.heal_shield()
        if self.type == 'yellow':
            character.immune(POWERUP_EFFECT[self.type])
            character.image_code = 5
        if self.type == 'white':
            character.fast_fire(POWERUP_EFFECT[self.type])
            character.image_code = 6
        if self.type == 'green':
            if character.armor >= 4:
                return
            character.armor += POWERUP_EFFECT[self.type]
            character.image_code = 7
        if self.type == 'w_green':
            character.attack += POWERUP_EFFECT[self.type]
            character.image_code = 8
示例#13
0
 def activate(self, player: pygame.sprite.Sprite):
     if not self.activated:
         self.sound.play()
         self.activated = True
         player.set_momentum(-10)
         player.spawn_particles()
示例#14
0
 def spawn_particles(self, player: pygame.sprite.Sprite):
     color = random.choice(self.colors)
     player.spawn_particles(*self.rect.center, color, amount=1)
示例#15
0
 def activate(self, player: pygame.sprite.Sprite):
     """метод для обработки коллизии с игроком"""
     player.rect.bottom = self.top
     player.jump()
示例#16
0
 def activate(self, player: pygame.sprite.Sprite):
     if not self.activated:
         player.enable_gravity(False)
         player.set_flying_object(self)
         self.activated = True
示例#17
0
 def activate(self, player: pygame.sprite.Sprite):
     self.sound.play()
     player.set_momentum(-15)
     player.spawn_particles()
     player.rotate()
示例#18
0
 def on_delete(self, player: pygame.sprite.Sprite):
     if self.activated:
         self.sound.stop()
         player.enable_gravity(True)
         player.set_flying_object()
示例#19
0
 def activate(self, player: pygame.sprite.Sprite):
     if player.shield is None:
         player.game_over = True
示例#20
0
 def on_delete(self, player: pygame.sprite.Sprite):
     if self.activated:
         player.set_magnet()
示例#21
0
 def activate(self, player: pygame.sprite.Sprite):
     if not self.activated:
         player.set_magnet(self)
         self.activated = True
示例#22
0
 def spawn_particles(self, player: pygame.sprite.Sprite):
     player.spawn_explosion(*self.rect.center, self.colors, radius=(1, 10))