The final challenge in this series is to add a boss level for the end of the game.
My approach to this was the following:
- Create new boss artwork, but use what’s already available to help speed things up.
- Add hit zones and visuals to show damage to parts of the boss.
- Have the boss move on a waypoint system to keep it on screen.
- Update the UI to show a game winning screen and ability to restart.
The first part of this challenge is to take some of the artwork and reuse and modify. Any part of the artwork can eventually be changed out at a later time if you have more time. To make this easy, I used the basic enemy ship but increased the scale.
I used GIMP and added some layered paint marks to illustrate gashes / cracks in the boss ship on different areas.
To show the damage in stages, I used the boss game object and added some hit zones and damage areas that would emit particle effects.
The damage visuals combined with particle effects in Unity would indicate the damage stages.
The boss C# script inherits some of the enemy base class behaviors, but has its own waypoint movement, lasers, and control for the hit boxes and particle system emissions for the damage stages.
This first part of the script contains the variables for the particle systems and box colliders for the damage zones.
To show the visuals, I used the animator, which I will explain more later.
The following part of the script continues with more variables: bool variables to check the stage of damage, a hit count variable to count the hits on each trigger, a variable for the Spawn Manager, and the boss speed.
In the Start method, we get references to the hit colliders.
We continue with references to the damage particle systems, set all particle systems off, and set the first hit area enabled. We get a reference to the animator, a reference to the Spawn Manager, set the first stage function, and assign the waypoint path from the Game Manager.
In the last part of the boss Start method, we get a reference to the UI Manager, and we set the first animation which contains a single sprite that shows the base enemy image.
The Update method is similar to the other enemies. I modified the laser firing slightly to add a bool check if the Spawn Manager stop spawning is still false.
The next series of screenshots show the rest of the boss script with public methods for each stage start and for each stage that is over. We have a hit counter reset for each stage, and once the stage is over, we change the animation and show a new sprite with an increased level of damage, and we play the associated particle system.
Regarding the ship visuals described above, I created an animation clip for each stage of damage, but instead of a series of sprites, I added a single sprite and the clip just loops endlessly. Then in each new damage stage, I tell the animator to play the new damage visual.
In the shield script, I added a resized shield that can spawn randomly, similar to the other enemy shields that spawn randomly.
The boss version of the shield also requires several hits to break before the boss can be damaged.
In the Spawn scriptable object script that controls the enemy waves, I added a function for when the player wins to stop spawning.
For the four damage areas, each gameobject consists of an empty game object with a box collider, Rigidbody, Mesh Renderer, Material, and a Mesh Filter Quad. Each damage area C# script contains a reference to the player to record damage and points, a reference to the Mesh Renderer, and the flash time for each hit visual.
The rest of the damage area script consists of collider checks for a hit from the laser, homing missile, player, or shield, and adds score and also records the number of hits to the hit zone. The script also includes a function to flash the hit zone red to make clear what part of the boss can be damaged.
For the boss waypoint path, in the Game Manager script I added a new list of waypoints and assigned the set of waypoints in the Start method.
In the Boss C# script Update method, here’s the waypoint movement.
The last part of the updates is to add the game winning screen to the UI Manager script. Similar to the game over script, the winning message flickers, and we also show a restart option.
Here are some gif animations of various parts of the boss battle.
Thank you for your time!