def unit_test(unit, sq, army):
    assert (unit.get_squad() == sq)
    assert (unit.get_army() == army)
    assert (unit.get_health() == src.GameplayParameters.INITIAL_SQUAD_HEALTH)
    assert (unit.get_protection() ==
            src.GameplayParameters.INITIAL_SQUAD_PROTECTION)

    attack = unit.attack_initiator(None)
    assert (attack.attacker == unit)
    assert (attack.attacking is None)
    if isinstance(unit, MagicArcherDecorator):
        assert (attack.damage == Archer.ATTACKING_DAMAGE)
    else:
        assert (attack.damage is None)

    unit.update_health(-10)
    assert (unit.get_health() == src.GameplayParameters.INITIAL_SQUAD_HEALTH -
            10)
    unit.reset_battle_parameters()
    assert (unit.get_health() == src.GameplayParameters.INITIAL_SQUAD_HEALTH)

    init_health = src.GameplayParameters.INITIAL_SQUAD_HEALTH + src.GameplayParameters.INITIAL_SQUAD_PROTECTION
    assert (not unit.take_strike(Attack(None, unit, init_health + 10)))
    assert (unit.get_health() == 0)

    unit.reset_battle_parameters()
    assert (unit.take_strike(Attack(None, unit, init_health - 10)))
    assert (unit.get_health() == 10)
    def update(self, screen):
        super().update(screen)

        screen.blit(self.sprite, [self.rect.x, self.rect.y])

        if self.ranged_cooldown.isDone() and self.ranged_active:
            if self.ranged_count == 0:
                self.start_tick = self.handler.getTick()
                self.ranged_count += 1
            if (self.handler.getTick() - self.start_tick) % 5 == 0:
                self.handler.getAttackList().add(Attack(self, self.damage, self.handler))
            if (self.handler.getTick() - self.start_tick) == 10:
                self.ranged_cooldown.update()

        if not self.ranged_cooldown.isDone():
            self.ranged_cooldown.update()
            self.ranged_count = 0
            self.ranged_active = False

        if self.special_active:
            if self.special_count == 0:
                self.start_pos = [self.rect.x, self.rect.y]
                self.special_sprite_rect.x = self.rect.x
                self.special_sprite_rect.y = self.rect.y - 30
                self.special_count += 1
                self.start_direction = self.facing
            screen.blit(self.special_sprite, [self.special_sprite_rect.x, self.special_sprite_rect.y])

            if abs(self.start_pos[0] - self.special_sprite_rect.x) >= self.special_range:
                self.special_stage = 2

            if self.special_stage is 1:
                self.movespeed = 10
                if self.start_direction == 1:
                    self.special_sprite_rect.x += self.special_travel_speed
                if self.start_direction == -1:
                    self.special_sprite_rect.x -= self.special_travel_speed
            if self.special_stage is 2:
                pygame.transform.rotate(self.special_sprite, 10)
                x_dist = self.special_sprite_rect.x - self.rect.x
                y_dist = self.special_sprite_rect.y - self.rect.y + 30
                xy_dist = math.sqrt((x_dist * x_dist) + (y_dist * y_dist))
                y_angle = math.asin(x_dist / xy_dist)
                x_angle = math.acos(y_dist / xy_dist)
                x_speed = self.special_travel_speed * math.sin(y_angle)
                y_speed = self.special_travel_speed * math.cos(x_angle)
                if pygame.Rect.colliderect(self.special_sprite_rect, self.rect):
                    self.special_stage = 3
                if pygame.Rect.colliderect(self.handler.getOtherPlayer(self).rect, self.special_sprite_rect) and not self.special_hit:
                    self.handler.getOtherPlayer(self).takeTrueDamage(200)
                    self.special_hit = True
                self.special_sprite_rect.x -= x_speed
                self.special_sprite_rect.y -= y_speed
            if self.special_stage is 3:
                self.special_count = 0
                self.special_stage = 1
                self.special_active = False
                self.special_hit = False
                self.movespeed = 6
                self.special_cooldown.update()

        if not self.special_cooldown.isDone():
            self.special_cooldown.update()
Exemple #3
0
 def attack_initiator(self, enemy):
     PrintManager.inst().info(self.get_army(), self.get_attack_message())
     return Attack(self, enemy, self.get_attacking_damage())
 def attack(self, screen):
     self.handler.getAttackList().add(
         Attack(self, self.damage, self.handler))
Exemple #5
0
 def attack_initiator(self, enemy):
     result = Attack(self, enemy, 0)
     for unit in self._units:
         result.damage += unit.attack_initiator(enemy).damage
     return result
Exemple #6
0
    def update(self, screen):
        self.animation_manager.update()
        self.tick += 1

        if not self.special_cooldown.isDone():
            self.special_cooldown.update()

        if self.special_active and not self.sleeping:
            self.special_duration.update()
            if not self.special_duration.isDone():
                self.stunned = True
                self.defense = 0
                self.xchange += self.roll_speed * self.facing
            else:
                self.special_cooldown.update()
                self.defense = self.startdefense
                self.stunned = False
                self.special_active = False
                self.in_special = False

        super().update(screen)

        if self.rangedavailable:
            self.tickcounter += 1
            self.ranged_cooldown.current_cooldown = self.tickcounter / 60
            if self.ranged_cooldown.current_cooldown <= 1 and self.released:
                attack = Attack(self, self.damage, self.handler)
                attack.damage = 50
                attack.travel_speed = 10
                attack.left_animation = self.attack_animation
                attack.right_animation = self.attack_animation
                self.handler.getAttackList().add(attack)
                self.rangedavailable = False
                self.ranged_used = True
                self.tickcounter = 0
            elif self.ranged_cooldown.current_cooldown <= 2 and self.released:
                attack = Attack(self, self.damage, self.handler)
                attack.damage = 125
                attack.travel_speed = 15
                attack.left_animation = self.attack_animation
                attack.right_animation = self.attack_animation
                self.handler.getAttackList().add(attack)
                self.rangedavailable = False
                self.ranged_used = True
                self.tickcounter = 0
            elif self.ranged_cooldown.current_cooldown <= 3 and self.released:
                attack = Attack(self, self.damage, self.handler)
                attack.damage = 300
                attack.travel_speed = 20
                attack.left_animation = self.attack_animation
                attack.right_animation = self.attack_animation
                self.handler.getAttackList().add(attack)
                self.rangedavailable = False
                self.ranged_used = True
                self.tickcounter = 0
            elif self.ranged_cooldown.current_cooldown <= 4 and self.released:
                attack = Attack(self, self.damage, self.handler)
                attack.damage = 480
                attack.travel_speed = 25
                attack.left_animation = self.attack_animation
                attack.right_animation = self.attack_animation
                self.handler.getAttackList().add(attack)
                self.rangedavailable = False
                self.ranged_used = True
                self.tickcounter = 0
            elif self.ranged_cooldown.current_cooldown > 4 and self.released:
                attack = Attack(self, self.damage, self.handler)
                attack.damage = self.ranged_cooldown.current_cooldown * 200
                attack.travel_speed = self.ranged_cooldown.current_cooldown * 7
                attack.left_animation = self.powerattack_animation_left
                attack.right_animation = self.powerattack_animation_right
                self.handler.getAttackList().add(attack)
                self.rangedavailable = False
                self.ranged_used = True
                self.tickcounter = 0
                self.BIGGnoise.playSound()
            self.rangedcount = 0