This week we did our last iteration on Shootah and added a Bomb to be dropped by the enemy to try to hit the player.
We copied the existing Bullet class and called it Bomb instead. The main changes we had to make were:
- Changing the speed to a negative number so that it moved down instead of moving up (as the Bullet does)
- Changed the check for the top of the screen to one for the bottom of the screen instead (to account for the fact it moves down)
- Changed the check in its hit() function so that the Bomb doesn’t interact with the Enemy when it’s dropped, but will be marked as inactive it if hits anything else.
- Changed the colour of the bomb to red
It happened that the code we had already written to manage bullets was already perfect for managing bombs as well.
We used Visual Studio Code’s built-in capability to automatically rename symbols to:
- Rename the bullets array to projectiles
- Rename the manageBullets() function to manageProjectiles()
This was enough to have bombs move, draw and be removed when it becomes inactive.
We added a new function to Ememy called shoot(). In that function we generated a random number from one to two hundred. We then dropped a bomb every time that number was less than five (we tuned this small number to get a good rate of bomb drops). This meant that the enemy dropped a bomb at random intervals, to make it impossible for the player to anticipate.
The files for this week can be found on our GitHub repository.