ClickBall

This site is no longer maintained. It has moved to http://ictmindtools.net




ClickBall










   
The first game that we will make is a simple game with a ball that bounces around and you have to click on the ball to score points.

As soon as you start, save your game as ballbounce  (Make sure that you save it regularly)

   

 

If you click on the icon, you can see a video of  each set of instructions.

Some of the videos are quite long, but you can watch part of a video, then pause it to complete the steps in Game Maker.  The videos have play controls at the bottom.

 

Step 1 Set up the Game area

Start Game Maker and create a room where the action will happen:

Click the 'Add Room' icon

Choose a background colour

In settings, make the room caption 'Catch the Ball'

 

Step 2 Add in the Sprites you need - a ball and a wall

Click the 'Add Sprite' icon

Name it sprBall

Click Load Sprite, and find the ball image.

We also need a wall sprite . Find it in the Pacman folder. Name it sprWall

 

Naming Sprites, Sounds & Objects

If you name every sprite sprXXXX you will not have any problem separating them from the sounds, which we will call sndXXXX or the objects which we will call objXXXX.

Imagine for example that you have a sprite called "Bullet", an object called "Bullet" and a sound called "Bullet". Now, when programming, which is which?

Only use normal characters like letters, numbers and underscores when making a name. Never use spaces or weird characters like slashes, asterisks, dollar signs, ampersands, and similar. Also, don't start with a number, use it only later in the name.

Step 3 Create the objects and add them to the room

  • Next we will create ball and wall objects (Remember we have created a ball sprite, but you need an object to put in your game.  A sprite just represents the object.)

Click the Add Object icon

Name it objBall

Choose the Ball sprite to represent the object, but don't make it solid. (It's best not to make moving objects solid.)

Add in a wall object.  Name it objWall, choose the Wall sprite, and make it solid.

Don't make moving objects solid.  It interferes with the Game Maker collision detection system and your object may become 'stuck'. 

 

  • Put it in the room and add a wall

 

Open the room

Add in a ball (left click)

Add in walls (hold Shift and click)

 

Step 4 Set up the Events for when your game is played

Events are the things that happen in your game. As your program is now, when your game runs nothing happens.  You need to set up what you want to happen when the game starts.  We want the ball to start moving in a random direction.

Open the properties for the ball object

Add in an Event for when the ball is created.

Choose start moving in all diagonal directions at speed 8

 
Setting the speed to 8 means that the ball moves 8 pixels for each step of the game.  If the game is running at the normal speed of 30 frames per second, then there will be 30 steps every second.  (You can change the game speed in the settings tab of the room properties)    

  • The ball now moves, but just continues through the wall.  Next we want to set a bounce action for when the ball collides with the wall.
Add in an event for when the ball collides with the wall.

Set the ball to bounce.

So far our ball movement is very boring and predictable, but we will fix that later.

Add in an event to the ball object for when the left mouse button is pressed.

Set the score to 1, but make sure you choose Relative.

 

Left Button vs Left Press

If you choose the left button event rather than the left press event, the score will keep going up if you hold the mouse button down.  This is because the Left button event will continue to generate events while the button is held down.  If you change the event to Left Press, then only one event is recorded.

Relative

If you don't tick relative for the score, each time the user clicks on the ball, the score would be set to 1.  In other words, the score would always stay on 1.

Ticking relative means the score is 1 more than it was before.  In other words it will keep going up by 1.

 
   
Set up an event of your own to make a sound when the user clicks on the ball and a different sound when the ball bounces on the wall.

You will first need to add the sounds you need into your game.  Then use the Main tab in add events to the ball object.

 

 

Let's improve our game so that the ball does not move so predictably.  Approx every second we will make the ball change direction.  We will do this by setting an alarm clock to trigger an event every second. We need to set the alarm clock when the game first starts, then each time the alarm goes we will make the ball change direction and reset the alarm.
   
Change your game so that the ball does not move so quickly and changes direction every 2 seconds.

Step 5 Ending your Game

Let's say we want the game to end when the player's score is 20. Each time we add to the score, we will check whether the score is equal to 20. 

Step 6 Tidying Up

Let's improve the appearance by setting a background.
Now add information to tell the user how to play the game.

 

  • Change your game so that there are 2 balls bouncing around. Save it as 2ballbounce
  • Open your ballbounce game again. Change your game so that the ball starts off very slowly (speed 1) but every time the user clicks on it, the ball moves faster.  Save it as bouncefaster
  • Open your ballbounce game again. Change your game so that something other than a ball bounces around. (Hint: You can leave the ball object unchanged, just change the sprite.) Save it as bouncegame

 

   

Ending the Game more Gracefully

You will notice that the game ends very abruptly.  We can improve this by creating a text object and putting it in an ending room.

Save your finished game as ballbounce

Making your Ball Bounce Accurately off Walls

To do this, you need to treat horizontal and vertical walls separately.  Create sprites and objects for a ball, a horizontal wall block and a vertical wall block.
Add a room and draw a box around the ball using the sprites.
Now we will start the ball moving in a random direction and set events to make the ball bounce. 

Save your game as randombounce

 

Which way is up?

Directions are measured in degrees, where 0 degrees is in an Easterly direction or to the right.  90 degrees is Northerly or straight up, 180 degrees is Westerly or to the left, 270 degrees is South or straight down.

Random(360) will create a random direction between 0 and 360 degrees.  Random(90) will create a random direction between 0 and 90 degrees.

If you want to make an object move vertically but randomly within 40 degrees, for its direction you could use 70+random(40).  This would give directions between 70 and 110 degrees.

What code would I need to use to move randomly in any upward direction, but not downward?


This page has been produced by Margaret Meijers.  Questions concerning its content may be directed by email to margaret.meijers@education.tas.gov.au.  This page was last modified on Sunday, 24 May 2009. The URL for this page is http://www.mindtools.tased.edu.au/gamemaker/tutorials/clickball.htm .
This work is licensed under a Creative Commons Licence.
Some pages of this site have been developed with support from the SiMERR Project.