Exemplo n.º 1
0
    def test_regenerate_player_energy_correct_amount(self) -> None:
        player = make_player()
        recharge_amount = 15
        data = AbilityData(cool_down_time=300,
                           finite_uses=True,
                           uses_left=2,
                           recharge_amount=recharge_amount)
        recharge = GenericAbility(data)

        source = player.energy_source
        starting_energy = source.max_energy
        energy_expended = 20

        source.expend_energy(energy_expended)
        self.assertEqual(source.energy_available,
                         starting_energy - energy_expended)

        recharge.use(player)
        self.assertEqual(source.energy_available,
                         starting_energy - energy_expended + recharge_amount)
        self.assertEqual(recharge.uses_left, 1)

        recharge.use(player)
        self.assertEqual(source.energy_available, starting_energy)
        self.assertEqual(recharge.uses_left, 0)
Exemplo n.º 2
0
    def test_fireprojectile_use_ignores_can_use(self) -> None:
        player = make_player()
        fire_pistol = GenericAbility(self.projectile_ability_data)

        self.assertEqual(len(self.groups.bullets), 0)
        self.assertFalse(fire_pistol.can_use('dummy_arg'))
        fire_pistol.use(player)
        self.assertEqual(len(self.groups.bullets), 1)
Exemplo n.º 3
0
    def test_fireprojectile_cannot_use_after_firing(self) -> None:
        player = make_player()
        fire_pistol = GenericAbility(self.projectile_ability_data)
        self.timer.current_time += \
            self.projectile_ability_data.cool_down_time + 1

        self.assertTrue(fire_pistol.can_use('dummy_arg'))
        fire_pistol.use(player)
        self.assertFalse(fire_pistol.can_use('dummy_arg'))
Exemplo n.º 4
0
    def test_fire_many_bullets(self) -> None:
        player = make_player()

        projectile_count = 15
        ability_data = self.projectile_ability_data._replace(
            projectile_count=projectile_count)
        fire_many = GenericAbility(ability_data)

        self.assertEqual(len(self.groups.bullets), 0)
        fire_many.use(player)
        self.assertEqual(len(self.groups.bullets), projectile_count)
Exemplo n.º 5
0
    def test_player_shoot_kickback(self) -> None:
        player = make_player()
        fire_pistol = GenericAbility(self.projectile_ability_data)

        old_vel = (player.motion.vel.x, player.motion.vel.y)
        fire_pistol.use(player)
        new_vel = (player.motion.vel.x, player.motion.vel.y)

        kickback = self.projectile_ability_data.kickback
        expected_vel = (-kickback + old_vel[0], old_vel[1])
        self.assertEqual(new_vel, expected_vel)
Exemplo n.º 6
0
    def test_heal_player_damaged_correct_amount(self) -> None:
        player = make_player()
        heal_amount = 10
        data = AbilityData(cool_down_time=300,
                           finite_uses=True,
                           uses_left=3,
                           heal_amount=heal_amount)
        heal = GenericAbility(data)

        max_health = player.status.max_health
        player.status.increment_health(-heal_amount - 2)
        heal.use(player)
        self.assertEqual(player.status.health, max_health - 2)
        self.assertEqual(heal.uses_left, 2)
Exemplo n.º 7
0
    def test_heal_player_not_damaged(self) -> None:
        player = make_player()
        heal_amount = 10
        data = AbilityData(cool_down_time=300,
                           finite_uses=True,
                           uses_left=3,
                           heal_amount=heal_amount)
        heal = GenericAbility(data)

        max_health = player.status.max_health
        self.assertEqual(player.status.health, max_health)
        self.assertFalse(heal.can_use(player))

        # use implements a heal anyway
        heal.use(player)
        self.assertEqual(player.status.health, max_health)
        self.assertEqual(heal.uses_left, 2)
Exemplo n.º 8
0
    def test_fire_projectile_distance_independent_of_count(self) -> None:
        player = make_player()
        num_updates = 100

        data_dict = load_ability_data_kwargs('shotgun')
        data_dict['projectile_count'] = 1
        ability_data = AbilityData(**data_dict)

        fire_little_bullet = GenericAbility(ability_data)

        fire_little_bullet.use(player)

        self.assertEqual(len(self.groups.bullets), 1)
        bullet = self.groups.bullets.sprites()[0]
        first_pos = Vector2(bullet.pos.x, bullet.pos.y)

        for _ in range(num_updates):
            self.groups.bullets.update()

        one_disp = (bullet.pos - first_pos).length()

        many = 10
        ability_data = ability_data._replace(projectile_count=many)
        fire_little_bullet = GenericAbility(ability_data)

        self.groups.bullets.empty()
        fire_little_bullet.use(player)
        self.assertEqual(len(self.groups.bullets), many)

        bullet = self.groups.bullets.sprites()[0]
        first_pos = Vector2(bullet.pos.x, bullet.pos.y)

        for _ in range(num_updates):
            self.groups.bullets.update()

        many_disp = (bullet.pos - first_pos).length()

        self.assertLess(0.5 * many_disp, one_disp)
Exemplo n.º 9
0
    def test_fireprojectile_use_instantiates_bullet_and_flash(self) -> None:
        groups = self.groups
        player = make_player()
        fire_pistol = GenericAbility(self.projectile_ability_data)

        self.assertEqual(len(groups.all_sprites), 1)
        fire_pistol.use(player)
        # Check if a MuzzleFlash and Projectile sprite were created
        sprites = groups.all_sprites
        num_bullets = 0
        num_flashes = 0
        num_others = 0
        for sp in sprites:
            if isinstance(sp, Projectile):
                num_bullets += 1
            elif isinstance(sp, MuzzleFlash):
                num_flashes += 1
            else:
                num_others += 1

        self.assertEqual(num_bullets, 1)
        self.assertEqual(num_flashes, 1)
        self.assertEqual(num_others, 1)