Main Plane

Remember the (X,Y) for GameMaker...

Plane moving

Obj: myplane

Create the myplane object (make sure you name it with no spaces). This is the plane the player will control. Give it a depth of -100 to make sure it lies above bullets etc.

 

 Our main concern is to avoid the plane moving outside the room.

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

Moving Horizontally

Note: all the Jump actions below are relative!

For the horizontal motions, we check and change the X values...

  • <Left>
    • Test Variable: check if x > 40, if yes, then
    • Jump to Position (-4,0)
  • <Right>:
    • Test Variable: check if x < 600,
      (so margin of 40 px from edge, room width = 640)
    • Jump to Position: (4,0)

Moving Vertically

Now for the vertical motions, we check and change the Y values based on where it is in the room view... 

  • <Up>: if  y > 40, then Jump to (0,-2)
    So the plane can't go above the room view
  • <Down>: if y < 360, then Jump to (0,2)
    Remember our room height = 480 pixels; we need more room at the bottom for our score panel which is 76px high, and our plane is 65 px high - since the plane is centered, we're testing if score panel (76px) + half the height of the plane (65/2 = 33) = ~110 and adding a bit more room. So 480 - 120 = 

Room

  1. First change the grid X to 320, and Y to 120.
  2. Then place the plane at the middle of the bottom like this...

Test it out - check that you can move the plane but it cannot move out of the room at the top/bottom, or off the sides.