The Boss Enemy, Part 5
Objective: add boss damage effects, a damaged boss sprite for its second phase, and proper boss death effects
We’ll change the behavior of ToggleDamageEffects so that we gradually get more damage effects active over time, based on the ratio between maximum life and current life. This means that something at half life will have roughly half of its damage effects activated.
This means that something with a lot of life, like the boss, can require multiple hits to trigger its next damage effect.
Now we want to have pieces of the boss explode when it is reduced to half life. We’ll add a new edited sprite with some of the pieces erased.
Now, when the boss reaches half life, we do several things. We cause some camera shake, and call a coroutine that causes random explosions to appear within some of the boss’s Collider2D objects, which we keep track of in _phaseOneHitboxes. Afterwards, we change it’s sprite to the damaged version, create some explosions on points determine by empty gameobjects, and turn off any damage effects and colliders associated with the boss’s first phase.
We can create these mini explosions by using a coroutine that periodically creates an explosion randomly inside every given Collider2D. Instead of creating an array of each gameobject or collider we want for this, it’s more convenient to input a single gameobject whose children have all the colliders we want to check.
Finally, this DeathEffects coroutine is called when the boss reaches zero life. This also causes camera shake and mini explosions, as well as creating one large explosion. Only after all these effects happen do we tell the UI manager that the boss has died, so the victory message and all other end-game effects come afterward.
Now we get a really dramatic bunch of explosions when the boss finally goes down! It’s a perfect finale for the end of the game.