Project 1: Space Shooter

The Boss part 1

The movement, the shields, the damage and the death

Showing staged gameplay of the boss and the implemented features.
All the features work as wanted, only thing that needs tweaking is the shield’s recharge time which seems a bit too long.

It is finally time to create the Boss enemy. Since there is more work on the boss than the other enemies, this will be a multipart series covering the more interesting parts of the boss build.

The easiest to cover is the movement, the boss will spawn outside the game area at the top, then it will move straight down roughly down to the middle part and stay there.

Showing the movement method for the boss.
The movement method for the boss.

While the boss is moving down it is impervious to any form of damage. This is controlled with the Boolean variable _stoppedMoving. This is used to keep the boss moving and to return from the OnTriggerEnter2D method, which prevents any other checks being done before the movement has stopped and in this way prevents any form of damage.

Showing the OnTriggerEnter2D method with the damage prevention measures.
The OnTriggerEnter2D method with the damage prevention measures.

Then the shields, these are essentially the same as the shields for the player and the enemy, with one exception, the boss’s shields regenerate themselves. Once the player has damaged the shields three times, the shield regeneration begins.

Showing the ShieldDamage method that handles the damage to the shields and their recharge.
The ShieldDamage method that handles the damage to the shields and their recharge.

The time it takes for the shields to recharge is calculated using a random time in seconds between and seconds added with the amount of health the boss has and finally with addition of the current time during the calculation.

The boss has nine health in total, so every time the player hits the boss the recharge time drops by second. As for the damage, there are eight child objects on the boss which will show visually the damage.

These damage points will be picked randomly, so that every time the player gets to the boss the order of these points showing up changes. This is achieved with the do-while loop, it will pick a random index from the array of the game objects showing the damage. If the game object at that index is not active then it will be activated and the loop is broken. On the other hand if that damage is already shown, it will continue as long as it finds one that is not.

Showing the boss’s Damage method.
The boss’s Damage method.

Once the health reaches zero the death sequence is started with the OnDeath method. It gives the player the points earned, then it stops all the spawning, after that it will pick three different damage points where explosions are instantiated. The hash set is used to store these points because of its feature that every stored item has to be unique, this ensures that three different damage points are selected.

Showing the OnDeath method.
The OnDeath method.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store