IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help


Drag 'n Drop Programming
using Game Maker

Pong is one of the 'oldest' 2-player games played on computer. Indeed it was one of the first to be tried commercially and game-starved geeks everywhere flocked to play it. Pong has an amazing history - read all about it.

The following recipe will allow you to construct a complete ONE LEVEL game of pong. All assets and instructions are included to allow you to construct a 2 player version without the use of ANY code.

In case you cannot wait, play the finished version first:
pong - the game that started it all

Before you start - make a folder in your H: drive and call it pong - this is where everything associated with the project will be stored. Now collect the game's graphical assets:
bat1 bat2
bouncywall endwall
r-click and save-as each of these
files to your pong project folder

The instructions that follow assume you can see that there are duplicate processes, with different names (one paddle acts like the other, for example). As such, some detail has been omitted else this recipe would be miles long. If you are unsure of steps missing, ask for assistance.

  First you add the sprites (graphical components) that your game will use - we need to add 5 sprites as each of the above graphics have particular jobs to do later in the game. The name of the sprite doesn't really matter but it is good practise to give them descriptive names.
  When adding a new sprite, you can browse to find your asset files - they can be all sorts of files - typically a sprite is in multiples of 32x32 pixels wide (icon size). If you want them to move then animated gifs can be used.
  Once your sprite for the ball is loaded, you get a preview of it, and the ability to edit it as well. Notice the transparent tick indicates that there is a colour that will be rendered see-through, and the colour can be found as the TOP LEFT pixel of the sprite. You have 5 sprites to add for this game.

Once you have your sprites, you must create OBJECTS that use them - the main way sprites make it onscreen and visible in a game is by being associated with an object.

Objects in a Game Maker game do things like respond to events and that is what we will get them to do soon.

You have 5 objects to create for this game.

You need to create an object for each of your sprites. It is possible to have the same sprite in many different objects, but in this game we have a sprite for each.

Look carefully at the collection of SPRITES and OBJECTS that are listed opposite. The gobblewalls will be animated bricks when the game is playing whereas the bouncewall is just stationary wall bricks that the ball will bounce off of.

The player1 and player2 objects are the paddles and will be steered up and down by the keyboard.

The ball will bounce around the screen, off the bouncewalls and paddles but not off the gobblewalls.

Notice there is also a ROOM added in the game tree - that is going to be set up as the space where the game takes place.

Double-clicking on an object brings up it's edit screen - more on that later.

YOU SHOULD SAVE your game before going on
- FILE-> saveas and put it in your project folder also.

When you have created your room, you paint the objects on to it - use the picture opposite as a guide as to where to put them. The LGobblewalls are the bricks on the left-hand end, RGobblewalls are to the right. The top and bottom walls are made up of bouncewalls. I placed the bats and ball central to the game space as that is where I want them to start off.

Save every 5 minutes or so to prevent loss of your game.

Close your room and double click on the Player1 object to open up the event builder. Then click on the ADD EVENT button to get a list of things that could happen in your game.

Player1 is a paddle so we want to make it sensitive to the keyboard - the "A" key to move up and the "Z" key to move down.

In the Keyboard events, select letter -> A from those things on offer.

Notice that there are lots of keyboard events that objects can listen and react to. We have to anticipate the things the user wants to do and build event handlers for those things.

Each paddle will react to 3 things happening. Paddle 1 will "bounce" off the top and bottom walls if it hits a bouncewall object, and will move UP if the "A" key is pressed and DOWN if the the "Z" key is pressed.

For each event, click-drag the appropriate ACTION into the actions box. The order here does not seem to matter.

To control an action, double-click on the action icon to bring up the action details box.

The box on the left shows the correct settings for a bounce against objects action where you want the bounce to riccochet naturally off
(geekspeak: angle of incidence = angle of reflection).

We will call this a riccochet and use the same process in a little while.

To cope with the keypress, the start moving in a direction action needs to be added and configured - double click on it's icon and then select UP for the "A" key with a speed of 5. Similarly, pick DOWN for the "Z" key with a speed of 5.

You would repeat the previous instructions for the second paddle player2 (except use the up and down arrow keys instead of "A" and "Z")

Once you have configured the paddles, we have to define the Events and actions for the ball. As you can see, there are a few. To summarise,

  • we want 4 things to happen when the ball is first created (start moving in a direction; set health to 5; set lives to 5; set the window caption info)
  • cope with a collision with a bounce wall (riccochet)
  • cope with a collision with player1 (riccochet)
  • cope with a collision with player2 (riccochet)
  • cope with a collision with Lgobblewall (described later)
  • cope with a collision with RGobblewall (similar to LGobblewall)
  • Run out of Health (player1 wins)
  • Run out of Lives (player2 wins - similar to player1 winning)
To make things simple, when the ball is first created, it should be moving - I decided it would be fine to always have the ball served by player1. Double-click on the start moving in a direction action, select top-right, and enter a speed of 5. Much faster than that and it is really hard to actually hit the ball.

Scoring in this game is a little klunky but workable - we will use LIVES for player 1 and HEALTH for player 2. You can display on the title bar of the game the current values for these values - enter details as shown left.

Notice the HEALTH CAPTION has some extra typing in it to separate the values out a little, otherwise they tend to be printed too close to each other.

The collision of the ball with the bouncewall should be a simple bounce - we use a riccochet as done earlier
When the ball hits player1 (a bat), the bounce is a riccochet as done earlier. The same should be done for the collision with player2

More complex things happen when the ball goes out of play (hits a wall behind a bat). The LBOUNCEWALL collision has 4 actions:

  • decrease LIVES by q
  • re-position the ball to the middle of the screen
  • serve it (reversing horizontal and vertical directions makes the ball come from the winner of the point)

Setting the lives to what they used to be minus one is fairly straight forward. The new lives value is set to lives-1.

This means that each time the ball hits the LGOBBLE, the LIVES gets decreased as player 1 let one through.

You do the same thing for RGOBBLEWALL except it is the HEALTH that is decreased (meaning player2 let one through)

Notice that the actions in the collision with RGOBBLEWALL are almost the same as the LGOBBLEWALL. The only difference is the HEALTH is decreased by one.

NO MORE LIVES is simple - a MESSAGE is displayed saying PLAYER2 WINS and the game is restarted.

NO MORE HEALTH is similar except the message displayed is PLAYER1 WINS

explore Sounds can greatly enhance the game - a simple addition would be a sound when the ball collides with the bat, rebounds off a wall or goes out of play - can you work out where to place those actions?
goto TOP
goto HOME



©Copyright t 1992..2018+. Edition 26.150117
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License