When you open the starting file, you should see a “+” beside Objects – when you expand the folder, you should see these objects.

FYI: if you are interested in how the X & Y values are chosen for moving the planes, look at this below…

Our main concern is to avoid the plane moving outside the room. First we check if the plane is able to move (not too close to an edge) using Test Variable; if we can, then we move it a little bit using Jump to Position (needs to be relative to where the plane is currently!)

Remember the (X,Y) for GameMaker…

Here an explanation of how we get the X & Y values for the next part.

moving DOWN, we need to make sure our plane is above our bottom score panel we will be adding later (which is 76px high), so 76 + 40 = 116 and adding a bit more room. So 480 – 120 = 360

Our plane sprite =65 x 65 px. Distance from edge of plane = 65/2 = 33.

moving LEFT, we need to make sure our plane is at least 40 for x.

moving RIGHT, we need to make sure our plane is 640 – 40 = 600 for x.

moving UP, we need to make sure our plane is 480 – 40 = 440 for y.

Main Plane Flying

Moving Horizontally

Go into the myplane object…

Add a <Left> Keyboard event:

  • Test Variable: check if x > 40, if yes, then
  • Jump to Position (-4,0), relative

Add the <Right> Keyboard event…

  • Test Variable: check if x < 600
  • Jump to Position: (4,0), relative

Moving Vertically

Add the <Up> Keyboard event…

  • if y > 40
  • then Jump to (0,-2), relative

Add the <Down> Keyboard event…

  • if y < 360
  • then Jump to (0,2), relative

Save & test your game, you should be able to move the plane in the first room “Testing: Flying”

Enemy 1 Flying

Go into the enemy1 object…

Create event

First add a Create event …

  • Vertical Speed: 4 (= moving downward)

Step event

Add a Step event.

  • Test Variable: if y > 512
    Checking if enemy plane gone past the bottom of the room, so
    480 (room height) + 32 (height of plane) = 512
    has the plane gone past the bottom of the room?
  • If so, Jump to Position: x = random(room_width) and y = -16
    so it starts above top of the room

Save and test the game. Once you’re in play mode, hit the ‘N’ key to skip the first room, to go to the “Testing: Enemy 1” level.

  • do they fly down when in the room?
  • once they’ve gone out the bottom, do they reappear at the top?

Enemy 1 Controller

We’ll create a controller to keep creating enemy1 planes with a bit of delay.

Go into the object enemy 1 controller

Create event

Add a Create event…

  • Create Instance: enemy1 object,
    X = random(room_width) and Y = -16
  • Alarm1 = 100

Alarm 1 event

Duplicate the Create event for Alarm1 event.

Then add a Test Instance Count action at the top. If there are less than 8 of the enemy1 planes in the room, then we will create another enemy1 plane.

Test out if it works. If it does, continue.

Shooting Bullets

Bullet Moving, Destroy Itself

Go into the bullet object. Add a Create event….

When the bullet is created, we want it to move upwards so Set the vertical speed to “-8”.

Next we add a Outside Room event. We have to destroy it once it leaves the room or else you’ll have more and more bullets flying around.

  • Destroy Instance: default, destroys itself

Player Can Shoot

We want the bullet to appear when the player (who controls the main plane) hits the space bar. Go into your myplane object and add a Space Bar event.

  • Create Instance: we create a bullet just in front of the plane (0,-16). Make sure its relative so it’s just in front of the plane (not top left corner of the room!)

If you test it out, you’ll see something like this…

Bullets Spaced out

We don’t want too many bullets at a time, so only fire 2 bullets every second (= 15 steps).

In the myplane object, add a Create event…

  • Set Variable: set the variable can_shoot to “1”

Go into the <Space> event you already have. We’ll first test if we can shoot, and if so, we’ll create a bullet, and then set a timer/alarm…

  • First we check, are we allowed to shoot? (= if “can_shoot” true/1).
    Test Variable: if can_shoot = 1

Then add the following actions…

  • Set Variable: set the variable can_shoot to 0 (false, indicating we can no longer shoot).
  • Set Alarm0: to 15. The alarm ticks down to 0 with one tick each step. You can change the speed with which you can shoot by changing the value of the alarm clock.

Add Start and End blocks around the actions as shown below…

You will also need an event Alarm0 – what happens then the alarm reaches 0, runs out of time? In this situation, we want to set the variable can_shoot back to true/1 so the plane can shoot again.

Now if you test it in your room, the bullets should be spaced out…

Enemy 1 Hit

If the enemy plane is hit by a bullet, then the enemy plane should be destroyed.

Enemy1 Hit by Bullet

Go into your bullet object and add the following event: Collision with enemy1

  • Create Instance: set to ‘other’ (so enemy1 plane turns into explosion, in the same place as the enemy plane)
    object = explosion1, (0,0), relative
  • Set Score: give the player 5 points, make sure relative
  • Destroy Instance: (self = the bullet)
  • Destroy Instance (other =enemy1 plane)

Explosion 1

Go into the object explosion1. The only thing we need to do is add an Animation End event so that once the explosion animation has played, it destroys itself.

Test it out . Hit the ‘N’ key to skip the first room, to go to the “Testing: Enemy 1” level.

Check if you hit your enemy1 plane with a bullet:

  • does the bullet disappear
  • does the enemy plane explode/disappear?