Ghost Invaders
2 Moving The Ship

Section Menu

Ghost Invaders Home | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

When the ship is first created, we want it to jump to the bottom centre of the room. Add a Create Event and drag in the Jump To Position icon into the actions window. The position you want to jump to is x 140 and y 295.

Game Maker Screenshot

The ship will move when we press the left and right cursor keys. We don't want the ship to move off the screen so we will only allow the player to move the ship if it will not go off the screen.

Click on Add Event, Keyboard, Left.

Go to the control tab and drag the Test Expression icon into the actions window. The expression you want to test is x>=5.

Drag in a Start Block (up arrow) and an End Block (down arrow).

In between the two arrows, add a Jump To Position icon and set x to -5, y to 0 and click on Relative.

Game Maker Screenshot

Your ship object should now look like the screenshot.

Game Maker Screenshot

Click on Add Event, Keyboard, Right. Go to the control tab and drag the Test Expression icon into the actions window.

The expression you want to test is x<=room_width-32.

Drag in a Start Block (up arrow) and an End Block (down arrow).

In between the two arrows, add a Jump To Position icon and set x to 5, y to 0 and click on Relative.

Game Maker Screenshot

Save your game and test to make sure that the ship movement works as it should. Your ship should move left and right without going off the edge of the screen.

⇐ Previous | Next ⇒