Asteroids
1 Making The Ship

Section Menu

Asteroids Home | 1 | 2 | 3 | 4 | 5

Launch Game Maker and save your file with a suitable name.

Create a sprite called spr_ship and load the ship graphic from the resources page.

Game Maker Screenshot

Notice that this graphic has 72 subimages. These are images of the ship rotated through various positions.

Create an object using this sprite and call it obj_ship.

Game Maker Screenshot

Create a new Room and make its background black. Add the ship object to the centre of the screen.

Game Maker Screenshot

Rotating The Ship

Open up the ship object window. We will sort out the rotation first.

Add an End Step event and drag in a Change Sprite icon. Fill in the pop-up as follows.

Game Maker Screenshot

At the end of every game step, the ship will be drawn with the subimage that matches the direction in which it is facing. There are 360 degrees in a circle, we have 72 images, for every 5 degrees of rotation in the complete circle.

Game Maker Screenshot

Now add a Keyboard event and choose Left. Drag in a Move Free icon and fill in the pop-up as shown,

Game Maker Screenshot

The keyboard event for the Right button is similar but with the following change in direction,

Game Maker Screenshot

Your ship objectwindow should look like the screenshot,

Game Maker Screenshot

Save and test that the ship can be rotated in both directions using the cursor keys.

Managing Thrust

In the classic game, the player can thrust the ship and move around the screen. We will thrust with the Up key and slow down with the Down key.

Add a keyboard event for the Up arrow key. Create a new sound called, snd_rev. Drag a Play Sound icon into the event you created and play this sound when the key is pressed. Also drag in a Set Variable icon and fill it in as shown.

Game Maker Screenshot

Save and test this. The ship goes off the screen very quickly if you hold the key down for too long. We need to make the ship reappear on the screen when it goes off the edge. To do this, create an Outside Room event and drag in the Wrap Screen icon, filling it in as shown,

Game Maker Screenshot

Save and test again. That's better, but we need to be able to slow down. Add a Keyboard event for the Down key. We can only slow down if the ship is moving. We need to check this. Drag in a Test and fill it in as follows,

Game Maker Screenshot

Drag in a Start Block followed by a Set Variable icon, filled in as shown.

Game Maker Screenshot

Finish with an End Block, save and test.

⇐ Previous | Next ⇒