Ghost Invaders

2 Moving The Ship

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.

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.

Your ship object should now look like the 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.

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.