They’ve engaged shields!
In the last article, I implemented balanced spawning between enemies and powerups. Today, I’m going to be continuing the second, and final, phase of the GameDevHQ 2D Game Development Certification track. In this article, I’ll be adding enemy shields! The requirement reads as follows:
- Provide logic for some enemies to have shields
- Shields allow the enemies to take 1 free hit.
My first step to completing this task was to give the enemy script some of the same properties that the player script has for enabling shields and the shield visualizers. Adding shield strength, booleans to track if the shields are active, and a Visualizer object are all brough into the script.
Since not all enemies will have shields I also provided a percentage chance field and made it configurable from the editor.
Next during the initialization of the enemy I calculate whether or not the enemy has shields based on the percentage chance.
I then added the code to handle the shields being active to the collision detection code on enemies.
The last thing I did was to prefab the shield visualizer from the player object and then drag the shield visualizer prefab onto each type of enemy in their prefabs.
In this article, I implemented enemy shields. Next time, I'll be adding an aggressive enemy type! If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.