Asteroids

1 Making The Ship

Before starting to make this game, make sure that you have copied all of the sprites and sounds from the Game Resources page.

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.

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.

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

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.

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.

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

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

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

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,

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,

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

Finish with an End Block, save and test.