Boss spawn minions and Explosion - UQdeco2800/2021-studio-2 GitHub Wiki

Overview

The elves boss has the special component (skill) that allow it to call upon two elves minions (one melee and one ranged) twice, when its health is 50% and 25% respectively.

Code

Check for spawning condition

    private boolean canSpawn() {
        float maxHealth = owner.getEntity().getComponent(CombatStatsComponent.class).getMaxHealth();
        float health = owner.getEntity().getComponent(CombatStatsComponent.class).getHealth();
        float ratio = health / maxHealth;


        if (ratio < 0.5 && spawn < 1) {
            return true;
        }
        return ratio < 0.25 && spawn < 2;
    }

If health is less than 50% and it has not spawn any enemy before, spawn first time. If health is less than 25% and it has not spawn enemy twice, spawn second time.

Spawn minion and explosions

    public void spawn() {
        Entity elf = NPCFactory.createMeleeElf(target);
        Entity elf2 = NPCFactory.createRangedElf(target, "normalArrow", 0.15f);
        Entity explosion = WeaponFactory.createExplosion(owner.getEntity());

        ServiceLocator.getGameAreaService().incNum();
        ServiceLocator.getGameAreaService().incNum();

        gameArea.spawnEntityAt(elf, owner.getEntity().getCenterPosition(), true, true);
        gameArea.spawnEntityAt(elf2, owner.getEntity().getCenterPosition(), true, true);
        gameArea.spawnEntityAt(explosion, owner.getEntity().getCenterPosition(), true, true);

    }

Two enemies are spawn at the boss position and will be pushed away by the hit box. The boss spawn an explosion ring around it to push the player away. (Number of enemy on the map is record)

Spawn minion and Explosion Class Diagram