Aeroplane Shooting Game Tutorial – Adding Enemies


As of now we have a player plane which can be controlled using the keyboard. The player plane can shoot bullets so we need now some enemies to dodge and shoot at. We are going to add the enemies in the same way we dealt with the player bullets. We are going to use a Vector which stores the enemy planes. We add 2 members to our main class: the vector storing the enemies and a variable to define the enemy speed, so we don’t hardcode it.

Unlike the player bullets the enemies creation is slightly different. We create the enemies in the top part of the screen at random x positions and at random times. We add a new method which creates the enemies:

At this moment we have the function which creates enemies but we have to trigger it(at random times). In enterFrame method we add the code to create enemies at random times, the code to update enemy planes positions and to destroy the enemies which went out of the screen boundaries:

Now that we have enemies we need to add them the functionality to shoot bullets. First of all we create a new method to create a bullet for a specific plane.

Then we need to invoke the function as we did for the enemy planes. We add the following code in enterFrame method to deal with the enemy bullets(create, update positions and destroy the bullets getting out of the screen boundaries).

Now the output of this tutorial looks more like a game. We have a player plane shooting bulets, enemies planes shooting bullets too, coming from the top. We didn’t deal yet with collisions, this will be handled in the next part of this tutorial.

Browse the code for this part here.

One thought on “Aeroplane Shooting Game Tutorial – Adding Enemies

Leave a Reply

Your email address will not be published. Required fields are marked *