Create A Game Yourself!

Published Date
01 - May - 2006
| Last Updated
01 - May - 2006
Create A Game Yourself!
If you've just read the article about young Shashank H R, you're probably itching to get started on a game of your own. Here, we'll create a simple, one-level version of that ever-loved classic, Arkanoid.

STEP 1. The Cast
After you've installed Game Maker from the Digit CD and fired it up, the first step is to add all the sprites you're going to use. Sprites are just images that will play different roles in the game. For this game, we'll need a bat, a ball, a wall and a brick. Select Add > Add Sprite and click on the Load Sprite button in the dialog. Game Maker comes bundled with a load of example sprites, so you don't have to hassle yourself making your own. Find the sprites here:

Ball: <Drive>:Program FilesGame_Maker6Spritesvarious (pick any of the Ball icons from here)
Bat: <Drive>:Program FilesGame_Maker6Spritesbreakoutbat1.gif
Brick: <Drive>:Program
Wall: <Drive>:Program FilesGame_Maker6Spritespacmanwall.gif
Make sure you name the sprites appropriately.

STEP 2. Walls And Bricks
Just loading sprites isn't enough-you need to turn them into objects to make them interact with each other in the game. We'll start by creating an object for the wall. Go to Add > Add Object. Call the object

Creating the Wall object

"wall_obj" and click on the button under "Sprite" to choose the Wall sprite. This is going to be a solid object, so check the Solid checkbox. Repeat the same procedure and create an object for the Brick as well.

STEP 3. The Bat
We'll do more in the Add Object dialog this time. Once we've added a Bat object (the way we did for the wall), we need to define what it's going to do in the game:

Setting up the Bat

(a) Move left when we press the left arrow; ditto for the right
(b) Stop when it touches the wall

The Event selector

For the first requirement, we'll create a Key Press event that tells the bat to move when one of the arrow keys is pressed. Click on the Add Event button and in the Event selector that comes up, click on Key Press and choose Left. From the Move panel on the left, drag the "Start Moving in a Direction" icon (the red one with arrows in all directions) into the Actions region. In the dialog that comes up, depress the left arrow and set the speed to 5. Repeat this for a Right key press event.

We also need to stop the bat when the arrow keys are released, so repeat the same procedure for Key Release events for the left and right arrows, this time setting the speed to 0.

Finally, we also need to stop the bat when it touches the wall. Add a Collision event, and select the Wall object. Again, drag the Start Moving in a Direction icon and choose a speed of 0.
STEP 4. The Ball
The ball is the heart of the game, and we'll be creating lots of events here. The first thing we want it to do is move in a random direction when the game starts. To do this, add a Create event and drag the Start Moving in a Direction icon into the Actions region. Depress all three arrows at the top to make it choose a random upward direction. Set the speed to "8".

Setting up collisions for the Ball

The next thing we need to do is create a collision even for the bat. The ball is supposed to bounce off it, so drag the "Bounce Against Objects" button from the Jump panel on the right. In the dialog that comes up, select "Precisely" and "Against All Objects". Do the same for the brick and the wall, but choose "Against Solid Objects" this time.

You're supposed to lose the ball if you miss it, so we'll delete it if it leaves the room. From the Event Selector, choose Other, and select Outside Room. Select the "main1" tab from the right and from under the Objects panel, drag the Destroy the Instance icon (the one that looks like the Windows Recycle Bin) into the Actions region.

STEP 5. Back To The Bricks
Edit the Brick object again and add a collision event with the Ball object. Just like you did for the ball, create a "Destroy the Instance"

Adding points to Bricks

Action for the brick. Finally, we'll add a score point every time a brick is destroyed. To do this, add a Destroy event, and from the Score tab on the right, drag the Set the Score icon (the first one) to the Actions region. In the dialog, enter the points you want to add after each brick is destroyed and make sure you choose Relative so that scores are added and not just assigned.

STEP 6. More Balls!
We've created an event where the ball will be destroyed if missed, but we also need to create a new ball each time. You could create the ball automatically, or wait for the player to hit a key. We'll do the latter here, but the procedure remains the same-you just need to know which event to assign the action to.

Checking the number of Balls in the Room

Edit the bat object-add another Key Press event for the space bar. We're first going to see if the previous ball has indeed been destroyed-there should be 0 balls in the room. Select the Control tab on the right and choose the "If the number of instances is a value" icon from the Questions panel. In the dialog, choose the ball object as the object you want to check, the number is 0, and the operation is Equal to.

If there aren't any balls in the room, we'll create a new one, and also pile on a score penalty of 10 points for needing to create one.

To create a new ball, select the Create Instance of Object icon from the "main1" tab and choose the ball object in the dialog.

Finally, add a Set the Score action to this, set the score to "-10" and choose Relative.

Placing objects in the Room

STEP 7. The Room
Now that we've set up the game's rules and the objects' behaviours, we need to create a room for all this to happen.

Go to Add > Add Room to add one. In the Room Properties dialog, you can place all the sprites where you want them.

Click inside the Objects panel to select the object you are going to place in the room. Click in the room layout to place the object. Start with the wall object and place them along all but the bottom edge of the room. To remove an object from the room, right-click on it. Do the same for the bricks, the ball and the bat.

You're done! Run the game by clicking on the Play icon on the toolbar.

This is, of course, nowhere near as complex as the original Arkanoid-you can add a lot more: special bricks, power-ups, monsters… anything you like. You can also create new levels (rooms) and rules for the game. Go wild!  

Team DigitTeam Digit

All of us are better than one of us.