Exemple #1
0
    def update(self, game):
        """
        Обновление объекта
        :param game: класс игры
        """
        if self.wait_counter < 5:
            self.wait()
        else:
            CutAnimatedSprite.update(self, game)
            self.move(game)
        self.frames_handler(game)
        self.explosion.update(game)
        self.mask = pygame.mask.from_surface(self.image)
        self.mask_rect = get_rect_from_mask(self.mask).move(self.coords)
        if self.hurt_delay >= 1:
            self.is_hurt = False
        self.hurt_delay += self.hurt_delay / 3 + 0.01

        if not self.is_killed:
            PhysicalCreature.update(self, game)
        else:
            self.disappear(game)
        HeartsIncludedCreature.update(self, game)
        if self.move_delay >= 1:
            pass
Exemple #2
0
    def update(self, game):
        """
        Обновление объекта
        :param game: класс игры
        """
        from items import HalfHeart, FullHeart
        self.player_position = game.player.coords
        self.mask = pygame.mask.from_surface(self.image)
        self.mask_rect = get_rect_from_mask(self.mask).move(self.coords)
        CutAnimatedSprite.update(self, game)
        HeartsIncludedCreature.update(self, game)

        if self.hurt_delay >= 1:
            self.is_hurt = False
        self.hurt_delay += self.hurt_delay / 3 + 0.01
        self.move()

        self.attack_delay += self.attack_delay / 5 + self.attack_speed
        if self.attack_delay >= 1 and pygame.sprite.collide_mask(
                self, game.player):
            self.attack(game.player)
        if self.is_killed:
            self.explosion.update(game)
            self.spawn_items([(HalfHeart, 0.1), (FullHeart, 0.01)], game)
        PhysicalCreature.update(self, game)
Exemple #3
0
    def __init__(self, coords):
        CutAnimatedSprite.__init__(self,
                                   'assets/enemies/i-blob.png',
                                   4,
                                   3,
                                   *coords,
                                   size=1.7,
                                   speed=0.0008)
        PhysicalCreature.__init__(self)
        CantHurtObject.__init__(self)
        ItemsSpawner.__init__(self)
        self.render_rect = pygame.Rect(*coords, *self.image.get_size())
        self.rect = pygame.Rect(*coords, int(30 * 1.7), int(21 * 1.7))
        self.coords = list(coords)
        self.speed = 20
        self.move_delay = 0
        self.can_move = False
        self.tears_list = []
        self.collision_direction_x = None
        self.collision_direction_y = None
        self.is_killed = False
        self.team = 'enemy'
        self.mask = pygame.mask.from_surface(self.image)
        self.mask_rect = get_rect_from_mask(self.mask).move(self.coords)
        self.explosion = Explosion(self, (500, 500),
                                   (self.image.get_width() / 3, 30), 0.7)
        self.is_invisible = False
        self.move_delay = 0
        self.__counter = 0
        self.wait_counter = 0
        self.is_wait = False
        health = 4

        HeartsIncludedCreature.__init__(self, 'enemy', health=health)
Exemple #4
0
 def on_collision(self, collided_sprite, game):
     """
     :param collided_sprite: объект с которым столкнулись
     :param game: игра
     """
     if isinstance(collided_sprite,
                   Tears) or collided_sprite in game.creatures:
         return
     PhysicalCreature.on_collision(self, collided_sprite, game)
Exemple #5
0
    def update(self, game):
        """
        Обновление объекта
        :param game: класс игры
        """
        if self.is_attack:
            update_body_parts = (self.body_sprite, )
        else:
            update_body_parts = (self.head_sprite, self.body_sprite)

        if self.hurt_delay >= 1:
            self.is_hurt = False
        self.hurt_delay += self.hurt_delay / 3 + 0.01

        if self.direction_x == 'left':
            for element in update_body_parts:
                element.action_sprites = element.left_sprites
                element.start(action='walking-x')
        elif self.direction_x == 'right':
            for element in update_body_parts:
                element.action_sprites = element.right_sprites
                element.start(action='walking-x')
        if self.direction_y == 'up':
            for element in update_body_parts:
                element.start(action='walking-up')
        elif self.direction_y == 'down':
            for element in update_body_parts:
                element.start(action='walking-down')

        if self.direction_x is None and self.direction_y is None:
            self.stop_move()

        self.move(self.direction_x, self.direction_y,
                  self.collision_direction_x, self.collision_direction_y)
        self.body_sprite.update(game)
        self.head_sprite.update(game)

        self.image = pygame.Surface((self.head_sprite.image.get_width(),
                                     self.head_sprite.image.get_height() +
                                     self.body_sprite.image.get_height()))
        self.image.fill((0, 255, 0))
        self.image.set_colorkey((0, 255, 0))

        self.image.blit(self.body_sprite.image, (10, 39))
        self.image.blit(self.head_sprite.image, (0, 0))

        self.attack(game)
        self.mask_rect = get_rect_from_mask(self.mask).move(self.coords)
        PhysicalCreature.update(self, game)
        HeartsIncludedCreature.update(self, game)
        if self.is_killed:
            self.explosion.update(game)
            self.explosion.explode()
            self.is_stopped = True
            if self.explosion.index == 7:
                game.end_game()
Exemple #6
0
 def on_collision(self, collided_sprite, game):
     """
     действия при столкновении
     :param collided_sprite: объект с которым столкнулись
     :param game: класс игры
     """
     if isinstance(collided_sprite,
                   Tears) or collided_sprite in game.creatures:
         return
     PhysicalCreature.on_collision(self, collided_sprite, game)
Exemple #7
0
    def __init__(self, coords, size):
        PhysicalCreature.__init__(self)
        CanHurtObject.__init__(self)
        ItemsSpawner.__init__(self)
        self.is_invisible = False
        self.one_punch_object = False
        if size == 'big':
            self.speed = 1
            self.damage = 2
            self.attack_speed = 0.00001
            creature_size = 3
            health = 5
            explosion_size = 0.7
        elif size == 'small':
            self.speed = 2
            self.damage = 1
            self.attack_speed = 0.001
            creature_size = 2
            health = 3
            explosion_size = 0.5
        CutAnimatedSprite.__init__(self,
                                   'assets/enemies/mosquito.png',
                                   2,
                                   1,
                                   *coords,
                                   size=creature_size,
                                   speed=0.01)
        self.coords = list(coords)
        HeartsIncludedCreature.__init__(self, 'enemy', health)
        self.mask = pygame.mask.from_surface(self.image)
        self.mask_rect = get_rect_from_mask(self.mask)

        self.attack_delay = 0.001
        self.explosion = Explosion(self, self.coords, (35, 40), explosion_size)
        self.is_killed = False
        self.collision_direction_y = None
        self.collision_direction_x = None
Exemple #8
0
    def __init__(self, coords: tuple):

        CantHurtObject.__init__(self)

        self.is_invisible = False
        head_sprite_map: Dict[str, List[str]] = dict()
        for action_folder in ('idle', 'walking-x', 'walking-down',
                              'walking-up', 'attack-x', 'attack-up',
                              'attack-down'):
            head_sprite_map[action_folder] = [
                f'assets/player/head/{action_folder}/{i}'
                for i in os.listdir(f'assets/player/head/{action_folder}')
            ]

        body_sprite_map: Dict[str, List[str]] = dict()
        for action_folder in ('idle', 'walking-x', 'walking-down',
                              'walking-up'):
            body_sprite_map[action_folder] = [
                f'assets/player/body/{action_folder}/{i}'
                for i in os.listdir(f'assets/player/body/{action_folder}')
            ]

        self.head_sprite = PlayerBodyParts(head_sprite_map,
                                           (coords[0], coords[1]),
                                           self,
                                           animation_speed=0.001)

        self.body_sprite = PlayerBodyParts(body_sprite_map,
                                           (coords[0] + 10, coords[1] + 39),
                                           self,
                                           animation_speed=0.001)

        self.coords = list(coords)
        self.direction_x = None
        self.direction_y = None

        self.speed = 4

        self.ammos_list = list()

        self.attack_speed = 0.05

        self.image = pygame.Surface((self.head_sprite.image.get_width(),
                                     self.head_sprite.image.get_height() +
                                     self.body_sprite.image.get_height()))
        self.image.fill((0, 255, 0))
        self.image.set_colorkey((0, 255, 0))
        self.image.blit(self.body_sprite.image, (10, 39))
        self.image.blit(self.head_sprite.image, (0, 0))
        self.rect = pygame.Rect(
            (coords[0], coords[1], self.head_sprite.image.get_width(),
             self.head_sprite.image.get_height() +
             self.body_sprite.image.get_height()))
        self.mask = pygame.mask.from_surface(self.image)
        self.collision_direction_x = None
        self.collision_direction_y = None

        self.is_attack = False
        self.is_killed = False
        self.is_stopped = False
        self.explosion = Explosion(self, self.coords, (70, 55), 0.8, 0.5)
        health = 10
        PhysicalCreature.__init__(self)
        HeartsIncludedCreature.__init__(self, 'player', health)
        self.mask_rect = get_rect_from_mask(self.mask).move(self.coords)
        self.attack_delay = 0