Download as pdf or txt
Download as pdf or txt
You are on page 1of 253

GameMaker Studio Book

A Beginners Guide
To
GameMaker Studio
2014 Edition

Ben Tyers
Copyright © 2014 BEN TYERS
All rights reserved.
ISBN-13: 978-1497393837

ISBN-10: 1497393833
CONTENTS

1 - Getting Started Introduction


2 – Game Assets
3 – Designing Your First Game
4 – Brick and Ball Game – Sprites
5 – Brick and Ball Game – Creating the Game
6 – Brick and Ball Game – Refining the Game
7 – Spot the Difference Game
8 – Spot the Difference Game – Refining the Game
9 – Hangman Game
10- Memory Card Game
11 – Tower Defence Game
12 – Side Scrolling Shooter Game
13 – Book Review
ACKNOWLEDGMENTS
Many thanks to Mark Overmars and YoYo Games for some truly awesome software.

Edited by Charlie Saunders.

i
Resources

Free Resources For Projects In This Book Are Available For Download At:

Http://www.GameMakerStudioBook.com/Resources
Chapter 1

Getting Started
BEN TYERS
Introduction

Congratulations if you’ve just downloaded Yoyo Games’ Gamemaker Studio.

Gamemaker is an amazing piece of software that allows you to create games, ap-
plications and proof of concepts then export them to an array of different devices including
Windows, Windows 8 (Native , Javascript and Phone), iOS, Android, HTML5, Ubuntu
(linux), and Tizen (Javascript and Native) at the time of writing.

To start making games with GameMaker Studio you need little prior knowledge or skill.
Using the program’s built in game creation tool called Drag and Drop; you can create games
without writing a single line of code. As you get more proficient, you can start to learn the
scripting language called GameMaker Language (GML).

This chapter will prepare you better, ensuring you approach your game design and pro-
gramming in logical and methodical way, and answer some general questions about games,
game design and programming.

For the purpose of this book; references, drag and drop, and coding relate to the regis-
tered Windows GameMaker Studio Version.

To start off with you'll learn the basics of GameMaker (GM) using it's built in GUI
system known as Drag and Drop (D&D). This system allows you to create simple games
without the need for any programming or coding knowledge. As you work through this book
you'll learn how to replace this with the more flexible coding known as GML (Game Maker
Language). The first part of this book focuses primarily on D&D, and gradually introduces
GML as you work your way through.

You will build a game made up of several elements including sprites, sounds, objects,
events, rooms, and backgrounds. Scripts/coding (GML) and tilesets are covered later in the
book.

4
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Installation
Visit http://www.yoyogames.com/studio/download to download the trial version or to
buy the full version.

Instructions below.

Free Version Installation:

Figure 1-1. Showing Download Page

Click the ‘Download GameMaker: Studio’ button to commence download, as shown in


Fugure 1-1.
Once downloaded, double click and then choose ‘Run’ as shown in fugure 1-2.
Read through the agreement and click ‘I agree’ if you agree. Then click ‘Next’. You can
then click ‘Next’ again to install in the default path, or change it if you wish to install some-
where else.
On the website, as in Figure 1-1 choose ‘Buy GameMaker: Studio’. There are several
packages you can buy: Standard, Professional and Master. If you’re just starting off then the
Standard package should suffice. The Professional Collection allows for team features. Where
as the Master Collection allows for exporting (creating games on different systems, such as
Android, HTML5 and Windows 8). If you buy the Standard or Professional, you’ll have the
opportunity to buy extra export modules as required. The Master collection has the bonus that
you’ll also be entitled to all current and future export modules of Gamemaker: Studio.
For the paid versions you’ll need to enter some details and make a payment. After pay-
ment, you’ll receive a license code which you enter in GameMaker: Studio to unlock and
upgrade to the full version and enable any export modules you’ve purchased.

5
BEN TYERS
Tour of GameMaker Studio:
Depending on which version of windows you’re using you can then start the program.

For example Start>Programs>GameMaker-Studio 1.2 and the GameMaker Logo:


As shown in Figure 1-2 below:

Figure 1_2. Starting GameMaker in Windows XP, Vista.

Upon starting GM for the first time, after entering your license code (if you bought a paid
version), you’ll be presented with a screen like that shown in Figure 1-3.
Note: The projects in this book assume you have the paid version of GameMaker Studio.

Figure 1_3. Showing starting screen.

Create a new project called New_Project.


Next you’ll see this screen, as shown in Figure 1_4

6
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 1-4. Showing main screen.

On the left you’ll see folders with names like Sprites, Objects and Rooms. This is the
asset area. When you create an asset it will be placed here.
The icons along the top are primarily used to create assets.
For example, clicking the create object icon, as shown in Figure 1_5:

Figure 1_5. Showing create Object Button.

After clicking this you’ll be presented the screen as shown below in Figure 1_6.

7
BEN TYERS

Figure 1_6. Showing a newly created object.

On the right you’ll see actions. These are used to make things happen, such as make an
object move or play a sound.
Clicking the ‘Add Event’ will bring up the following window as shown in Figure 1_7
below:

8
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 1_7 Showing Events.

These events are used to test if something is happening, for example to check if the right
arrow key is pressed, as shown in Figure 1_8 below:

Figure 1_8. Detecting a key press.

You can then use actions to make something happen when a key pressed, for example
make the object move to the right, as shown in figure 1_9.
9
BEN TYERS

Figure 1_9. Making an object move right at a speed of 2.

10
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Objects
Objects are the main blood of GM. You use them in two ways, firstly to test if some-
thing is true, and secondly make things happen.
Display a sprite on screen.
Make a ball move.
Detect a key-press, mouse button or mouse movement.
Play a sound effect.
Create Artificial Intelligence (AI) for objects.
Detect collisions.
Change rooms.
Play background music.
Animate a sprite.
Display a message.
Respond to an event.
Change/Display the score/lives.
Draw something.
Create another object.
Create an effect.
Do / Create / change something else.

Throughout this book you'll gradually learn how to do all of the above, so I won't go into
any more detail here, but feel free to experiment with it as you go along.
Sprites
A sprite is basically a graphical element made up of one or more images that is displayed
on the screen. Sprites are displayed using objects. Examples of sprite graphics include:
Ball – Like the ball you'll create in the first part of this book that bounces around the
screen.
Key – Something you need to collect to open a door or go to the next level
Ghost – An enemy that follows you around and tries to kill you in a maze game.

It should be noted that objects and sprites are different. A sprite is an image that is dis-
played on the screen. An object is the tool to actually draw the sprite on the screen.

11
BEN TYERS
Events
An event, in simple terms, is something that happens. Events usually happen inside an
object. For the purposes of this book, I'll be focusing mainly on:
Create event (happens only once).
Key press.
Object hitting another object (called a collision event).
An alarm event (something happening after a set period of time).
A step event (something that occurs at regular intervals).
An object being destroyed.
Click a mouse button.
Draw event (draws the sprite, score, lives, text on the screen).

Events are then used to test, change or make something else happen, with an action:
Increase score.
Reduce lives.
Create a bullet.
Stop something.
Start something.
Change something.
Create something.
Move something.
Test something – like how many lives left or which level .
It's these interactions and changes that work together to create a game that interacts with
you, the player.
Using events and combining them with D&D allows you to manage, design and decide
what events happen if certain conditions are met. By combining the events and D&D in a
logical way, you can start to implement the design of your game. This can also be used as a
basis of an AI system to control objects not controlled by the player. Events will be dealt with
more later in the book.
Drag and Drop
Drag and Drop (D&D) is GameMaker's inbuilt GUI for creating games without any prior
programming knowledge. It allows for an easy way to create basic games. D&D also has its
GML (Game Maker Language) equivalent in code. As you get more advanced, you'll learn to
use a combination of D&D and GML, and in time move on to using just GML.
D&D is a great way to start developing games as the logic and approach is similar to
GML. As you progress through this book you'll learn most of the main functions of D&D and
be introduced to GML.
Using D&D you'll learn how to make things happen in response to another event, action,
or value, or occurrence.
For example:
Make a player move left if left cursor is clicked.
Decrease lives by 1 if player hits enemy.
Create a moving bullet if the fire button is pressed.
Make a ball bounce if it hits edge of screen.

Looking at the previous examples you'll see that each consists of two parts, part one
something happening, part two do something because of this. That's the basic of logical pro-
gramming, you're well on your way to becoming a great games programmer.
12
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
In this book you'll learn how to incorporate this into your design process. As you get more
advanced in D&D and coding you'll discover other logics, such as:
Do something if something isn't true.
Do something if (something and something else) is/isn't true.

13
BEN TYERS
Can I Sell My Game? How Do I Make Money?
Yes, you can sell your game. YoYo Games' Terms and Conditions for GM are pretty
relaxed and allow you to make and sell pretty much anything (except another Game Maker).
You don't have to acknowledge you used their software or pay any commission if you make
some or lots of money. Given that GM is so reasonably priced, you'd only have to sell a few
copies of your software before turning a profit.

With the ability to release your game on a variety of platforms, at time of writing – Win-
dows, Windows 8, Tizen Mac, HTML5, Android, iOS amd Ubuntu, the opportunity of
multiple revenue streams is available. You can for example release a demo version and charge
for the full version, or display on screen ads and earn ad revenue from each click or sale.

14
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Copyright

The following is brief outline only, as copyright laws vary from country to country. If in
any doubt contact a legal professional or the copyright, trademark or patent office of your
country. The following is not intended to be or replace professional legal advice.

Basically, if you didn't make something yourself or pay someone to make it for you, then
you don't own the copyright on it. A lot of people rip (copy) sprites and sounds from other
games to use in their own creations. Most major companies generally turn a blind eye if people
use this for home projects or educational reasons. If you start selling or otherwise start making
money, expect them to come knocking at your door.
Online there are a number of free repositories where you can get sounds, music and
sprites. Always check their terms & conditions or copyright policy before using.
If you're unsure, always email for permission before using.

15
BEN TYERS
How Do I Develop a Game?

The design process of any game is probably one of the most important steps in the devel-
opment process. Having a properly designed game speeds up the whole development process.
You may think that a simple game wouldn't need much planning, but as you'll find in Chapter
1, when you design a brick and ball game, having a well designed game makes the program-
ming of it much simpler. To start with you'll probably be designing and making your game by
yourself, so you won't need to consider team collaboration, but imagine what would happen
if you had a big team and no game design - it just wouldn't work. Having a well thought-out
plan will allow you to create resources for your game much more easily, set out rooms quickly
– as you'll know where everything needs to go, quickly track down bugs and errors, and easily
designate different parts of the process to other people. You will also know what events, con-
ditionals or interactions your game will require.

For a minute, consider the film industry. If you've ever watched one of those bonus DVDs
that come in some box sets, you would have seen something called a story board. Every scene
is planned out well in advance using a storyboard, like a comic, with each action or camera
angle in a different cell. This advance planning allows the actual filming process to be com-
pleted more accurately, and on time. Just imagine the chaos on set if no one knew where to
stand or where to point a camera?

I'm not saying you need to plan your games in as much detail as a film, just that planning
and design plays a very important part in the overall process.

It's also OK to ad-lib now and again if a great idea pops into your head when you're
programming – just remember to add it to your design notes.

16
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Chapter 2

Game Assets

17
BEN TYERS
Variables
What is a variable? In simple terms a variable is a value held in the computer's memory.
In GM there are two main types: Strings and Real Numbers
Here are some examples of strings:
“hello”
“big”
“What is your name?”
Here are some examples of real numbers:
1
7
3.14592
1999999
So strings are generally words, and real numbers are numbers.

You can add strings together:


For example example_string=”Hello “+”World” would set example_string as “Hello
World”. There other things you can do with strings, such as get the length(how many
characters), add/remove/change letters and words.
You can add real numbers together, so example_number=10+5, would set example_num-
ber as 15. You also perform other actions on real numbers, such as subtract, divide and
multiply, and use a wide range of mathematical operations, which you’ll learn about as you
work your way through this book.

Real values are signed floating point numbers. GM also allows hexadecimal
representation of real values in code (preceded by "$").

Below is an example for creating an object and adding together two string variables.
First create a new object by clicking on the create object button, a shown in Figure 2_1:

Figure 2_1. Creating a new object

Next name the object obj_example, and click add event, as shown in Figure 2_2.

18
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 2_2. Naming an object.

Next click the create event button, as shown in figure 2_3.

Figure 2_3. Create event

19
BEN TYERS

Navigate to the control tab, on the right of the screen as shown in figure 2_4:

Figure 2_4. Control Tab.

Next click the VAR button, as shown in figure 2_5, and drag into the actions window:

Figure 2_5. Adding a variable action.

Next assign a name and a value, as in Figure 2_6. Notice the quotation marks at the start
and end, this lets GM know it’s a string:

20
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 2_6. Setting a string variable.

Then click OK.


Repeat the process of adding a a new variable, word_two, and set as “World”, as shown
in Figure 2_7

Figure 2_7. Setting second string variable.


21
BEN TYERS

The click OK again.


Your screen should look like that shown in Figure 2_8

Figure 2_8. Showing both set variable actions.

Next click “Add Event” again and add a “Draw” event, as shown in Figure 2_9:

Figure 2_9. Creating a draw event

22
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next select the “Draw” tab as shown in Figure 2_10:

Figure 2_10. The draw tab.

Next click the “Var” button with the green outline, as shown in Figure 2_11:

Figure 2_11. The draw variable action.

23
BEN TYERS
Next set as follows, remembering to tick the relative box, as shown in Figure 2_12:

Figure 2_12. Adding two variables.

Click OK twice to close both windows.

24
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Rooms
Next we’ll create a room. Click the create room button on top bar, as shown in Figure
2_13:

Figure 2_13. Create a new room button.

Go to the ‘Settings’ tab and set the name as room_example, as shown in Figure 2_14:

Figure 2_14. Naming a new room.

Now go to the objects tab, create one instance of the object by clicking in the middle of
room, as shown in Figure 2_15:

Figure 2_15. Placing object in room


25
BEN TYERS
Next click the green tick at the top left, as shown in Figure 2_16:

Figure 2_16. Saving and closing room.

A room is the place where your game takes place. It will generally consist of a background
and objects. A game can have multiple rooms, for example; a game may have a menu room,
a room where the main game-play takes place and a shop to buy things. When you're starting
out it's fine just to have one room. As you get more advanced in GM you'll learn how to do
things such as: use multiple rooms, change the size of rooms, and create views for scrolling
games.

Finally, click the green triangle on the top bar, as shown in Figure 2_17:

Figure 2_17. Playing the created program.

If you followed the steps correctly, you should see something like that shown in Figure
2_18:

26
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 2_18. What the game should look like.

Now save your program as example_1 (File>Save As).


See if you can edit the program so you have your first and last name as separate strings
and display them together.
Real Numbers
You can also use real numbers to perform calculations, and draw the value of these num-
bers on the screen. The following gives a brief explanation of real numbers.
Firstly create new project by clicking the new project button at the top left, selecting new,
entering the name ‘example_2’ and clicking create, as shown in figure 2_19 below:

Figure 2_19. Creating a new project.

27
BEN TYERS
Now create a new object, as shown in Figure 20:

Figure 2_20. Create new object.

Name the new object obj_example, as shown in figure 2_21:

Figure 2_21. Naming a new object.

Now click the ‘Add Event’ button, followed by the ‘Create Event’, as shown in figure
2_22:

28
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 2_22. Adding a create event.

We will now program three variables, x y and z. This can be done by clicking the control
tab on the right and clicking the grey square variable as shown in figure 2_23:

Figure 2_23. Creating variables.

29
BEN TYERS
Create the following, as shown in figure 2_24, by repeating this process three times.

Figure2_24. Varaible x y and z set with numerical values.

Next create a draw event, as shown in Figure 2_25, by clicking on the ‘Add Event’ then
the draw event:

Figure 2_25. Creating a draw event.

30
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Now select the ‘Draw’ tab and then the draw variable action, as shown in figure 2_26:

Figure 2_26. Creating a draw variable action.

Program this draw action as shown in Figure 2_27, remember to check the ‘relative’
check box.

Figure 2_27. Draw variable action.


31
BEN TYERS
Click OK twice to close both windows.
Now create a new room, and place an instance of obj_example in the room, as shown in
figure 2_28. Do this by clicking the ‘Create Room’ button at the top, selecting the ‘object’
tab, then clicking in the room.

Figure 2_28. Creating new room and placing object in the room.

You can also go to the ‘settings’ tab and naming the room, room_1.
Click the green tick to save and close the room window.
Now save your game, by clicking File and naming it ‘example_game’.
To test your game, click the green arrow at the top of the screen. You should see some-
thing as shown in Figure 2_29.

Figure 2_29. Showing screen when game is run.

32
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Sprites and Objects
A sprite is a graphical element that is displayed on the screen. Some examples would be
a ball that bounces around on the screen, or a bat the player controls.

You can create a sprite by clicking on the sprite image in the title bar, as shown in Figure
2_30.

Figure 2_30. Creating a new sprite.

After clicking on the create sprite you choose to load or edit it. Click the load button and
browse to resources file: Sprites and Background For Examples >> brick and ball>> spr_bo-
nus_2_0.png
Load it in and name the sprite, sprite_skull, and click ok, as shown in Figure 2_31.

Figure 2_31. Loading in new sprite and giving it a name.

After creating a sprite you then need to choose an image file and give it a name. You can
call the sprite anything you want, excluding words that are pre-assigned to GM (see appendix
in back of this book for information on this). You can import various image files including
GIF, JPG, BMP, PNG).
A good housekeeping practice is reduce/edit/crop the image the file size of your graphics
files using external software. This will reduce the overall size of your game, make it load
quicker and may reduce some problems when playing. Sprites are drawn by using an object
event or code.

33
BEN TYERS
Although you can call your sprite almost anything, it's good practice, especially when it
comes to coding, to be descriptive. For a sprite, start the name with sprite_ or spr_ . The main
reasons for this are:
That you may create a lot of sprites, so using this method allows you to easily identify it
and make changes.
When you do start using GM this will prevent errors in your code (if you use a space in a
name in your GML will not understand the coding and will think it's two separate items).
Easily distinguish between objects, sounds and sprites.

Do not use spaces in your description, instead use _ (underscore), as you may also create
similarly named objects or sounds, and having sprite_ or spr_, sounds_ or snd_, or object_ or
obj_, allows you to identify it as a sprite, sound or object.
Good examples of names are:
(for sprites)
spr_ball
spr_chicken
spr_enemy_ghost
(or for sounds)
snd_bounce
snd_background_music_track_1
(or objects)
obj_ball
obj_wall

Bad examples are:


ball
music
ghost enemy
object arrow
bouncing sound

It's possible to do a number of different things with sprites. The end of this chapter will
start with the basics and progress throughout the book to cover more advanced sprite handling.
Most of the time you'll just be setting sprites to objects and drawing them on them on the
screen, as shown in the following example.
Create a new object, and name it object_skull, and then sprite the sprite you just created
above.
In simple terms, you place an object in your room. You'll then program it, using D&D or
code, to do certain things, such as the examples above. In the most part you will make it react
to events, introduced in this chapter, and do something as a result.
A good name for the start of an object is obj_ or object_. Objects can be assigned a sprite
and made visible (using a draw event) or invisible without a sprite (such as a control object –
control objects will be dealt with at the end of this chapter).
As shown below in Figure 2_32. Do not click OK, as you’ll be adding some more events
to it.

34
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 2_32 Creating a new object and assigning a sprite to it.

Now click Add event and select create event. As shown in Figure 2_33.

Figure 2_33. Adding a Create Event.

35
BEN TYERS
Next, select the ‘Move Tab’ and add jump to random position and click OK as shown in
figure 2_34.

Figure 2_34. Setting create event to make object jump to random position.

Next add a new event for detecting a mouse button release. Do this by clicking ‘Add
Event’ and then mouse, as shown in Figure 2_35.

Figure 2_35. Choosing mouse event.

36
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next set as release event, as shown in Figure 3_36.

Figure 2_36. Setting Mouse Left Release action.

Next add a jump to random position action in this event, and click OK twice to close all
windows, as shown in figure 2_37.

Figure 2_37. Adding a jump to random position action on the left mouse button release event.

37
BEN TYERS
Now click the new room icon at the top of the page and select the settings tab name the
room as room_test. Next select the objects tab and place in instance of object_skull in room.
Click the green arrow to save and close the room. Save the game as Mini_Game_1. You can
get the GMZ file for this files in resource folder /GMZ files/.
Now play this game by pressing the green arrow at the top of the window, as shown in
Figure 2_38.

Figure 2_38. Button to play the game.

Each time you click on the skull it should jump to a new position.

38
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Sounds
Various sound files can be used in GM, the main ones being, mp3, wav, and ogg. Sounds
can be things such as sound effects (bounces, boings, animal sounds, and other effects, voices
or dialogues) or background music.
The latest version of GameMaker allows for much control over how the program/game
utilizes the sound files you use. You can choose to load sounds as needed either into memory
or straight from the storage device. Pre-loading sound effects will ensure they play quickly,
while loading background music only as needed will reduce the amount of memory that's
required.
GM can play an assortment of different sound files. You can program your game to play
sounds when certain conditions are met, for example when one object hits another or a certain
score is reached. Sounds can consist of effect sounds or background music.
You're probably going to need an external sound editor, as at the time of writing of writing
there isn't a built-in one included in GM. There are plenty of free ones available, I recommend
Audacity, which is free and it's quite easy to use its basic functions.
It's good practice, as before with sprites, to name your sounds as descriptively as possible,
starting with snd_ or sound_. A good example is 'snd_score_point', some bad examples are
'beep', 'extra life' and 'hello'.
A good housekeeping practice is to reduce the file size of your sound files using an ex-
ternal program. This will reduce the overall size of your game, make it load quicker and may
reduce some problems when playing.

We'll now add a sound effect to this mini game so it makes a sound when you click on
the skull.
Firstly we’ll load a sound. You’ll need to create a new sound, you can do this by clicking
on the add sound button on the title bar, as shown in Figure 3_39.

Figure 2_39. Creating a new sound.

39
BEN TYERS
Name the sound, sound_ghost_hit and click the folder icon, as shown in figure2_40.

Figure 2_40. Creating and loading in a new sound.

Load in the sound boink3 from the resources in the folder /Download_Pack/Sounds and
Voices/Pack 1, as shown in Figure 2_41.

Figure 2_41. Loading in a sound.

When done, click the OK button.

40
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Your project tree should now look like Figure 2_42 below.

Figure 2_42. Showing updated project tree.

Now re-open object_skull by double clicking on it the directory tree and then click on the
Left Released Event, so your screen looks like that in Figure 2_43.

Figure 2_43. Object_skull with Left Released Event Selected.

41
BEN TYERS
Select the ‘Main 1’ tab and add a play sound button, as shown below in Figure 2_44.

Figure 2_44. Add a play sound action.

Set the sound to the sound you just created, sound_ghost_hit, as shown in Figure 2_45.

Figure 2_45. Setting sound to play sound_ghost_hit.

Click OK twice to close both windows.


Save your game as ‘Mini_Game_2’. A GMZ of this file is available in the resources
folder. Click the green arrow at the top to test your game. If you click the ghost it should now
play the sound.
42
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Score and Lives, Health and using a Control Object.
We’ll now add some extra features and create an aim for this game:
You win by clicking 20 skulls, then the game ends.
You have five lives.
You only have 3 seconds to click each skull or you lose a life.
You lose the game if all lives are lost.
First we’ll create a control object. A control object is an object for performing functions
like drawing the score and number of lives on the screen.
Create a new object and name it object_control, do this by clicking the create object but-
ton on the top bar, as shown in figure 2_46.

Figure 2_46. Creating an object called object_control.

43
BEN TYERS
Add a create event by clicking on ‘Add Event’ then ‘Create’, as shown in figure 2_47.

Figure 2_47. Making a Create Event.

Got to the ‘Score’ tab and then add a set lives action and set this to 5, as shown in Figure
3_48.

Figure 2_48. Setting starting lives to 5.

44
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Then set the score to 0, using the set score action button as shown in Figure 2_49.

Figure 2_49. Setting the starting score to 0.

Next we’ll draw the lives and score on the screen.


You can draw lives as a number or as images for each life. In this example we’ll draw
lives as an image. You’ll need to load in a sprite for this. Click the a ’create sprite’ button on
the top bar and load in the sprite ‘spr_lives_0.png’ from the resources folder. Name this sprite
‘sprite_lives’ then close the window. Your project tree should like that shown in Figure 2_50.

Figure 2_50. Project tree after adding sprite_lives.

45
BEN TYERS
Now in the object_control object that should still have a window open, add a draw event
by clicking the ‘Add Event’ and then the ‘Draw’ option, as shown in figure 2_51.

Figure 2_51. Creating a draw event.

Select the ‘Draw’ tab, then the ‘Draw Life Images’, set the sprite as sprite_lives and check
the ‘relative’ box (checking this box will make the sprites be drawn where you place it in the
game’s room), as shown in figure 2_52.

Figure 2_52. Setting the draw action to draw lives as an image.

46
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next set the score to be drawn on the screen. Do this by adding the ‘Draw Score’ action.
Set it to relative and add put 50 in the y box, this will draw the score value just under the
images. See figure 2_53.

Figure 2_53. Setting up the draw actions.

Next add a step event, as shown in Figure 2_54.

Figure 2_54. Creating a step event.


47
BEN TYERS
Now create an action to test the score. This is the octaganol action in the score tab. Add
this as shown in Figure 2_55.

Figure 2_55. Testing the score.

Now go to the control tag and add start and end blocks. Anything put between these
blocks will be executed if the score is equal to 20. Your screen should look Figure 2_56 after
you have added them.

Figure 2_56. Add start and end blocks to a test action.

48
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Now open the ‘Main 2’ tab and add a message as shown in Figure 2_57. If you need to
move the actions around you can click and drag them.

Figure 2_57. Adding a pop-up message.

Now in the same tab, add a restart game action. The step event actions should now look
like Figure 2_58.

Figure 2_58. Showing actions in Step Event of object_control.

Now cloce any open windows.

49
BEN TYERS
Now, open the room and select the objects tab. Place one instance of the object, ob-
ject_control, in middle of the room, just below the top. As shown in Figure 3_59. Click the
green tick to close this window.

Figure 2_59. Adding an instance of the control object to the room.

Now open the object object_skull, click on the ‘Left Released’ event. Go to the score tab,
add a set score action and set it to relative 1, as shown in figure 2_60, then click OK. This will
add 1 to the current score when it’s clicked with the left mouse button.

Figure 2_60. Setting score relative.

Now save your game as mini_game_3 (a GMZ example is available in the resources
download).
Test your game by pressing the green arrow at the top of the screen. If you click 20 skulls
you’ll get a message that you’ve won. Upon clicking OK the game will restart.
We’ll now set up so that you only have a few seconds to click each skull. If you fail to
click it in time, you’ll lose a life.
We’ll use something called alarms. You can set a starting value of an alarm, for example
100, which will then reduce by one on each step the game makes. When the alarm reaches 0
50
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
you can program GM to make something happen, in this case reduce the number of lives by
one and restart the timer.
You can find the timer actions in the ‘Main 2’ tab, as shown in Figure 2_61.

Figure 2_61. Showing location of timer actions.

51
BEN TYERS
Open the object, object_skull and a set alarm [0] to room_speed*3, as shown in Figure
2_62. This will set the timer to 3 seconds.

Figure 2_62. Setting alarm[0] to room_speed*3.

Next create an event for alarm[0], this will perform these actions if and when alarm[0]
has a value 0 (the time has run out). Do this as shown in Figure 2_63.

Figure 2_63. Creating an Alarm[0] event.

52
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Now add the ‘Set Lives’ action from the ‘Score’ tab, and set the number of lives relative
-1. This will subtract 1 from the current lives value. As shown in Figure 2_64.

Figure 2_64. Subtracting 1 from the current lives value.

Next reset the alarm to room_speed*3, as shown below in Figure 2_65. Click OK.

Figure 2_65. Restarting the room speed in the alarm[0] event.

53
BEN TYERS
In the ‘Left Released’ event of object_skull add another alarm[0] reset to room_speed*3.
This will restart the alarm after the object is successfully clicked by the player. This is shown
in Figure 2_66 below.

Figure 2_66. Resetting alarm after player clicks object.

Click OK, as needed, to close any open windows. Open the object, object_control, and
set as shown in figure 2_67 below.

Figure 2_67. Showing a message and restarting game if lives are equal to 0.

Click OK to close any open windows.

54
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Finally we’ll set a background for this mini game.
Click the ‘Add Backgound’ button as shown in Figure 2_68.

Figure 2_68. Creating a new background.

Load in the file ‘crumple’ in the resources folder: / Sprites, Backgrounds and Tile_Sets /
Backgrounds.
Set as shown below in Figure 2_69, naming it background_1.

Figure 2_69. Setting a background.

55
BEN TYERS
Open the room, room_test. Select the background tab, as shown in Figure 2_70.

Figure 2_70. Assigning a background to a room, first part.

Next scroll down using the sidebar, and set the background as background_1, as shown
in Figure 2_71.

Figure 2_71, assigning a background to a room, final stage.


Once done, click the green tick to close the window.
Save your game as mini_game_4 (a GMZ file is available in the resource’s folder for this
game).

56
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Now test your game by clicking the green triangle at the top of the screen. Check that it
works as expected.

57
BEN TYERS
Debugging a Game
As with any game, no matter how simple, there may be some bugs, errors or objects doing
unexpected things. After you create any game, you need to test fully and make any changes
as needed. In this example, sometimes the skull object may be drawn at the edge of the screen,
so it won’t be visible and the player won’t be able to click it. This can corrected by making
the following changes:
Open the sprite, sprite_skull, and set the sprite origin as the center, as shown in Figure
2_72. Click OK.

Figure 2_72. Setting the origin of a sprite to the center.

Save and retest your game.


Congratulations, you’ve just created your first game with GameMaker: Studio.

58
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Review
You should now know some of the basics that make up a game:
Sprites: What a sprite is, how to load a sprite, and how to set it to an object.

Variables: How to use basic variables, set them, test them, change a value, and draw the
score and lives.

Objects: Create an object place it in a room. Assign a sprite to an object and draw it on
the screen.
Sounds: Load and use a sound, Make it play with an object is clicked with the mouse.
Backgrounds: Set a background for a level.
Events: Use the create event, alarm event, release of a mouse button, the step event and
the draw event.
Alarms: The basics of using alarms. Creating a new alarm and performing actions when
the alarm value reaches 0.
Control Object: Creating a control object and use it to display and test variables.
Rooms: Creating a new room, setting a name, setting a background and adding objects to
the room.
General: How to save a game and how to play a game.

59
BEN TYERS

Chapter 3
Chapter

Designing Your First Game

60
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Design

After reading the first few chapters, you'll have a basic knowledge of the different ele-
ments that work together to make a game. Don't worry if you don't understand everything just
yet – this will come with time and practice, and will be introduced and explained throughout
this book. Later in the book you'll discover more ways to use these elements. At the moment
it's just important that you are aware of the basic elements that make up a game: Sprites,
objects, sounds, backgrounds, events, conditional structures and basic variables, such as score
and lives. If you're still a little unsure what the elements are, and their basic usage, please go
back and re-read chapter 1 again, and perhaps make a few notes in this book or note-book or
similar. This will be time well spent.

This chapter deals with how to design a game, and consider what elements will be used
in the game and how they will react to the player (user input) and with itself (the AI). The
importance with initial game design, similar to other industries where designing something,
is to get as many ideas and sketches down as quickly as possible. It's not an art competition,
in fact being a poor artist probably helps, crude basic sketches are just fine – so long as you
understand the idea trying to be portrayed.

In this chapter you'll be introduced to more Drag and Drop (D&D), these will be dealt
with continually throughout the rest of the book, and looked at in more detail. For the purpose
of this chapter you'll just be shown the D&D and a brief explanation of what it does. This
gradual exposure will help you think for yourself when creating your own games.

61
BEN TYERS

Figure 3-1. Quick sketch of game layout


Game Outline
So the game idea will go something like this: The player controls a bat using the left and
right arrow keys. The goal of the game is to control a ball using the bat, while trying to hit and
destroy the bricks. Along the way the player can collect bonus items. If the ball hits the bottom
of the screen, the player loses a life. The goal is to get the highest score.
Figure 3.1 shows a scan of my basic plan for a brick and ball game. This gives me an idea
of what's visible on the screen and what the basic elements are. I've numbered each element
from 1 to 11. They are:
1: The Players Bat
This is the object the player will control. The controls will be the left and right arrow
keys, which will move the bat to the left or the right.
2: The Ball
This object will bounce around the screen.
3: Brick Type 1
This is one object that the player tries to hit with the ball. It only needs to be hit once.
4: Brick Type 2
This is another object that the player tries to hit with the ball. It needs to be hit twice.
5: Bonus Brick
This object needs to be hit by the player. Hitting it will create an instance of a Bonus (no.
10)
6: Wall
This object marks the top, left and right of the playing area.
62
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
7: Bottom Wall
This object marks the bottom of the play area
8: Score
This displays the player's score
9: Lives
Displays the players lives as images
10: Bonus
The player collects this and gets extra points
11: Room
This is the play area(known as a room). It holds all the above elements (1 to 10) in it.
Interactions
Now you need to plan and work-out what the interactions and events are and what hap-
pens when these are met.
For example some interactions and what should happen:
On right arrow key press move bat to the right
When the ball hits a side or top wall, to bounce off at an angle.
If the ball hits a brick, destroy the brick and bounce off.
There are other interactions possible, they are dealt with in more details in the next chap-
ter.

63
BEN TYERS

Chapter 4

Brick and Ball Game – Part 1

64
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Sprites

Firstly we’ll create and load in sprites required for this game. Most sprites will have a
single image, though some will have more than one. These are called sub-images. This enables
you create sprites that can animate/change if something happens. The sprites below that have
more than one image will allow us to create objects that can be partially destroyed if it is hit
by the ball.
Sprites can be loaded in as images, or you can create them using the built in editor. For
the first two sprites we’ll create them using this editor.
How to create a new sprite
To create a new sprite, click the ‘create a sprite’ button on the top title bar, as shown in
figure 4_1 below.

Figure 4_1. ‘create a sprite’ button.

Name the sprite ‘spr_wall_tlr’ as shown below in figure 4_2.

Figure 4_2. Setting a sprite name.

65
BEN TYERS

Next open the sprite editor by clicking on ‘Edit Sprite’ This is shown in Figure 4_3.

Figure 4_3. Opening Image Editor.

Now Click ‘File>>New’ and set width and height as 32.

You’ll see what is shown in Figure 4_4. Double click on image_0.

Figure 4_4. Showing where to double click to open the image editor.

66
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
A pop up window will appear, as shown in figure 4_5.

Figure 4_5. Showing the Image Editor.

Use the middle mouse scroll button (or CTRL+=) to zoom in so the image looks like
Figure 4_6.

Figure 4_6. Showing image zoomed in on.

67
BEN TYERS
Select ‘Draw a Line’ by pressing ‘L’ or click where shown in figure 4_7.

Figure 4_7. Selecting ‘Draw a Line’.

68
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Select a green colour by click the green square in the colour palette on the top right, as
shown in Figure 4_8.

Figure 4_8. Setting colour to green.

Then draw some lines so the image looks like that shown in Figure 4_9.

Figure 4_9. Showing what to draw in the image editor.


69
BEN TYERS

Now press the green tick twice to close the editor.


Set the sprite origin to centre, as shown in Figure 4_10. You can then click ‘OK’.

Figure 4_10. Setting the sprite origin to center.

All sprites in this game will have the Origin set to center. It is important that this is done.
This allows the sprite to centered when it is drawn on the screen.

Create a new sprite, spr_wall_bottom, and repeat the above process, except this time use
the colour red instead of green. Again, set the sprite origin to center, as shown in Figure 4_11.

Figure 4_11, showing sprite, obj_wall_bottom.

70
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
In the resource folder / Sprites and Backgrounds For Examples / Brick and Ball/
You’ll find some more sprites for this game to load in, as shown in Figure 4_12.

Figure 4_12. Additional sprites that need to be loaded into the game.

To load in an image to use a sprite, click the ‘Create a Sprite’ button as shown previously
in Figure 4_1. Then follow the steps below.
Enter the name of the new sprite, then click ‘Load’ as shown in Figure 4_13.

Figure 4_13. Setting sprite name and then clicking load.

71
BEN TYERS
Then navigate to resource folder and load in the sprite image, as shown in Figure 4_14.

Figure 4_14. Loading in a new image to use as a sprite.

Again, set the sprite origin to center and click ‘OK’.

Figure 4_15. Remembering to set sprite origin to center.

72
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Create an object for each sprite, for example obj_ball (shown in Figure 4_20b). Repeat
this process for the sprites shown in Figure 4_20a, except the sprite spr_stone_blue which will
be done differently.

The sprite for spr_stone_blue is slightly different. It will consist of two sub-images.
One image will show the stone whole, one slightly damaged. When we add this to an object
later in the chapter we can set it so that it when it is hit once by the ball it shows some damage,
then is destroyed completely when hit again.

To create this, add a new sprite by clicking on the ‘Create a Sprite’ button as shown back
in Figure 4_1.
Name the sprite ‘spr_stone_blue’ and then click ‘Edit Sprite’. Click ‘Add From File’ or
press CTRL+A as shown in Figure 4_16.

Figure 4_16. Adding image from file.

The load in the damaged blue stone as shown in Figure 4_17.

Figure 4_17. Adding damaged blue stone.

73
BEN TYERS

Click Open. The click ‘Add From File’ again and select the whole blue stone, as shown
in Figure 4_18.

Figure 4_18. Add additional sub image.

It will now look like that shown in Figure 4_19.

Figure 4_19. Showing both subimages for the sprite ‘spr_stone_blue’.

74
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Your project tree for sprites will look the same as Figure 4_20a.

Figure 4_20a. Showing project tree for sprites.

Figure 4_20b – Showing objects named and set with sprites.

Click the green tick to apply changes.


Set the origin to center, then click OK.

Now is a good time to save your progress. Save this as ‘Brick_and_Ball_A’ , by clicking
file and then ‘Save As’.
75
BEN TYERS

76
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Chapter 5

Brick and Ball Game

Part 2

77
BEN TYERS
Creating The Game

Sounds
We’ll now load in the sound effects and music for this Brick and Ball Game.
The sound resources for this game can be found in the download resources folder /Sounds
and Voices/Brick_and_Ball Basic/.
You can add a new sound by clicking the ‘Create a Sound’ button on the top of the GM
windows, as shown in Figure 5_1.

Figure 5.1. Showning ‘Create a Sound’ button.

When the window opens, type in the name of the resource, the first one is
‘snd_bounce_1’, click the folder icon and navigate to resource’s folder and load the correct
sound. When done click OK. This procredure is shown in Figure 5_2.

Figure 5_2. How to create and load in a new sound.

78
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Repeat the above procedure to load in all sounds as shown in Figure 5_3.

Figure 5_3 Showing Sounds loaded in.

[note snd_music_1 is an MP3 file


Now save your game, and give it the name ‘Brick and Ball’.
Objects

We’ll now create the objects for this game, and add to them the sprites that were created
in the previous chapter.

First we’ll create a control object. We’ll use this set up score and lives and to draw them
on the screen.

Click the ‘Create an Object’ button on the top bar, see figure 5_4.

Figure 5_4. Create a new object.

79
BEN TYERS
Name this object obj_control, as shown below in Figure 5_5. This object does not require
a sprite.

Figure 5_5. Naming the new object to obj_control.

Update – Please see page 121 for a correction for this object

80
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next we’ll add events to this object. We’ll start with the create event. You do this by
clicking ‘Add Event’, followed by create event. The D&D or GML in the Create Event is only
execuated when this object is first created. This makes it’s ideal for setting initial variables
for game, in the case the starting score and the number of lives.This is shown in Figure 5_6.

Figure 5_6. How to create a ‘Create Event’.

Go the ‘Score’ tab on the right, set the score to 0, set the lives to 5. This is shown below
in Figure 5_7

Figure 5_7. Setting initial score and lives.


81
BEN TYERS

Then go to the ‘Main 1’ tab and click the sound icon, this shown in Figure 5_8.

Figure 5_8. Setting sound to play.

Set the sound to the following, as shown in figure 5_9. This will set the background music
to play in a loop. Setting as a loop means when the track comes to the end it will then restart
from the beginning again.

Figure 5_9. Setting music to play in the background on a loop.

82
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next go to the ‘control’ tab and add the action ‘Set Variable’. Set global.bat_speed to 4,
as shown in Figure 5_10.

Figure 5_10 Setting a variable, global.bat_speed to 4.

Once you’ve completed the above, the object obj_control should look like that shown in
Figure 5_11.

Figure 5_11. Showing the completed create event for obj_control.

83
BEN TYERS
Next we’ll create a step event. This can be done by clicking ‘Add Event’ and then Step,
then Step again. This is shown in Figure 5_12.

Figure 5_12. Creating a step event.

84
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
First go to the score tab and add the action ‘Test Lives’. This is shown in Figure 5_13
below.

Figure 5_13. Showing test lives action.

Next add a ‘Start Block’ action from the ‘Control Tab’. Your window will now look like
Figure 5-14.

Figure 5_14. Adding start block.


Next add a ‘Play Sound’ action from the ‘Main 1’ tab. Set it to play snd_game_over and
set the loop as false. You should be able to add this without a screenshot.
85
BEN TYERS
Next go to the ‘Main 2’ tab and drag across ‘ Display Message’ as shown in Figure 5_15.
Set the message to Game Over.

Figure 5_15 Adding ‘Display Message’ action.

Also from the ‘Main 2’ tab drag across the ‘Restart Game’ action.
Finally go back to the ‘Control Tab’ and add an ‘End Block’ action.
When done, the ‘Step Event’’ for obj_control will look like Figure 5_16 below.

Figure 5_16. Showing completed step event for object obj_control.

What this does: Each step of the game it will test how many lives are left. If there are no
lives (a value of 0) it will execute the actions between the start and end block. Placing the
actions between the blocks is very important, it will only execute them if lives are 0. If the
actions were not placed inside blocks then the actions would be executed every step of the
game (except the first action just after the testing of the variable).
Now Click the Green Tick / OK button to close the window.

Next is to add the draw event for the control object, obj_control.
Open the object obj_control by double clicking it on on resource tree on the left.
86
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Click ‘Add Event’ then ‘Draw’.
Add the ‘Draw Score’ Action (this has a green border), double click it to open it and set
as shown in Figure 5_17. Do not click the relative box.

Figure 5_17. Adding the Draw Score action.

Next draw the lives as image, by setting as shown in figure 5_18 below, again do not
click the relative box.

Figure 5_18. Drawing the lives as an image.

Next we’ll draw the value of the variable global.bat_speed and some text so the player
knows what the number is.

87
BEN TYERS
First the variable, go to the control tab and add the action ‘Draw Variable’ and set as
shown in figure 5_19.

Figure 5_19. Drawing the varaible global.bat_speed.

Finally for this object we’ll draw some text infront of the variable being drawn. Go to the
‘draw’ tab and add the action ‘Draw Text’. This shown in Figure 5_20.

Figure 5_20. Drawing text on the screen.

Click OK to close all open windows. The control object is now complete.
Let’s check that it works ok so far.
Click the ‘Create Room’ button on the top bar, as shown in figure 5_21. Name the room
game1.

Figure 5_21. Creating a new room.


88
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Go to the objects tab and select obj_control. Place once instance of this object by clicking
in the room. When done you’ll see a blue circle, as shown in Figure 5_22.

Figure 5_22. Adding an object to the room.

When done, click the green tick in top left.


Click the green arrow on the top bar to run your game. If all’s ok, you’ll see that shown
in figure 5_23.

Figure 5_23. Showing progress of game so far.


89
BEN TYERS
Now would be a good point to save your game.
Next we’ll create the players bat. We’ll program it to move left and right, and stop it
leaving the room.
First create a new object by clicking the ‘Create an Object’ button at the top of the GM
window, name the object obj_player_bat.
Set the sprite for this object to spr_player_bat, as shown in figure 5_24.

Figure 5_24 Naming object and assigning sprite to the object.

Next add a ‘Create Event’ and add the ‘Set Variable’ action to set global.bat_speed to 1,
as shown in figure 5_25 below.

Figure 5_25. Create event for object obj_player_bat

90
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Then click OK.


Then set another variable, global.bat_speed to 1, followed by OK.
Next add a step event.
Add the action ‘Test Varaible’ to test if x is less than 80, as shown below in Figure 5_26.

Figure 5_26. Testing if the varaible x is less than 80.

X is the left to right position on the screen.


Click OK. Add a start block, then use the ‘Set Variable’ action to set x to 80. This is
shown in Figure 5_27.

Figure 5_27. Shown actions in step event.

91
BEN TYERS
Then program the step event so it looks like that shown in figure 5_28 below. This keeps
the obj_player_bat on the screen. Checking the speed will keep the speed between 1 (mini-
mum) and 20 (maximum). Putting in place checks such as this is an important part of the game
development process and helps prevent unexpected things from happening. You should do
checks like this on any variable, global or local, that changes through the course of playing
the game. It would also be nice if current speed of the ball was displayed at the top of the
screen.

Figure 5_28. Showing all actions for step event in obj_player_bat

These actions will stop the players bat from going off the screen and keep the bat size and
speed within a certain range.
Go to the draw actions tab and drag across ‘Draw Sprite’, as shown in figure 5_29.

Figure 5_29. Selecting ‘Draw’ tab and ‘Draw Image’ action.

92
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Program this action as shown in Figure 5_30, followed by OK.

Figure 5_30. Setting action to draw the players bat sprite.

The final stage for this object is to program in the key presses that make the object move.
Click add event, Key press, then click ‘left’, as shown in Figure 5_31.

Figure 5_31. Adding ‘Left’ keypress event.

93
BEN TYERS
Go to the ‘Move’ tab and add the action move fixed. Program it as shown in Figure 5_32.

Figure 5_32. Programming a left key press event to make an object move.

Repeat the previous steps, but this time program for a right key press event and set the
movement to the right, as shown in Figure 5_33.

Figure 5_33. Programming object to move on right key press.

94
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Finally add one of this object to the room by double clicking the room on the project tree
on the left of the screen. Selecting Objects and adding a bat, as shown in Figure 5_34.

Figure 5_34. Adding players bat to the room.

Now save and then test the game. If everything has been done correctly, you should be
able to control the bat left the left and right keys without the bat going off of the screen.
Next we’ll add some borders.
Create an object, obj_wall_tlr, and set the sprite spr_wall_tlr, check the solid tick box, as
shown in Figure 5_35. When done, click ok.

Figure 5_35. Creating a new object and assigning a sprite to it.


95
BEN TYERS
Now repeat the above process and create an object, obj_wall_bottom, and assign the sprite
spr_wall_button. Be sure to check the solid check box.
Making an object solid tells GM that it’s a solid object so it can interact with other solid
objects, which in this case will be a ball.
Now add these two objects into the room, so it looks like Figure 5_36. The top and side
walls are made from the green object, obj_wall_tlr. The bottom is made from the red object,
obj_wall_bottom.

Figure 5_36. Showing room with newly created objects in it.

Next we’ll create some bonus objects. These objects will drop down when the ball hits a
bonus stone.
Create a new object, obj_bonus_1, assign the sprite spr_bonus_1.
In the create event, set it to start moving down the screen as shown in Figure 5_37.

Figure 5_37. Showing create event for obj_bonus_1.


96
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Next create a collision event for with obj_wall_bottom, so that the object destroys itself
on contact with it. Click ‘Add Event’, then click ‘Collision’ then select the object
obj_wall_bottom, as shown in Figure 5_38.

Figure 5_38. Setting collision event between two objects.

Add the action ‘Destroy Instance’ from the Main 1 tab. Leave the check box as self. Your
screen will look that in Figure 5_39 below.

Figure 5_39. Add a destroy instance action to the collision event.

Now create a new collision event, this time with obj_player_bat.

97
BEN TYERS
Add the actions to play the sound snd_bonus_collected, set the score relative to 250
(check the relative box), and destroy instance (self again). As shown in figure 5_40 below.

Figure 5_40. Adding actions for the collision event with obj_player_bat.

Next create a new object, obj_bonus_2, set the sprite to spr_bonus_2. In the create event
set it to move down with a speed of 2. Make a collision event with obj_wall_bottom. Make a
collision event with obj_player_bat, and the actions to increase the score by 500 (with relative
box checked), set the variable global.bat_speed to 2 relative. The next three screen shots show
how to do this, in Figures 5_41, 5_42 and 5_43.

Figure 5_41. Setting object to start moving using moved fixed action.

98
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Figure 5_42. Setting the ‘destroy self’ action in collision with obj_wall_bottom.

Figure 5_43. With collision obj_player_bat event. Set score relative to 500, set
global.bat_speed to relative 2 and destroy self actions.

Next create a new object, obj_bonus _3, assign the sprite spr_bonus_3.
In the create event, add the ‘move fixed’ action to make it move down at a speed of 2.
In a collision event with obj_wall_bottom, set it to destroy itself, using ‘Destroy Instance’
action.
In a collision event with obj_player_bat, set the variable global.bat_speed to -2 relative
(check the relative box). After this place a ‘instance destroy’ (self) action.
Next we’ll create the ball object. Create a new object and name it obj_ball. Add a create
event and set the ball to start moving in an up-left direction at a speed of 3, by using the moved
fixed action. Check the ‘solid’ check-box. See Figure 5_44 to see what this should look like.

Figure 5_44. Creating the ball object, obj_ball.

99
BEN TYERS
Click ok to close the windows. We’ll come back to this object later in this chapter to add
some collision events, once the other objects have been created.
Next step is to make some stones that the player must try and hit.
Create a new object obj_stone_red and assign the sprite spr_stone_red.
Make a create event for this object and use the ‘Set Variable’ action to set a variable
my_health to 1, as shown in Figure 5_45. This is a local variable (note it does not have global.
in front of this). This variable keeps track of how many hits are needed to destroy it, it will be
programmed in the collision event to reduce the value of my_health by 1 each time it is hit by
the ball.

Figure 5_45. Create event for object obj_stone_red.

Create a step event and program as Figure 5_46 below (note that the score is set relative,
so you’ll need check the relative box)
:

Figure 5_46. Step event for object obj_stone_red.

100
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next create a collision with obj_ball and add set as shown below in Figure 5_47. Set it to
reduce the value of my_health by 1, as shown below, remembering to check the relative box.

Figure 5_47. Collison with obj_ball, and showing solid checkbox ticked. Note that Set variable
is set to -1 with relative box checked.

Click OK to close the window.


Next create new object obj_stone_pink and set the sprite spr_stone_pink. Program as
shown in Figures 5_48 to 5_50 below:

Figure 5_48. Create event for obj_stone_pink.

101
BEN TYERS

Figure 5_49. Step event for object obj_stone_pink.

Figure 5_50 Collision event with obj_ball for object obj_stone_pink. Remember to set Set
Variable Relative by -1 by checking the relative box.

Next create a new object, obj_stone_yellow and set the sprite spr_stone_yellow. Program
it the same as obj_stone_pink above.
Next create a new object, obj_stone_blue and set the sprite as spr_stone_blue.
Program it as shown below in Figures 5_51 to 5_54.

Figure 5_51. Create event for object obj_stone_blue.

102
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 5_52. Step event for object obj_stone_blue.

Figure 5_53. Collision event with obj_ball for object obj_stone_blue. Set as relative using the
relative check box.

Figure 5_54. Draw event for object obj_stone_blue. This draw event sets it to draw the subi-
mage sprite, either 1 or 0, depending if it’s been hit or not.

Next we’ll create the bonus stones.


103
BEN TYERS
Create a new object, obj_bonus_stone_1, set the sprite to spr_bonus_stone_1, and pro-
gram as shown below in Figures 5_55 to 5_57.

Figure 5_55. Create event for object obj_bonus_stone_1.

Figure 5_56. Step event for object obj_bonus_stone_1.

Figure 5_57. Collision event with obj_ball for obj_bonus_stone_1. Set variable as -1 with rela-
tive box checked.

Next create a new object obj_bonus_stone_2, set the sprite to spr_bonus_stone_2 and
program as shown in Figure 5_58 to 5_60.

104
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 5_58. Create event for object obj_bonus_stone_2.

Figure 5_59. Step event for obj_bonus_stone_2.

Figure 5_60. Collision event with obj_ball for object obj_bonus_stone_2.

Next create a new object, obj_bonus_stone_3, set the sprite, spr_bonus_stone_3, and pro-
gram as shown in Figures 5_61 to 5_63.

105
BEN TYERS
Figure 5_61. Create event for obj_bonus_stone_3.

Figure 5_62. Step event for object obj_bonus_stone_3.

Figure 5_63 Collision event with obj_ball for obj_bonus_stone_3.

106
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Now re-open obj_ball by double clicking it on the resource tree, shown in figure 5_64a

Figure 5_64a. Double click obj_ball.

Create a collision event with obj_wall_tlr and set as shown in Figure 5_64b below:

Figure 5_64b. Setting collision event between ball and border.

107
BEN TYERS

Next create a collision event between the ball and the floor, as shown in Figure 5_64c

Figure 5_64c. Collision event between ball and floor.

Create a collision event obj_bonus_stone_1, as shown in Figure 5_65.

Figure 5_65. Adding collision event.

Add the action ‘bounce’, from the move tab, and set to not precisely, as shown in figure
5_66.

108
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 5_66. Setting object to bounce.

Next go to the ‘Control’ tab and add the action ‘Execute Code’, as shown in Figure 5_67.

Figure 5_67. Adding an execute code action.

Next double click on this this action, as shown in figure 6_68. Type in the GML code:
move_bounce_all(true);

Then click the green tick.

109
BEN TYERS

Figure 5_68. Adding some GML code.

This code will help the ball bounce without getting stuck next to objects. It’s not a perfect
soloution, but will suffice for now.
Now repeat the actions from Figures 5_64 to 5_67 for all the other stone objects, when
done, the object obj_ball should look like that as shown below in 5_69.

Figure 5_69. Showing all collision events added to object obj_ball.

110
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Finally open the room and add the objects so it looks like that as shown in Figure 5_70,
rename the room room_level_1.

Figure 5_70. Showing room with objects added.

Now save your game, then test it by clicking the green triangle on the top bar.
Check the game plays as expected, if not go back and check you haven’t made any mis-
takes.
The GMZ file for this game is in the download folder /GMZ Files/Brick and Ball and is
file book_1_brick_and_ball_A.

111
BEN TYERS

Chapter 6

Brick and Ball Game – Part 3

112
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Refining The Game

Once you've got your basic game functioning, you can start refining the look and play of
it.

You can do things such as:

• Refine the game by replacing place holder sprites, adding more sounds
• Set a goal to the game
• Add more objects
• Add music
• Change the appearance of text
• Create Multiple Levels
You'll learn how to do all of these in this chapter.

Before you proceed any further, I suggest you go back and review chapters 1 through 5.
This chapter will assume that you've understood everything so far, and will contain less ex-
planations and screen shots.

Refining the Brick and Ball Game

We'll go back and edit some of the settings and make it more dynamic to allow the future
integration of other features, such as a bonus object that makes the bat move faster or change
the bat's size.
Upon playing your game you'll see that it's quite difficult to keep the players bat up with
the ball.
Open object obj_control and delete the set global.bat_speed 'set variable' action. Click
OK to close the open window.
Open object obj_player_bat, add a 'set variable' action and set the variable
global.bat_speed to 10, as shown in Figure 6_1. This will make the starting speed of the bat
much faster. Now open the step event in object obj_player_bat and change the test
global.bat_speed from 1 to 3. This will keep the speed of the bat between 3 and 10.

113
BEN TYERS

Figure 6_1. Adding 'Set variable' to obj_player_bat to create event.

To make testing the game easier we'll program in some key press events that can be used
to make changes. In this case we'll program it so key 'a' slows down the bat and key 's' speeds
it up. We'll also add keypress of 'r' to restart the ball. For keypress events, click 'Add Event'
then 'Key Press' then 'Letters' as shown in Figure 6_2. This is shown in Figures 6_3, 6_4 and
6_5 below.

Figure 6_2. Adding 'Key Press' event.


114
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 6_3. Setting key 'A' to reduce speed.

Figure 6_4. Setting key 'S’ to increase speed.

115
BEN TYERS

Figure 6_5. Setting key 'R' to restart ball. Note: This is set to apply to object obj_ball.

Now save and test your game. Check that minimum and maxium speeds of the players
are kept in range, by pressing 'a' and 's'. Check you can restart the ball by using 'r'.

116
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Set a Goal to the Game

The aim of this game is to get the biggest score you can before you lose all your lives.
You could of course have other goals such as:
• Collecting all the bonuses
• Getting to the next level
• Completing as quickly as possible
• Destroy all the bricks on a level
For the purpose of this introduction book, we'll set it so you have to destroy all bricks to
get to the next level. We'll need some method to keep track of how many stones are left on
each level. A good way to do this is to create a variable in the create event of each stone, as
shown in Figure 6_6 below, making sure you check the relative box is ticked:

Figure 6_6. Adding relative variable to keep track of number of stones.

Repeat above process with all of the other stone objects, including the bonus stones.
Now we need to reduce the value of global.stones_left each time a stone is destoyed.

117
BEN TYERS
Open up a stone and add a 'destroy event', by clicking 'Add Event' then 'Destroy'. Add the
action as shown below in Figure 6_7.

Figure 6_7. Reducing the value of global.stones_left when object is destroyed.

Repeat the above process with all the other stone objects, including the bonus stones.
Now open the object obj_control, and program the step event so it looks like that shown
in Figure 6_8. The action 'Display Message' can be set to "You Win".

Figure 6_8. Showing updated actions for step event in object obj_control.

118
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next we'll create a new font, so the text displayed on the game looks different.
First click the 'Add Font' button on the top bar, as shown in Figure 6_9.

Figure 6_9. Adding a new font.

Choose a font and font size, as shown in Figure 6_10.

Figure 6_10. Creating a new font.

Then click ok.


Next open the object obj_control, go to the draw event and then add the set font action to
the top the actions, as shown in Figure 6_11.

Figure 6_11. Add 'Set Font' action to the draw event for object obj_control.

Now save and test your game, you will now see the text drawn in the new font. Destroy
all of the bricks and you should get the message 'You Win'.

119
BEN TYERS

Next we'll create a few more levels. On the project tree, right click on room_level_1 and
select 'Duplicate', as shown in Figure 6_12.

Figure 6_12. Right click on room_level and select 'Duplicate'.

Repeat this process twice and name the new rooms, room_level_2 and room_level_3, as
shown in Figure 6_13.

Figure 6_13. Showing extra rooms.

Now open the room room_level_2. Right click on each of the stones and select delete, or
hold Left Control and the right mouse button whilst moving the cursor over the stones.
Now add stones to make a new level, by selecting the object tab and selecting the stones,
then clicking in the room to position each one, as shown in Figure 6_14.

120
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Figure 6_14. Adding stones to the level.

When you've finished adding stones, you'll have new level, for example as shown below
in Figure 6_15.

Figure 6_15. An example of an extra level.

Repeat this process for room_level_3.


Now save and test your game.

A GMZ file for this game is available in the download, at Download Pack / GMZ Files /
Brick and Ball / book_1_brick_and_ball_B

Debugging – Error Present


If using version B of the game you will get an error, open up and edit object obj_control
and update as shown in figure 6_16:

Figure 6_16. Adding set variable global.stones_left to 0 on game start.

121
BEN TYERS

122
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Chapter 7

Spot The Difference Game

123
BEN TYERS

In this chapter we'll create a very simple Spot the Difference type game.
This game will use background image. A background is applied to a room, and is gener-
ally a static image that is shown behind any objects. (As you become more advanced you'll
learn how to make backgrounds move, or use multiple backgrounds to make cool graphical
effects).
First you need to load in a background. You can create a new background by clicking the
'Create a Background' button the top bar, as shown in Figure 7_1.

Figure 7_1. Button for creating a new background.

Name the new background bg_level_example, uncheck the 'Tile:Horizontal' and


'Tile:Verticle' check boxes. The click 'Load Background'. These steps are shown in Figure
7_2.

Figure 7_2. Naming and setting up a new background.


124
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
After clicking 'Load', navigate to the folder/ Download Pack / Sprites and Background
For Examples / Spot The Difference Basic /. Then load in the file 'bg_level_example'. This
shown in Figure 7_3.

Figure 7_3. Last steps of loading in a new background.

Now we'll create a new room and assign this background to it.
Click the 'Create a Room' button on the top bar. This is shown in Figure 7_4.

Figure 7_4. Creating a new room button.

125
BEN TYERS
Go to the settings tab, name the room room_level_example and set the width to 800 and
the height to 400. This is shown in Figure 7_5.

Figure 7_5. Changing Settings for the game.

126
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Now go to the tab 'backgrounds' , make sure 'Background 0' is highlighted, check the
'visible when room starts' checkbox, click where it says <no background' and select
bg_level_example. These steps are shown in Figure 7_6.

Figure 7_6. Adding and setting a backgroung to a room.

When done your screen will look like that in Figure 7_7.

Figure 7_7. What is shown after setting a background to the room.


127
BEN TYERS
Now click the green tick at the top of the window to apply these changes and close the
window.
Now create a new room, room_you_win, set it to a width of 800 and a height of 400. This
room does not need a background. Close by clicking the green tick.
Next create another new room, room_you_lose, again set to a width of 800 and a height
of 400. Then close the window.

This game uses only 4 sprites, load in from the resource folder so your tree looks like that
shown in Figure 7_8.

Figure 7_8. Showing sprites loaded in.

Next step is make some objects.


First we'll create an object called obj_spot_found. Click the create object button on the
top bar. Name the object 'obj_spot_found'. Set the sprite to 'spr_spot_found'. Add a draw event
and add the action 'draw self', as shown in Figure 7_9.

Figure 7_9. obj_spot_found with draw event and action 'draw self'.

Next create a new object, obj_spot, and assign the sprite spr_spot. Create a mouse left
button released event. Add the action 'execute code' from control tab, as shown in Figure 7_10.

128
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 7_10. Showing 'execute code' action.

After adding this action, open it up by double clicking on it in the actions window.
Then enter code shown below.
///difference found
global.tofind-=1;
instance_create(x,y,obj_spot_found);
instance_destroy();

This will look like that shown in Figure 7_11.

129
BEN TYERS
Figure 7_11. What code looks like on the screen.

Click the green tick at the top left of the window to apply.
Explanation of the code:
///difference found - This is comment. A comment on one line can start with // ///.
Using /// allows you set a name for any code that is shown in the actions window (see below
in Figure 7_12.)

global.tofind-=1; - This reduces the variable global.tofind by 1. This is the same as


using '-1' with the relative button checked for the action 'Set Variable'.
instance_create(x,y,obj_spot_found); - This creates an instance of the
obj_spot_found at the same x and y location as the current object. This is the same as using
the action 'Create Instance'.
instance_destroy(); - This destroys itself. Same as using the action 'Destroy In-
stance' with the self checkbox selected.

Figure 7_12. Using /// in code to give code a name.

Finally make sure the visible check box is unchecked, as shown in figure 7_13. This
means that when the game is run the objects will be present on the screen, but no sprite will
be drawn. This object will be placed where the player needs to click when they have found a
difference.

130
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 7_13. Ensure the checkbox Visible is unchecked.

Next create a new object, obj_you_win, set the sprite as spr_you_win and program as
below, using the event 'mouse left released' and the action 'Restart Game' from the 'main 2'
tab. This is shown below:

Figure 7_14. Setting sprite and programming left mouse released event.

Close the window by clicking OK.


Create a new object, obj_you_lose. Program as shown in figure 7_15 below.

Figure 7_15. How to set the object obj_you_lose.

Next create a new font by clicking the 'Add Font' button on the top bar and then set as
shown below in Figure 7_16.

131
BEN TYERS

Figure 7_16. Setting up a new font, font_gui_1.

Click OK to close the window.


Now we'll create and program a control object. This will be used to keep track of how
many differences the player has found, how many attempts have been made, and draw both
of these on the screen.
Create an object, obj_control_10_diff.
Add a 'create event', add an 'execute code' action and enter the code as shown below.
///Declare Variables
global.tofind=10;
global.attempts=0;
global.attempts_max=12;

Explanation of above code:


/// Declare Variables- as stated before this is used to make a comment
global.tofind=10;
global.attempts=0;
global.attempts_max=12; - These set global variables needed to
start the game.

When done, this will look like Figure 7_17

132
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Figure 7_17. Showing GML code for create event of object obj_control_10_diff

Next create a step event and add the following code as shown below.
///Check If Won or Lost

if global.tofind==0
{
room_goto(room_you_win);
}

if global.attempts==global.attempts_max
{
room_goto(room_you_lose);
}

Code Explanation:

if global.tofind==0 - Checks how many differences are left to be found, if it's 0


then all 10 differences have been found. Same as the action Test Variable
{ - Same as action 'start block' - can also be written as begin
} - Same as action 'end block' - can also be written as end
room_goto(room_you_win); - Goes this room if above conditional is true (correct).
Same as action 'different room'

When done, it will look like that shown in Figure 7_18.

Figure 7_18. Showing GML for step event of obj_control_10_diff

Next create a global left mouse button released event. Note that this is different from the
previously used mouse left button released event. A global mouse button event can be any-
where in the game's window, not just on the sprite for an object. This can be added as shown
in Figure 7_19 below.

133
BEN TYERS

Figure 7_19. Creating a global mouse left released event.

Add a execute code action and add the code shown next.

///Attempt Made
global.attempts+=1;

Code explanation - This will add 1 to the variable global.attempts. This is the same as the
action 'set variable' 1 with relative box checked.
When done it will look like Figure 7_20 below.

Figure 7_20. GML code for global left released mouse button code action.

Finally create a draw event, and add the code as shown below.
When done, this will look like:

134
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
///Draw GUI
draw_set_font(font_gui_1);
draw_set_color(c_red);
if global.tofind>0
draw_text(10,320,"To Find: "+string(global.tofind));
if global.attempts>0
draw_text(10,340,"Attempts: "+string(global.attempts));
draw_text(10,360,"Max Attempts: "+string(global.attempts_max));

Explanation of code:
draw_set_font(font_gui_1); - This sets the font for drawing text/variables.
draw_set_color(c_red); - Sets the drawing colour as red.
if global.tofind>0 - checks to see if there are more than 0 differences to find based
on the value of global.tofind
draw_text(10,320,"To Find: "+string(global.tofind)); - this draws text
in the game window at position 10,320 (10 pixels across from the left, 320 pixels down from
the top). "To Find:" draws the text “To Find” and string(global.tofind); converts
a real number to a string so it can be added to and drawn as text.
if global.attempts>0 draw_text(10,340,"Attempts:
"+string(global.attempts)); - if more than one attempt left it will draw the text "At-
tempts:" followed by global.attempts which is converted to a string.
draw_text(10,360,"Max Attempts: "+string(global.attempts_max));
Displays maximum attempts allowed.

135
BEN TYERS
This will look like Figure 7_21.

Figure 7_21. Shown Draw event GML code for the object obj_control_10_diff

Now apply changes by clicking the green tick and click OK to close any open windows.
Next open the room room_you_win and place one instance of the object obj_you_win in
the center. Close the window. As shown in Figure 7_22.

Figure 7_22. Showing the room room_you_win with object obj_you_win.

Clcik the green tick to close this room. Next open the room room_you_lose and place one
instance of the object obj_you_lose in the center. Close the window.

136
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Finally open the room room_level_example. Place one instance of obj_control_10_diff
in white area at the bottom. Then place one instance of the object obj_spot in the places where
the differences are. When you're done they'll be ten instances of obj_spot.
This complete room is shown in Figure 7_23.

Figure 7_23. Showing room room_level_example with control object obj_control_10_diff and
ten instances of obj_spot.

Now save and test your game.


Figure 24 shows the completed game in action.

Figure 7_24. Showing completed game in action.

137
BEN TYERS

The GMZ for this project, spot_difference_example, is available in download resources


at / GMZ Files / Spot The Difference / spot_difference_example.gmz

138
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Chapter 8

Spot The Difference Game

Refining The Game

139
BEN TYERS
In this chapter we'll add some extra features, such as multiple levels, a level select screen,
a splash screen, and some basic adverts.

140
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Splash Screen
First the splash screen. A splash screen can be used to show your game logo, an advert,
or any other info you'd like the player to see before starting your game. With a graphics editor
of your choice, create a simple image 800x400 pixels. (or load the splash_example file from
the resources download).
Create a new background by clicking the background button on the top bar. Load in the
image you created, name it background_splash_1, you can uncheck both the tile settings in
the Texture box.
Create a new object, obj_splash_1. Make a create event, add a code action, and enter the
GML code to set an alarm 0 for 90 steps. As shown in Figure 8_1.

Figure 8_1. Setting an alarm using GML.

Next add an alarm[0] event, as shown below in Figure 8_2.

Figure 8_2. Setting up an alarm 0 event.

Use the code action and add the code: room_goto_next();

141
BEN TYERS
Now create a new room, in the settings tab name the room room_splash_1 (see Figure
8_3) and change the width to 800 and the height to 400. In the backgrounds tab, set the back-
ground to background_splash_1, you can uncheck the tile checkboxes, (see Figure 8_4). Then
go to the objects tab and add one instance of the object obj_splash_1 (see Figure 8_5).

Figure 8_3. Naming room and changing width and height.

142
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 8_4. Setting background

143
BEN TYERS

Figure 8_5. Adding an object to the room.

Your resource tree for the rooms will now look like that shown in Figure 8_6

Figure 8_6. Showing room resources.

You'll need to change the order of these rooms so that room_splash_1 is at the top. Click
on it with your left mouse button and drag it up to where it the green folder icon and Rooms
text is. It should now look like Figure 8_7.

Figure 8_7. Showing room order after change.

You can now save and then test your game. The splash screen should show and then take
you to next room, room_level_example.

144
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Adverts
Next we'll create a very basic advert system which you can display adverts or messages.
Something like this is great if you have a trial version of your game and want the player to
visit a webspage to buy/upgrade/downlad the full version.
This example will use 3 different adverts, but you could easily add more or less.
Using your prefered graphics editor create 3 advert images of 200x50 pixels, or use the
sample resources).
Add a new sprite, name it spr_adverts, and add all three images as sub-images, and set
the origin to the centre, see Figure 8_8.

Figure 8_8. Showing sprites added and origin set as center.

Now create an object obj_advert and set spr_advert to it.


Make a create event and put in the following code:
current_ad=0;
alarm[0]=90;

Make an alarm 0 event and put in the following code:


alarm[0]=90;
current_ad+=1;
if current_ad==3 current_ad=0;

145
BEN TYERS
Code explanation:
alarm[0]=90; - resets the alarm to 90
current_ad+=1; increases the variable current_ad by 1
if current_ad==3 current_ad=0; Checks if current_ad equals 3, if so reset to 0;
Next add a mouse left button released event and add the following code:
if current_ad==0 url_open( 'http://wwww.google.com' );
if current_ad==1 url_open( 'http://wwww.yoyogames.com' );
if current_ad==2 url_open( 'http://wwww.gamemakerbook.com' );

Above code will take you a different website, depending on the value of current_ad.
Now make a draw event and enter the following code:
draw_sprite(spr_advert,current_ad,x,y);

This will draw a subimage based on the of current_ad.


Open room_level_example, and place one instance of this object, obj_advert at the bot-
tom of the screen, as shown in Figure 8_9.

Figure 8_9. Showing room with obj_advert added.

Now save and test your game.

Next we'll create a button so the player can exit the game and return to the menu.
Create a 200x50 pixel button with the word 'QUIT' on it, or load the example from the
resources, name this sprite spr_quit, and set the origin to the center.
Create an object, obj_quit, assign the sprite spr_quit. Make a mouse left button released
event and enter the following code:
room_goto(room_menu);

This will take the player to the room room_menu, which we'll create shortly. Place one
instance of this object in the bottom right of the room room_level_example.
Now create a new sprite, 200x50 pixels, with the word 'EXIT' on it, with origin center.
Create an object obj_exit, and in a mouse left button released event enter the following code:

146
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
game_end();

This will quit the game and return to the Operating System that was running the game,
ie. Back to windows or android screen for example. Place one instance of this on bottom right
of room_menu
Now we'll create the main level select room.
Create a new room, room_menu. Set the width to 800 and height to 400.
Click the green tick to close the window.
On the resource tree drag this room up so it's between room_splash_1 and room_level_ex-
ample, so it looks like figure 9_10.

Figure 9_10. Showing room_menu moved to second from top.

Rename room_level_example to room_level_1


Open object obj_splash_1 and add the following code under the current line:
global.level=1;

Then close the object.


Create a new sprite spr_levels and load in the sprites spr_level_0 and spr_level_1 so that
it looks like that shown in Figure 9_11.

Figure 9_11. Showing subimages for sprite spr_levels.

147
BEN TYERS
Close the window.
Create a new object, obj_levels_1.
Program as shown below:
Create event code:
//set variables
my_id=1;
count=1;
image_speed=0;

Step Event:
///check if allowed
if global.level <= my_id-1
count=1
else
count=0

Mouse Left Button Released Event:


///go to level(room)
if count=0
room_goto(room_level_1);

Draw Event:
draw_sprite(spr_levels,count,x,y);

draw_text(x,y,string(my_id));

Explanation of above code:

Create Event

Sets variables needed for the object. My_id relates to which level can be unlocked, count
determines if object is locked 1 or unlocked 0.

Step Event

Checks current value of global.level against my_id, sets count accordingly.

Mouse Event

Upon mouse click goes to room if count is 0.

Draw Event

Draws my_id and locked/unlocked depending on value of count.

In the tree on the left, right click on obj_level_1 and select duplicate, do this four times.
Name the new objects: obj_level_2, obj_level_3, obj_level_4 and obj_level_5.
148
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Open object obj_level_2. Change the code in the create event, my_id=1; change to
my_id=2;
In the left released event, change the code room_goto(room_level_1); to
room_goto(room_level_2);
Do this with the remaining 3 objects, change to 3, 4 and 5 respectively.
Now open obj_control_10_diff.
Remove the current code in the step event and replace with the following:
///Check If Won or Lost

if global.tofind==0
{
global.level+=1;
room_goto(room_menu);
}

if global.attempts==global.attempts_max
{
room_goto(room_you_lose);
}

Close any open windows.

Create a new object, obj_menu_control.


Make a step event, and enter the following code:
if global.level==6 room_goto(room_you_win);

Close the window by clicking the green tick.


Now make a new event for the key release of letter 'L', this will be used for testing, allows
you to unlock levels without having to play them.
Enter the following code:
global.level+=1;

Close the window.


Open room room_menu
Place one instance of obj_menu_control in the top left.
Place one instance of each of the obj_levels objects, from 1 on the left to 5 on the right.
It should look like Figure 8_12.

149
BEN TYERS

Figure 8_12. Showing control object and 5 level objects in room room_menu.

In the resource tree go to the Backgrounds folder, rename bg_level_example to


bg_level_1.
Create 4 new backgrounds and name them bg_level_2, bg_level_3, bg_level_4,
bg_level_5. For each of them load in a different background image from the resources folder.
Now go to the Rooms folder in resources tree. Duplicate room_level_1 four times and
rename as: room_level_2, room_level_3, room_level_4, room_level_5. For each room go to
the background tab and set the correct background image that you create previously. For ex-
ample as shown in Figure 8_13 and Figure 8_14.

Figure 8_13. Renaming Duplicate room.


150
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 9_14. Setting background bg_level_2 for room_level_2.

Now open up each room for levels 2 through 5. Go to the object tab and then place an
instance of object obj_spot where each difference is. You can do this two ways: Firstly delete
all instances of obj_spot currently present by right clicking and selecting delete and then create
a new instance where each difference is, or secondly drag the existing instances of object
obj_spot by left clicking and dragging.
When done save your game and test it. Remember you can press 'L' to increase the level,
upon doing so each level should unlock in turn and lastly you'll be taken to the you win room,
room_you_win.
A GMZ file for this project is available in Projects Resources Folder - Spot_the_differ-
ence_pro .

151
BEN TYERS

Chapter 9

Hangman Game

152
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

In this chapter you'll learn about string variables and how to do various things with them.
You'll also learn of to use text files and load data from them, and creating graphic effects for
button. There will a lot of new GML, which willl be introduced and explained throughout this
chapter. We'll also introduce a script for processing and returning string variables.
First create a new sprite, spr_button and load in the following sprites from the resources
folder.

153
BEN TYERS
Sprites
This game uses 4 sprites, each of which has sub images.
First create a new sprite, spr_button and load in the following sprites from the resources
folder, as shown in Figure 9_1.

Figure 9_1. Images spr_button.

After adding, it will look like Figure 9_2.

Figure 9_2. Showing images added to sprite.

Next create a new sprite, spr_newWord, and set as shown below in Figure 9_3.

Figure 9_3. Showing images for spr_newWord.

154
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Next create a sprite, spr_exit, and set as below in Figure 9_4.

Figure 9_4. Showing images for spr_exit.

Finally create another sprite,


spr_hangman and load in the 12 images, in order, as shown in Figure 9_5.

Figure 9_5. The 12 images for spr_hangman.

155
BEN TYERS
Included File
This game uses an external file. In this case it's a text file with words that will be used for
the game.
Using a document editor, such as note pad. Enter the following words, which must all be
in capitals:
HANGMAN
HELLO
GAME
PROGRAM
JAVA
BOOK
CREATIVE
And save this document as dictionary.txt Note: This must be a .txt file. If you’re using a
wordprocessor such as Microsoft Word or Open Office make sure you save it in the txt format.
Now add this to your game. In the directory tree, right click on 'Included Files' (Figure
9_6) and left click on 'Create Included File' (Figure 9_7).

Figure 9_6. Right click on 'Included Files.

Figure 9_7. Left click on Create Included File.

Then navigate to the location where you saved your file and load it in, which is shown in
Figure 9_8.

156
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 9_8. Loading in the included file dictionary.txt

157
BEN TYERS
Game Fonts
Now add two fonts, as shown in Figure 9_9. These fonts should already present on your
computer, if they're not you can substitute for a similar font.

Figure 9_9. Creating two fonts.

158
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Script
Next we'll create a script. You can create a new script by right clicking on the 'Script' in
the resource tree, as shown in figure 9_10 , and then selecting 'Create Script'.

Figure 9_10. Right click here to create a new script.


Enter the code, as shown in Figure 9_11 below. Name the script newWord. The code for
this is shown in Code 9_1.

Figure 9_11. Showing script named 'newWord' with code present.

159
BEN TYERS
Enter the following code:

var file;
if(file_exists(working_directory + "dictionary.txt")){
//open the dictionary file
file = file_text_open_read(working_directory +
"dictionary.txt");
if(file == -1){
//if loading the file failed return -1
return -1; //will end the script
}
var wordList, wordNumber = 0;
//make a list containing all words of the dictionary
while(!file_text_eof(file)){
wordList[wordNumber] = file_text_read_string(file);
file_text_readln(file);
wordNumber++;
}
file_text_close(file);
return wordList[irandom(wordNumber-1)]; //return a random word
}

Code explanation:
var file; This declares a temporary variable called file. Declaring a temporary varia-
ble means that once the script exits or returns the variable is removed from the computers
memory. Using temporary variables is good practice and should be followed when ever pos-
sible.
if(file_exists(working_directory + "dictionary.txt")) This checks if
the file dictionary.txt is present in the working directory. It's important to check a file exists
before trying to do things with it such as opening it (below), as this will help prevent some
errors. The working_directory is the path where included files are located on a device. Loca-
tions will vary depending if your testing your game, running from windows, or on another
device such as an android device.
{ This is the start block. Code within { and } will be executed if the above condition is
true (the file exists).
//open the dictionary file Just a comment. Putting comments in your scripts
and code is useful to remind yourself what something does, so when you return to update or
check code things are easier for you.
file = file_text_open_read(working_directory +
"dictionary.txt"); this opens the file, which we've already checks exists and assigns it
to file.
if(file == -1){
//if loading the file failed return -1
return -1; //will end the script

160
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
} This section checks if there is any error, if there is it
will return a value of -1. (return is explainded in more detail in
the paragraph below this code explantion.)

var wordList, wordNumber = 0; Create two local temporary variables, wordList


and wordNumber and sets the value of each to 0.
//make a list containing all words of the dictionary Comment

while(!file_text_eof(file)) ! means not. While will do something between {


and } so long is it is true. In this case the code below between { and } will be executed con-
tinuously until the end of the file is reached (ie there are no more words to read.)
{ start block
wordList[wordNumber] = file_text_read_string(file); This adds a
word to an array called wordList (arrays are explained in more detail below).
File_text_read_string reads the word from the open file.
file_text_readln(file); This code moves to the next line of the open file.
wordNumber++; Increments the variable wordNumber by 1. Same result as using
wordNumber +=1
} end block
file_text_close(file); Closes the open file 'file'. When opening and reading files
it is very important to close it when you've done using it. Failure to close it will result in
memory leaks and other issues.
return wordList[irandom(wordNumber-1)]; //return a random
word Chooses at random one of the words from the array. The -1 is because an array starts at
0, while the variable wordNumber starts at 1
} End of block
Return
One way to call a script is: word = newWord(); which will set the variable word with the
string from the script newWord.

161
BEN TYERS
Arrays
Arrays are a useful way to store data. Arrays can store variables and strings, and other
information.
An example to create an array in GML is:
example[0]="cheese";
example[1]="bacon";
example[2]="pizza";
example[3]="tomato";
example[4]="cake";

So food=example[2] would set the variable food as "pizza".


You'll learn more about arrays when you make some more games later in the book.
irandom
irandom creates a random number between 1 and the number provided.
For example:
cost=irandom[10];
would set the varaible cost a value between 1 and 10

162
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Objects
Now we'll create objects for this game.

Create an object obj_button and assign the sprite spr_button.


Put the following code into a create event:
activated = true;
letter = "A";
image_speed = 0;
image_index = activated;

Code explanation:
activated = true; Creates a variable with the value true. This allows easy testing
using conditionals to find out if something is true or false. This is known as Boolean, which
can be either true or false
letter = "A"; Sets the variable letter to the character 'A'
image_speed = 0; Sets how quickly sub-images are shown in animation. Setting as 0 stops
any animation and will only draw the sub-image stated in the draw event.
image_index = activated; sets the image_index to true, which is equivalent to 1.

Create a step event and enter the following code:

if(activated){
//if the mouse hovers above the button
if(mouse_x>=x && mouse_x<x+sprite_width && mouse_y>=y &&
mouse_y<y+sprite_height){
//if the mouse left button is down
if(mouse_check_button(mb_left)){
image_index = 3;
}else{
image_index = 2;
}
//if the button is released
if(mouse_check_button_released(mb_left)){
activated = false;//deactivate button
//check if the letter is in the word
var newReveal = "", found = 0;
for(i = 1; i<=string_length(word); i++){
/*for each letter in the word
check if it is equal to the chosen letter*/
if(string_char_at(word, i) == letter){
found++;
newReveal += letter;
}else{
163
BEN TYERS
newReveal += string_char_at(revealedWord, i);
}
}
revealedWord = newReveal; //update the displayed word
//if the letter is not found in the word, update the
hangman
if(found == 0){
with(obj_hangman){
image_index++;
}
}
}
}else{
image_index = 1; //change image to activated button
}
}else{
image_index = 0; //change image to deactivated button
}

Code explanation:
if(activated) This checks if the variable activated is true. If it is then the code be-
tween the first and last { and } is excecuted. If the value is false it won't execute any code.
This basically means that if you've already clicked the button, you can't click it again.
{
//if the mouse hovers above the button
if(mouse_x>=x && mouse_x<x+sprite_width && mouse_y>=y &&
mouse_y<y+sprite_height){
//if the mouse left button is down
if(mouse_check_button(mb_left)){
image_index = 3;
}else{
image_index = 2;
} This code will change the sub image of the sprite when
the mouse cursor hovers over the button.
//if the button is released
if(mouse_check_button_released(mb_left)) checks for release
of mouse button
{
activated = false;//deactivate button Tells it you've
clicked the mouse (released left button) and sets activated to
false.
//check if the letter is in the word
var newReveal = "", found = 0;
for(i = 1; i<=string_length(word); i++){
/*for each letter in the word

164
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
check if it is equal to the chosen letter*/
if(string_char_at(word, i) == letter){
found++;
newReveal += letter;
}else{
newReveal += string_char_at(revealedWord, i);
}

} Checks if selected letter (different letter on each button) is present in the word and
replaces any _ with the selected letter

revealedWord = newReveal; //update the displayed word Updates


word to show added letter(s)
//if the letter is not found in the word, update the
hangman
if(found == 0){
with(obj_hangman){
image_index++;

} Changes the sub image of the hangman image if your letter was not present.

}
}
}else{
image_index = 1; //change image to activated button

Changes image back to starting position.

}
}else{
image_index = 0; //change image to deactivated button

Changes image so can see it's already been pressed.

Next create a draw event and add the following code:


draw_self();
draw_set_font(fnt_button);
draw_set_halign(fa_center);
draw_text(x+16, y+4, letter);
draw_set_halign(fa_left);
Code explanation

draw_self(); draws the current subimage with all the default object
properties
draw_set_font(fnt_button); sets the font to draw text in
draw_set_halign(fa_center); centers the text at x position
draw_text(x+16, y+4, letter);
165
BEN TYERS
Draws the variable letter. x+16 draws the text 16 pixels to the right, y+4 draws the text 4
pixels down. This change in the x and y position will center the text over the sub-images.

draw_set_halign(fa_left); Sets the allign back to left


Close any windows to apply changes.

Now create a new object obj_hangman and apply the sprite spr_hangman.
In a create event enter the following code:
randomize();

globalvar word, revealedWord;


word = newWord();

//setting the displayed word


revealedWord = "";
for(i = 0; i<string_length(word); i++){
revealedWord += "_";
}

image_index = 0;
image_speed = 0;

//creating all the buttons


//top row
var alphabet = "QWERTYUIOP";
for(i = 0; i<10; i++){
var bt = instance_create(64+i*32+(8*i), 64, obj_button);
bt.letter = string_char_at(alphabet, i+1);
}
//middle row
var alphabet = "ASDFGHJKL";
for(i = 0; i<9; i++){
var bt = instance_create(72+i*32+(8*i), 104, obj_button);
bt.letter = string_char_at(alphabet, i+1);
}
//BOTTOM row
var alphabet = "ZXCVBNM";
for(i = 0; i<7; i++){
var bt = instance_create(88+i*32+(8*i), 144, obj_button);
bt.letter = string_char_at(alphabet, i+1);
}

gameFinished = false;

Code explanation

166
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
randomize(); This creates random seed based on computers clock. This ensures you
get different random words each time you play the game.

globalvar word, revealedWord; declares global variables (same result as using


global.word and global.revealedWord)
word = newWord(); Runs the script newWord and gets back a random word

//setting the displayed word


revealedWord = "";
for(i = 0; i<string_length(word); i++){
revealedWord += "_";
}

This creates a string with the same length as the word, using just _ in place of each letter.

image_index = 0;
image_speed = 0;

Stops any sub image animation.

//creating all the buttons


//top row
var alphabet = "QWERTYUIOP";

Creates a local variable alphabet

for(i = 0; i<10; i++)

This will repeat the code between { and } below until i is more than 10.
{
var bt = instance_create(64+i*32+(8*i), 64, obj_button);

Create an instance of obj_button and assigns it to bt


bt.letter = string_char_at(alphabet, i+1);

This will supercede the code letter = "A"; in obj_button and assign it the letter from the string
alphabet at string position i.

}
//middle row
var alphabet = "ASDFGHJKL";
for(i = 0; i<9; i++){
var bt = instance_create(72+i*32+(8*i), 104, obj_button);
bt.letter = string_char_at(alphabet, i+1);
}

167
BEN TYERS
//BOTTOM row
var alphabet = "ZXCVBNM";
for(i = 0; i<7; i++){
var bt = instance_create(88+i*32+(8*i), 144, obj_button);
bt.letter = string_char_at(alphabet, i+1);
}

The above code creates a keyboard on the screen. If you look back at the object obj_button
you'll see code letter = "A"; in the create event. To draw the keyboard on the screen you could
duplicate obj_button 26 times and set a different letter in the create event. The code above is
an easier way to achieve the same result.

gameFinished = false;

Means the game is still in progress by setting a boolean value to gameFinished.

Now create a Begin Step. This is different from the normal Step event. Actions and code
within a Begin Step will be executed before any other object's step event. This is useful to
ensure a variable has been declared/changed before another object tries to use the variable.
The code for this Begin Step is:
if(!gameFinished && (image_index == image_number-1 || word ==
revealedWord)){
gameFinished = true; //end the current game
with(obj_button){
activated = false; //deactivate all buttons
}
}

The above checks if the game is not finished by checking two condtions, first if the im-
age_index is at the end (all available guesses are used) or the guessed word matches the word
the player is trying to find.

Finally create a draw event for this object and enter the following code.
draw_self();

//draw the word with holes


draw_set_font(fnt_word);
draw_text(64, 240, revealedWord);

//end game message


draw_set_font(fnt_button);
if(gameFinished){
if(word == revealedWord){
draw_set_color(c_lime);//victory
draw_text(64, 280, "You won!");
}else{
draw_set_color(c_red);//loss

168
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
draw_text(64, 280, "You lost!#The word was " + word + ".");
}
draw_set_color(c_black);
}

draw_set_font(-1);

Code explantion
draw_self();

Draws the currently defined sub image with all object properties as if the draw event was
not used.

//draw the word with holes


draw_set_font(fnt_word);

Sets the drawing font


draw_text(64, 240, revealedWord);

Draws the revealedWord variable at a position 64 pixels across and 240 pixels down from
the top left.

//end game message


draw_set_font(fnt_button);

Sets the drawing font


if(gameFinished){ check if game is finished
if(word == revealedWord){
draw_set_color(c_lime);//victory
draw_text(64, 280, "You won!");
}

If game is finished by the player guessing the word, draw the text 'You won!' in lime
colour.
else{
draw_set_color(c_red);//loss
draw_text(64, 280, "You lost!#The word was " + word + ".");
}

If the game is finished by player using all their guesses display 'You lost! The word
was…….'. # means create a line break so following text appears on the next line, as though
enter was pressed.
draw_set_color(c_black);

Reset draw colour back to black


}

169
BEN TYERS

draw_set_font(-1);

Sets the font back to the previous font.

Close any open windows to apply changes.

Create a new object obj_buttonNewWord and apply the sprite spr_newWord.

In the create event add this code:


image_speed = 0;

In the step event, place this code:

//if the mouse hovers above the button


if(mouse_x>=x && mouse_x<x+sprite_width && mouse_y>=y &&
mouse_y<y+sprite_height){
//if the mouse left button is down
if(mouse_check_button(mb_left)){
image_index = 2;
}else{
image_index = 1;
}
//if the button is released
if(mouse_check_button_released(mb_left)){
//start the game over
//reset the hangman
with(obj_hangman){
image_index = 0;
gameFinished = false;
}
//activate all the buttons
with(obj_button){activated = true;}
//find a new word
word = newWord();
//setting the displayed word
revealedWord = "";
for(i = 0; i<string_length(word); i++){
revealedWord += "_";
}

}
}else{
image_index = 0; //change image to activated button
}

Code explanation:
170
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
//if the mouse hovers above the button
if(mouse_x>=x && mouse_x<x+sprite_width && mouse_y>=y &&
mouse_y<y+sprite_height){
//if the mouse left button is down
if(mouse_check_button(mb_left)){
image_index = 2;
}else{
image_index = 1;
} Changes the sub_image, depending if the mouse cursor is hovering over the
button.
//if the button is released
if(mouse_check_button_released(mb_left)){
//start the game over
//reset the hangman
with(obj_hangman){
image_index = 0;
gameFinished = false;
}

Tells the program to end the current game and reset on mouse button released.

//activate all the buttons


with(obj_button){activated = true;} Makes all letter buttons
clickable again.
//find a new word
word = newWord(); Gets a new word from the script newWord.
//setting the displayed word
revealedWord = "";
for(i = 0; i<string_length(word); i++){
revealedWord += "_";
}

}
}else{
image_index = 0; //change image to activated button
}

Re-declares the starting string used to show guessed letters.

Close any open windows to apply changes.


Lastly create a new object obj_buttonExit and apply the sprite spr_exit
In the create event put this code:

image_speed = 0;

In the step event put the following code:

171
BEN TYERS
//if the mouse hovers above the button
if(mouse_x>=x && mouse_x<x+sprite_width && mouse_y>=y &&
mouse_y<y+sprite_height){
//if the mouse left button is down
if(mouse_check_button(mb_left)){
image_index = 2;
}else{
image_index = 1;
}
//if the button is released
if(mouse_check_button_released(mb_left)){
//End the game
game_end();
}
}else{
image_index = 0; //change image to activated button
}

You should not need much explanation for the above code.

Finally create a room, rm_hangman, with a width of 800 and height of 400 then put the
objects in as shown below in figure 9_12. That's one instance of obj_buttonNewWord, one of
objButtonExit and one of obj_hangman.

Figure 9_12. Showing objects placed in room.

Now save and test your game.


A GMZ files for this game is available in the resources download.

172
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

173
BEN TYERS

Chapter 10

Card Matching Game

174
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

In this chapter you'll learn how to use ds lists to store and manipulate data.

Sprites
Load in the following sprites from the resources folder:

Figure 10_1. Showing sprites needed for game.

Create a new background and load in the file bg_wood, name this background bg_wood.
Create a script called mouse_in and put in the following code:
if (mouse_x > argument0 && mouse_y > argument1 && mouse_x <
argument2 && mouse_y < argument3) {
return true;
} else {
return false;
}

This code will return true if the mouse is over an image.


Create a font, font0 and set to Arial size 40.
Create an object obj_level_easy. Put the following code in the create event:
//display options:
cols=4; //columns
gap=16; //padding between card sprites

//create the deck:


deck=ds_grid_create(8,1);
//grid indexes (for readability):
key_sprite=0;

175
BEN TYERS
key_flipped=1;

//add 2 of each card to deck:


ds_grid_set(deck,0,key_sprite,spr_card_1);
ds_grid_set(deck,1,key_sprite,spr_card_1);
ds_grid_set(deck,2,key_sprite,spr_card_2);
ds_grid_set(deck,3,key_sprite,spr_card_2);
ds_grid_set(deck,4,key_sprite,spr_card_3);
ds_grid_set(deck,5,key_sprite,spr_card_3);
ds_grid_set(deck,6,key_sprite,spr_card_4);
ds_grid_set(deck,7,key_sprite,spr_card_4);

//shuffle the deck:


ds_grid_shuffle(deck);

//set card properties (after shuffle!):


ds_grid_resize(deck,ds_grid_width(deck),2);
for (i=0;i<ds_grid_width(deck);i+=1) {
ds_grid_add(deck,i,key_flipped,false); //flipped status
}

//defaults:
click1=noone; //card number clicked
click2=noone; //card number clicked
matches=0;
attempts=ds_grid_width(deck);
show[0]=0;
show[1]=room_speed;

Code explanation:
//display options:
cols=4; //columns
gap=16; //padding between card sprites

Sets some variables so we know how many images to be drawn across the screen and the
gap between them.

//create the deck:


deck=ds_grid_create(8,1);

Creates a ds grid with id and tells it how big to make it.


//grid indexes (for readability):
key_sprite=0;
key_flipped=1;

Declares some variable to use when putting data in the ds grid.

176
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
//add 2 of each card to deck:
ds_grid_set(deck,0,key_sprite,spr_card_1);
ds_grid_set(deck,1,key_sprite,spr_card_1);
ds_grid_set(deck,2,key_sprite,spr_card_2);
ds_grid_set(deck,3,key_sprite,spr_card_2);
ds_grid_set(deck,4,key_sprite,spr_card_3);
ds_grid_set(deck,5,key_sprite,spr_card_3);
ds_grid_set(deck,6,key_sprite,spr_card_4);
ds_grid_set(deck,7,key_sprite,spr_card_4);

Places two of each sprite into the ds grid at the position indicated.

//shuffle the deck:


ds_grid_shuffle(deck);

Randomly shuffles the cards in the ds grid with the id deck.

//set card properties (after shuffle!):


ds_grid_resize(deck,ds_grid_width(deck),2);
for (i=0;i<ds_grid_width(deck);i+=1) {
ds_grid_add(deck,i,key_flipped,false); //flipped status
}

Sets each location (card) by adding a new a location in the ds grid and setting it to false.

//defaults:
click1=noone; //card number clicked
click2=noone; //card number clicked
matches=0;
attempts=ds_grid_width(deck);
show[0]=0;
show[1]=room_speed;

Sets some variables which will be used to keep track of how many cards are flipped and
create a timer that will used to keep non-matching cards visible for 1 second.

In the draw event put in the following code:

//draw the deck:


var i,xdraw,ydraw,x1,y1,x2,y2,cs,row,col;

//draw the deck:


row=0;
col=0;
177
BEN TYERS
for (i=0;i<ds_grid_width(deck);i++) {

//get row & col:


if (i!=0) {
if (i mod cols) = 0 {
row+=1;
col=0;
} else {
col+=1;
}
}

//store current card sprite for convenience:


cs=ds_grid_get(deck,i,key_sprite);

//get card draw position:


xdraw=x+sprite_get_width(cs)-
sprite_get_xoffset(cs)+((sprite_get_width(cs)+gap)*col);
ydraw=y+sprite_get_width(cs)-
sprite_get_yoffset(cs)+((sprite_get_height(cs)+gap)*row);

//draw card front or back:


if (ds_grid_get(deck,i,key_flipped)==true) {
draw_sprite(cs,0,xdraw,ydraw);
} else {
draw_sprite(spr_card_back,0,xdraw,ydraw);
}
//draw_set_color(c_blue); //debugging
//draw_text(xdraw,ydraw,string(i)); //debugging

//card click positions:


x1=xdraw+sprite_get_bbox_left(cs)-sprite_get_xoffset(cs);
y1=ydraw+sprite_get_bbox_top(cs)-sprite_get_yoffset(cs);
x2=xdraw+sprite_get_bbox_right(cs)-sprite_get_xoffset(cs);
y2=ydraw+sprite_get_bbox_bottom(cs)-sprite_get_yoffset(cs);
draw_rectangle(x1,y1,x2,y2,1); //debugging

//check for mouse click:


if (mouse_check_button_pressed(mb_left) && !show[0] &&
!ds_grid_get(deck,i,key_flipped) {
if mouse_in(x1,y1,x2,y2) {
if click1==noone {
click1=i;
} else {
click2=i;
attempts-=1;

178
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
}

//flip the card:


ds_grid_set(deck,i,key_flipped,true);

//check for a match:


if
(ds_grid_get(deck,click1,key_sprite)==ds_grid_get(deck,click2,key_s
prite)) {
matches+=1;
click1=noone;
click2=noone;
} else if click2!= noone {
show[0]=show[1];
}

//end game:
if (matches>=ds_grid_width(deck)/2) {
room_goto(rm_win);
//instance_create(x,y,obj_memory);
instance_destroy();
} else if (attempts<=0) {
room_goto(rm_lose);;
//instance_create(x,y,obj_memory);
instance_destroy();
}

}
}
}

//show fail attempt cards for a while:


if (show[0] > 0) {
show[0]=max(0,show[0]-1);
if (show[0] <= 0){
ds_grid_set(deck,click1,key_flipped,false);
ds_grid_set(deck,click2,key_flipped,false);
click1=noone;
click2=noone;
}
}

//draw score:
draw_set_font(font0);
draw_set_color(c_white);
draw_text(16,16,string(attempts));

179
BEN TYERS

Code explanation:
var i,xdraw,ydraw,x1,y1,x2,y2,cs,row,col;

Declare local variables.

//draw the deck:


row=0;
col=0;
for (i=0;i<ds_grid_width(deck);i+=1) {

This for loop repeats depending on how many cards in the deck.

//get row & col:


if (i!=0) {
if (i mod cols) = 0 {
row+=1;
col=0;
} else {
col+=1;
}
}

Calculates where card should be drawn based on the row and column.

//store current card sprite for convenience:


cs=ds_grid_get(deck,i,key_sprite);

Sets cs to data from ds grid at position i.

//get card draw position:


xdraw=x+sprite_get_width(cs)-
sprite_get_xoffset(cs)+((sprite_get_width(cs)+gap)*col);
ydraw=y+sprite_get_width(cs)-
sprite_get_yoffset(cs)+((sprite_get_height(cs)+gap)*row);

Calculates the x and y position of where to draw the sprite.


//draw card front or back:
if (ds_grid_get(deck,i,key_flipped)==true) {
draw_sprite(cs,0,xdraw,ydraw);
} else {
draw_sprite(spr_card_back,0,xdraw,ydraw);
}

Draws front or back of sprite depending if it is flipped or not.


//draw_set_color(c_blue); //debugging
//draw_text(xdraw,ydraw,string(i));
180
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
//debugging Commented out so not executed, can be used to draw the number of each
card.

//card click positions:


x1=xdraw+sprite_get_bbox_left(cs)-sprite_get_xoffset(cs);
y1=ydraw+sprite_get_bbox_top(cs)-sprite_get_yoffset(cs);
x2=xdraw+sprite_get_bbox_right(cs)-sprite_get_xoffset(cs);
y2=ydraw+sprite_get_bbox_bottom(cs)-sprite_get_yoffset(cs);

Determines where cards can be clicked.


draw_rectangle(x1,y1,x2,y2,1); //debugging

Draws a border around the card. Can be left in, though not required.

//check for mouse click:


if (mouse_check_button_pressed(mb_left) and !show[0] and
!ds_grid_get(deck,i,key_flipped)) {
if mouse_in(x1,y1,x2,y2) {
if (click1==noone) {
click1=i;
} else {
click2=i;
attempts-=1;
}

Detects a mouse click over current card sprite. If card is already flipped not click will be
registered.

//flip the card:


ds_grid_set(deck,i,key_flipped,true);

Flips the clicked card to show the front.

//check for a match:


if
(ds_grid_get(deck,click1,key_sprite)==ds_grid_get(deck,click2,key_s
prite)) {
matches+=1;
click1=noone;
click2=noone;
} else if (click2!= noone) {
show[0]=show[1];
}

If two cards are clicked it checks if the sprites are them same, if they are mark
both as flipped, if not set timer to start
//end game:
181
BEN TYERS
if (matches>=ds_grid_width(deck)/2) {
room_goto(rm_win);
//instance_create(x,y,obj_memory);
instance_destroy();
} else if (attempts<=0) {
room_goto(rm_lose);;
//instance_create(x,y,obj_memory);
instance_destroy();
}

}
}
}

End the game either when all matches are found, then go to room rm_win, or no more
guesses are allowed then and go to room rm_lose.
//show fail attempt cards for a while:
if (show[0] > 0) {
show[0]=max(0,show[0]-1);
if (show[0] <= 0){
ds_grid_set(deck,click1,key_flipped,false);
ds_grid_set(deck,click2,key_flipped,false);
click1=noone;
click2=noone;
}
}

Sets timer to show non matching flipped cards.


//draw score:
draw_set_font(font0);
draw_set_color(c_white);
draw_text(16,16,string(attempts));

Draws the number of attempts remaining in top left of screen.

Create a new object obj_easy_button, and set the sprite spr_easy_button in a mouse left
released button put the following code:
room_goto(rm_easy);

Create a new object obj_playagain, set the sprite spr_playagain. In a left mouse released
event put:
room_goto(rm_menu);

Create a new object obj_youlose and set the sprite spr_you_lose.


Next, create a new object obj_youwin and set the sprite spr_you_win.

182
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Finally, create a new object obj_exit and set the sprite to spr_exit add the following code
to a mouse left button released event:
game_end();

Close any open windows.


Create a room rm_menu. Set the background to bg_wood. Put one instance of
obj_easy_button in it and one of obj_exit. Close the room.
Next, create a new room rm_easy and place one instance of object obj_level_easy in it.
Close the room.
Create a new room rm_win and place one instance of obj_youwin and one of
obj_play_again. Close the room.
Finally, create a new room rm_lose and place one instance of obj_youlose and one of
obj_play_again. Close the room.
Now save and test your game. It should look like Figure 10-1 below.

Figure 10_2. Showing game running.

A GMZ file for this game is available in the resource download.


There is another GMZ showing how multiple levels with harder difficulties with more
cards can be made.

183
BEN TYERS

184
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Chapter 11

Tower Defense Game

185
BEN TYERS

In this chapter you'll learn how to create a basic tower defense type game.

Sprites
Load in the following sprites:

Figure 11_1 Showing sprites.

Sprites spr_enemy1, spr_enemy2 and spr_enemy3 each have 10 sub images, spr_explo-
sion has 7,for example:

Figure 11_2. Showing sub images for sprite spr_enemy_1.

Next load in a new background, and set as shown in Figure 11_3 on the next page, ensur-
ing you set as a tile set and width and height of 32:

186
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 11_3. Setting a background as a tileset.

Now create a room, rm_lvl1, set as a width of 640 and height of 480. Go to the tile tab
and then use the tiles by selecting them to create a room the same as figure 11_4.

Figure 11_4. Room with tiles added.


187
BEN TYERS
Next we'll create a path. Click the create a path button on the top title bar, as shown in
Figure 11_5.

Figure 11_5. Clicking button to create a new path.

Next set snap x and y to 16, click the show room button, and select the room rm_lvl1, as
shown in Figure 11_6.

Figure 11_6. Setting snap and show room.

The program as below, in Figure 11_7, by entering the numbers into the boxes and click-
ing add after each.

Figure 11_7. Points for the path.

Click the green tick to apply changes.


Next load in the following sounds:

Figure 11_8. Sounds required for the game.

Next we'll create some scripts.

188
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
You can create a new script by clicking the 'create a script' button on the top bar, as shown
in Figure 11_9.

Figure 11_9. Button for creating a new script.

Create a new script name it shootBullet (at the top) and enter the following code:
/*
argument0 : bullet type
argument1 : target
argument2 : x
argument3 : y
argument4 : range
argument5 : damage
*/

audio_play_sound(snd_shoot, 0, false);
with(instance_create(argument2, argument3, argument0)){
direction = point_direction(argument2, argument3, argument1.x,
argument1.y);
range = argument4;
damage = argument5;
}

Code explanation: Takes the variables from the sent arguments and creates a bullet.
Click the green tick at the top left to apply changes.
Create another script, shootGuided and program as below:
/*
argument0 : bullet type
argument1 : target
argument2 : x
argument3 : y
argument4 : range
argument5 : damage
*/

audio_play_sound(snd_shoot, 0, false);
with(instance_create(argument2, argument3, argument0)){
target = argument1;
range = argument4;
damage = argument5;
189
BEN TYERS
}

Close this by pressing the green tick.


Finally create a third script, draw_window, and program as below:
/*
argument0 : x1
argument1 : y1
argument2 : x2
argument3 : y2
*/
draw_set_color(c_black);
draw_rectangle(argument0, argument1, argument2, argument3, true);
draw_set_color(c_white);
draw_rectangle(argument0+1, argument1+1, argument2-1, argument3-1,
false);
draw_set_color(c_black);
draw_rectangle(argument0+3, argument1+3, argument2-3, argument3-3,
true);
draw_set_color(c_blue);
draw_rectangle(argument0+4, argument1+4, argument2-4, argument3-4,
false);
draw_set_color(c_white);

Code explanation: draws series of rectangles to give the effect of a pop up window. Then
close the window.
Next create some fonts:
fnt_default as arial bold size 12.
fnt_small as arial size 8.
fnt_title as arial size 64.
fnt_menu as arial size 50.

Next we'll create the menu system. You could easily create buttons like in previous games
in this book; however the system below shows another method of doing this.
Create an object obj_winGame.
In the create event put:
title = "Victory!";
options[0] = "Again!";
options[1] = "Exit";

selected = 0; //index of the selected choice

Code explanation: Sets variable to be used for the menu.


In a begin step event put:
if(keyboard_check_pressed(vk_up) ||
keyboard_check_pressed(vk_down)){
//if the player presses on up or down, move the cursor
//this works because there are only 2 options

190
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
selected = 1-selected;
audio_play_sound(snd_beep1, 0, false);
}
if(keyboard_check_pressed(vk_space) ||
keyboard_check_pressed(vk_enter)){
//if the player presses on enter or space ...
audio_play_sound(snd_beep2, 0, false);
if(selected == 0){
room_goto(rm_lvl1);
}else{
game_end();
}
}

draw_set_font(fnt_menu);
var strW = string_width(options[0])
if(mouse_y>256 && mouse_y<256+string_height(options[0]) &&
mouse_x>(room_width-strW)/2 && mouse_x<(room_width+strW)/2)
{
//if the cursor is above the first option, select it
if(selected != 0){
selected = 0;
audio_play_sound(snd_beep1, 0, false);
}
//if the player clicks, new game
if(mouse_check_button_pressed(mb_left)){
room_goto(rm_lvl1);
audio_play_sound(snd_beep2, 0, false);
}
}

strW = string_width(options[1])
if(mouse_y>352 && mouse_y<352+string_height(options[1]) &&
mouse_x>(room_width-strW)/2 && mouse_x<(room_width+strW)/2)
{
//if the cursor is above the first option, select it
if(selected != 1){
selected = 1;
audio_play_sound(snd_beep1, 0, false);
}
//if the player clicks, end game
if(mouse_check_button_pressed(mb_left)){
game_end();
audio_play_sound(snd_beep2, 0, false);
}
}

191
BEN TYERS
draw_set_font(fnt_default);

Code explanation. Moves the menu option.


In a draw event put:
draw_set_halign(fa_center);
draw_set_font(fnt_title);
draw_set_color(c_yellow);
draw_text(room_width/2, 64, title); //drawing title
draw_set_font(fnt_menu);
for(i=0; i<2; i++){
if(i == selected){
draw_set_color(c_yellow);
}else{
draw_set_color(c_white);
}
draw_text(room_width/2, 256+i*96, options[i]); //draw options
}
draw_set_color(c_white);
draw_set_font(fnt_default);
draw_set_halign(fa_left);

Code explanation: Draws the options on the screen, changing colour for selected option.
This another approach for a menu system you can use instead of creating objects that can be
clicked.

Create a new object obj_mainMenu. Set the parent as obj_winGame.


In the create event put:
title = "Defence";
options[0] = "Start";
options[1] = "Exit";
note = "";

selected = 0; //index of the selected choice

Next create a new object, obj_lostGame and set the parent as obj_winGame.
In the create event put:
title = "You Lose!";
options[0] = "Again!";
options[1] = "Exit";

selected = 0; //index of the selected choice

Now close any open windows.


Create some rooms, rm_mainMenu, rm_lvl1, rm_winGame, and rm_lostGame.
Place one instance of obj_mainMenu in room rm_mainMenu.
Place one instance of obj_winGame in room rm_winGame.
192
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Place one instance of obj_lostGame in room rm_lostGame.

Now we'll create the shop. Create an object obj_shop. Set depth to -1.
In a create event put:
selected = noone;
shopHeight = 128;
shopOpen = false;

money = 2000;

In a begin step event put:


if(mouse_check_button_pressed(mb_left)){
if(shopOpen){
//if the shop is open and the shop button is clicked
//close the shop
if(abs(mouse_x-room_width/2)<=16 && mouse_y>=room_height-
shopHeight-16 && mouse_y<=room_height-shopHeight){
shopOpen = false;
audio_play_sound(snd_beep1, 0, false);
}

//if the player clicks at the height of the buttons


if(mouse_y > room_height-shopHeight+16 && mouse_y <
room_height-shopHeight+144){
if(money >= 1000){
//if the player clicks on the normal tower button
if(mouse_x > 16 && mouse_x < 112){
//purchase normal tower
audio_play_sound(snd_beep2, 0, false);
var newTower = instance_create(mouse_x,
mouse_y, obj_TowerPlacer);
newTower.towerType = obj_EntityTower;
newTower.towerPrice = 1000;
newTower.towerSprite = spr_tower1;
//close the shop
shopOpen = false;
}
if(money >= 2000){
//if the player clicks on the explosive tower
button
if(mouse_x > 144 && mouse_x < 240){
//purchase explosive tower
audio_play_sound(snd_beep2, 0, false);
var newTower = instance_create(mouse_x,
mouse_y, obj_TowerPlacer);

193
BEN TYERS
newTower.towerType = obj_EntitySniperTower;
newTower.towerPrice = 2000;
newTower.towerSprite = spr_tower3;
//close the shop
shopOpen = false;
}
if(money >= 5000){
//if the player clicks on the gatling gun
tower button
if(mouse_x > 272 && mouse_x < 368){
//purchase gatling gun tower
audio_play_sound(snd_beep2, 0, false);
var newTower = instance_create(mouse_x,
mouse_y, obj_TowerPlacer);
newTower.towerType =
obj_EntityGatlingGun;
newTower.towerPrice = 5000;
newTower.towerSprite = spr_tower2;
//close the shop
shopOpen = false;
}
}
}
}

if(selected != noone){
//if the player clicks on the upgrade button
if(mouse_x > 400 && mouse_x < 496){
//find price of the upgrade
var upgradePrice;
switch(selected.object_index){
case obj_EntityTower:
upgradePrice = 500;
break;
case obj_EntityGatlingGun:
upgradePrice = 2500;
break;
case obj_EntitySniperTower:
upgradePrice = 1500;
break;
}
upgradePrice *= selected.level;
if(money >= upgradePrice && selected.level <
3){
//if the player has enough money, get
upgrade

194
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
audio_play_sound(snd_beep2, 0, false);
with(selected){
level++;
range *= 1.1;
}
money -= upgradePrice;
}
}
}
}

}else{
//if the shop is closed and the shop button is clicked
//open the shop
if(abs(mouse_x-room_width/2)<=16 && mouse_y>=room_height-
16){
shopOpen = true;
audio_play_sound(snd_beep1, 0, false);

//remove all tower placers


if(instance_number(obj_TowerPlacer)>0){
with(TowerPlacer){
instance_destroy();
}
}
}else{
//if the user clicks on a tower, select it
selected = instance_position(mouse_x, mouse_y,
obj_EntityTower);
}
}
}

Code explanation: Checks if shop window is up, if it is draws towers depending if player
can buy or upgrade.

In a draw event put:


//if a tower is selected, draw its range
if(selected != noone){
draw_set_color(c_ltgray);
draw_circle(selected.x, selected.y, selected.range, true);
draw_set_color(c_white);
}

Code explanation. When selected this will draw a circle showing the range of the currently
selected tower.

195
BEN TYERS
And in draw GUI event put:
if(shopOpen){
draw_window(0, room_height-shopHeight, room_width-1,
room_height-1);
draw_sprite(spr_shop, shopOpen, room_width/2, room_height-
shopHeight);

//draw the buttons


draw_sprite(spr_shopButton, money>=1000, 16, room_height-
shopHeight+16);
draw_sprite(spr_shopButton, money>=2000, 144, room_height-
shopHeight+16);
draw_sprite(spr_shopButton, money>=5000, 272, room_height-
shopHeight+16);

//draw the towers on the buttons


draw_sprite(spr_tower1, money<1000, 64, room_height-
shopHeight+64);
draw_sprite(spr_tower3, money<2000, 192, room_height-
shopHeight+64);
draw_sprite(spr_tower2, money<5000, 320, room_height-
shopHeight+64);

//draw text on buttons


draw_set_font(fnt_small);
draw_set_halign(fa_center);
draw_text(64, room_height-shopHeight+80, "Normal#1000$");
draw_text(192, room_height-shopHeight+80, "Sniper#2000$");
draw_text(320, room_height-shopHeight+80, "Gatling Gun#5000$");
draw_set_halign(fa_left);
draw_set_font(fnt_default);

//draw the upgrade button


var upgradePrice = 0;
if(selected != noone){
//if a tower is selected, get its price
switch(selected.object_index){
case obj_EntityTower:
upgradePrice = 500;
break;
case obj_EntityGatlingGun:
upgradePrice = 2500;
break;
case obj_EntitySniperTower:
upgradePrice = 1500;
break;
196
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
}
upgradePrice *= selected.level;
}
draw_sprite(spr_shopButton, upgradePrice != 0 &&
money>=upgradePrice && selected.level<3, 400, room_height-
shopHeight+16);
var upTxt = "Upgrade#";
if(selected != noone){
if(selected.level<3){
draw_sprite(selected.sprite_index, upgradePrice == 0 ||
money<upgradePrice || selected.level>=3, 448, room_height-
shopHeight+64);
upTxt += string(upgradePrice) + "$";
}
}
draw_set_font(fnt_small);
draw_set_halign(fa_center);
draw_text(448, room_height-shopHeight+80, upTxt);
draw_set_halign(fa_left);
draw_set_font(fnt_default);
//draw money
draw_text(528, room_height-shopHeight+16, "money
:#"+string(money));
//draw level of the selected tower
if(selected != noone){
draw_text(528, room_height-shopHeight+52, "level
:#"+string(selected.level));
}
}else{
draw_sprite(spr_shop, shopOpen, room_width/2, room_height);
}

Code explanation. If shop is open draws the towers so that the player knows which they
can afford to buy / upgrade.

Close the object.

Create an object obj_EntityBlock, set the depth to 10, set the sprite to spr_blockMask.
In a begin step event put:
if(instance_number(obj_TowerPlacer) > 0){
visible = true;
}else{
visible = false;
}

Code explanation: Closes the object by making it invisible.

197
BEN TYERS

Create a new object obj_EntityTower, set the sprite to spr_tower1, set the parent to
obj_EntityBlock. Set the mask to spr_blockMask ( as shown in Figure 11_10).

Figure 11_10. Setting parent and mask.

In the create event put:


image_speed = 0; //stops the animation of the sprite

range = 120; //tower's shooting range at level 1


coolTime = 30; //time between 2 shots
cooldown = 0; //time left until next shot
bulletType = obj_EntityBullet; //type of bullet the tower uses
level = 1; //between 1 and 3
damage = 20; //base damage at level 1

Code explanation: Sets the variables for the tower type.

In a begin step event put:


//if the tower is still cooling down
if(cooldown > 0){
cooldown--; //decrement the cooldown, ie cooldown-=1
}

//if there is at least one enemy


if(instance_number(obj_EntityEnemy) > 0){
//find the nearest enemy to the tower
var nearestEnemy = instance_nearest(x, y, obj_EntityEnemy);
//if the closest enemy is within the shooting range
if(point_distance(x, y, nearestEnemy.x, nearestEnemy.y) <=
range){
198
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
//if the tower ready to fire then shoot
if(cooldown == 0){
cooldown = coolTime; //reset the cooldown
shootBullet(bulletType, nearestEnemy, x, y, range,
level * damage);
}
}
}

Code explanation: Checks if player can shoot or not. Shoots a bullet if allowed.

Close the object.

Create a new object obj_EntityGatlingGun. Set the sprite to spr_tower2 and the parent to
obj_EntityTower and the mask to spr_blockMask.
In a create event put:
image_speed = 0; //stops the animation of the sprite

range = 80; //tower's shooting range


coolTime = 4; //time between 2 shots
cooldown = 0; //time left until next shot
bulletType = obj_EntityBullet; //type of bullet the tower uses
level = 1; //tower's level (between 1 and 3)
damage = 5; //base damage at level 1

Close the object.


Create a final tower, obj_EntitySniperTower. Set the sprite to spr_tower3 and the parent
to obj_EntityTower and the mask to spr_blockMask.
In a create event put:
image_speed = 0; //stops the animation of the sprite

range = 300; //tower's shooting range


coolTime = 45; //time between 2 shots
cooldown = 0; //time left until next shot
bulletType = obj_EntityGuidedBullet; //type of bullet the tower
uses
level = 1; //tower's level (between 1 and 3)
damage = 50; //base damage at level 1

In a begin step event put the following:


//if the tower is still cooling down
if(cooldown > 0){
cooldown--; //decrement the cooldown
}

199
BEN TYERS

//if there is at least one enemy


if(instance_number(obj_EntityEnemy) > 0){
//find the nearest enemy to the tower
var nearestEnemy = instance_nearest(x, y, obj_EntityEnemy);
//if the closest enemy is within the shooting range
if(point_distance(x, y, nearestEnemy.x, nearestEnemy.y) <=
range){
//if the tower ready to fire then shoot
if(cooldown == 0){
cooldown = coolTime; //reset the cooldown
shootGuided(bulletType, nearestEnemy, x, y, range,
level * damage);
}
}
}

Code explanation: Checks if the tower is allowed to shoot, if it is it creates a bullet.


Close the object.

Next we'll create an object to place the towers once they've been purchased.
Create an object obj_TowerPlacer and set the depth to -2.
In a create event put:
image_speed = 0;

canPlace = 5; //security. Otherwise, the tower will be placed


immediately

towerType = noone;
towerSprite = noone;
towerPrice = 0;

In a begin step event put:


if(canPlace==0){
//if the player clicks, check if the tower can be placed at the
mouse position
if(mouse_check_button(mb_left)){
if(position_meeting(mouse_x - (mouse_x mod 32) + 16,
mouse_y - (mouse_y mod 32) + 16, obj_EntityBlock) &&
!position_meeting(mouse_x, mouse_y, obj_EntityTower)){
//purchase tower
obj_shop.money -= towerPrice;
instance_create(mouse_x - (mouse_x mod 32) + 16,
mouse_y - (mouse_y mod 32) + 16, towerType);
instance_destroy();
}
200
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
}else if(mouse_check_button(mb_right)){
//if the player right-clicks, cancel purchase
instance_destroy();
}
}else{
canPlace--;
}

Code explanation: Detects if tower can be placed at current location on screen.

And in a draw event put:


draw_set_alpha(0.75); //changing the transparency
//draw the tower on the mouse
if(position_meeting(mouse_x - (mouse_x mod 32) + 16, mouse_y -
(mouse_y mod 32) + 16, obj_EntityBlock) &&
!position_meeting(mouse_x, mouse_y, obj_EntityTower)){
draw_sprite(towerSprite, 0, mouse_x - (mouse_x mod 32) + 16,
mouse_y - (mouse_y mod 32) + 16);
}else{
draw_sprite(towerSprite, 1, mouse_x - (mouse_x mod 32) + 16,
mouse_y - (mouse_y mod 32) + 16);
}
draw_set_alpha(1); //reset the transparency

Code explanation: Draws a tower at mouse position, showing if allowed or not.

Now we'll create the bullets.


Create an object obj_EntityBullet, set the sprite as spr_bullet and a depth of -2.
In a create event put:
speed = 20;
range = 0;
damage = 10;

In a begin step event put:


//if the bullet goes beyond the range it will disappear
if(range>0){
range -= speed;
}else{
instance_destroy();
}

var enemy = instance_position(x, y, obj_EntityEnemy);


201
BEN TYERS
//if the bullet collides with an enemy
if(enemy != noone){
enemy.HP -= damage; //damage the enemy
instance_destroy(); //destroy the bullet
}

Close the object.


Create a second bullet object obj_EntityGuidedBullet and set the sprite as spr_bullet2 and
a depth of -2.
In a create event put:

sp = 20;
range = 0;
damage = 40;
target = noone;

And in the begin step event place:


//if the bullet goes beyond the range it will disappear
if(range>0 && instance_exists(target)){
range -= sp;
move_towards_point(target.x, target.y, sp);
}else{
instance_destroy();
}

var enemy = instance_position(x, y, obj_EntityEnemy);


//if the bullet collides with an enemy
if(enemy != noone){
enemy.HP -= damage; //damage the enemy
instance_destroy(); //destroy the bullet
}

Close the object.

Now for the enemies.


First we'll create an object to spawn (create in the game).
Create an object obj_EnemySpawner.
In a create event put:
randomize(); //change the seed the get truely random waves

spawnNumber = 5; //number of enemies to spawn

coolTime = 40; //time between 2 spawns


cooldown = 60; //time left until next spawn

202
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

spawnType = obj_EntityEnemy; //type of enemy to spawn

level = 1; //current level


lastLevel = 20; //last level
baseHP = 100;

In a begin step event put:


if(level <= 20){
if(spawnNumber>0){
if(cooldown > 0){
cooldown--;
}else{
instance_create(x, y, spawnType);
spawnNumber--;
cooldown = coolTime;
}
}else{
if(instance_number(obj_EntityEnemy) == 0){
level++; //next wave
spawnNumber = 5+(level div 2); //reseting the number of
enemies to spawn
cooldown = 60; //reseting cooldown
spawnType = choose(obj_EntityEnemy,
obj_EntityFastEnemy, obj_EntityToughEnemy); //choose the enemy to
spawn for the next wave
}
}
if(baseHP <= 0){
//the player lost
room_goto(rm_lostGame);
}
}else{
//the player won
room_goto(rm_winGame);
}

Code explanation: Spawns random waves of enemies, also checks if player has HP(health
points) and ends the game if 0 or less.
In a draw GUI event put:
draw_window(5*room_width/6, 0, room_width, 31);
draw_text(5*room_width/6+8, 8, "Wave : " + string(level));
draw_window(room_width/2, 0, 5*room_width div 6, 31);
draw_text(room_width/2+8, 8, "Base integrity : " + string(baseHP) +
"%");

203
BEN TYERS

Close the object.


Create a new object, obj_EntityEnemy, set the sprite as spr_enemy1.
In the create event put:
image_speed = 0.5;

maxHP = 100 + power(obj_EnemySpawner.level, 2)*10;


HP = maxHP; // enemy health

sp = 3 //enemy speed
path_start(path_lvl1, sp, 0, true);

Code explanation: Sets up variables for the object, tells object to start moving on the path.

In a destroy event put:


instance_create(x, y, obj_explosion);

In a begin step event put:


//if the HP reaches 0, kill the enemy
if(HP<=0){
instance_destroy();
obj_shop.money += 50*obj_EnemySpawner.level;
}
if(path_position == 1){
instance_destroy();
obj_EnemySpawner.baseHP -= 10;
}

Code explanation: Destroys self if own HP reaches 0. Reduces players HP if reaches end
of path.

In a draw event put:


draw_self();

//draw the health bar


draw_set_color(c_black);
draw_rectangle(x-16, y+14, x+16, y+16, true);
draw_set_color(c_white);
draw_rectangle(x-15, y+15, x+15, y+15, false);
if(HP>0){
if(HP>maxHP/4){
draw_set_color(c_lime);
}else{
draw_set_color(c_red);
}
204
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
draw_rectangle(x-15, y+15, x-15+30*HP div maxHP, y+15, false);
}
draw_set_color(c_white);

Close the object.

Create a new object obj_EntityFastEnemy, set the sprite as spr_enemy2. Set the parent
as: obj_EntityEnemy.
In a create event put:
image_speed = 0.5;

maxHP = 50 + obj_EnemySpawner.level*5;
HP = maxHP; // enemy health

sp = 5 //enemy speed
path_start(path_lvl1, sp, 0, true);

Close the object.


Create the third and final enemy, obj_EntityToughEnemy. Set the sprite as spr_enemy3
and the parent as obj_EntityEnemy.
In a create event put:
image_speed = 0.5;

maxHP = 200 + obj_EnemySpawner.level*20;


HP = maxHP; // enemy health

sp = 1 //enemy speed
path_start(path_lvl1, sp, 0, true);

Close the object.

Finally create an object obj_explosion, set the sprite as spr_explosion.


In a create event put:
image_speed = 1;
audio_play_sound(snd_explode, 0, false);

In an animation end event put:


instance_destroy();
Close the object.

Place one instance of obj_shop and one of obj_EnemySpawner in the room rm_lvl1.
Save and test the game.

205
BEN TYERS
A GMZ file for this project is available in the download resources.

206
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Chapter 12

Scrolling Shooter Game

207
BEN TYERS

In this chapter you'll utilise all the skills you've learnt so far in this book, and learn some
new ones, to create a side scrolling shooter type game
This game uses a lot of voices and sound effects.
Start by loading in the sounds, as shown below in Figure 12_1 and Figure 12_2.

Figure 12_1. Voice sounds for game

208
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 12_2. Sound effects.

Next load in the backgrounds. This game will have a splash screen for the main menu,
one for shop, one for each level of the game (which will be created in game, not from an
image), one provided some info for how to play and one providing info on the bonuses. All
backgounds will be 800x400 pixels.
Load in the backgrounds as shown in Figure 12_3 below.

Figure 12_3. Showing backgrounds loaded in.

Create five new rooms and set the according background, set all rooms to 800 x 400 pixels
in size, as shown in Figure 12_4 below.

Figure 12_4. Showing created rooms.

Now create an object obj_follow_me. No sprite is needed for this.

209
BEN TYERS
Next create a new room, name it room_level_1, set it to a width of 15000 and a height of
400. As shown in Figure 12_5.

Figure 12_5. Setting name of room, and setting width to 15000 and height to 400.

Now go to the views tab and set up as shown below in Figure 12_6.

Figure 12_6. Setting views for room room_level_1.


210
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
The above two steps create a room that is 15000 x 400 pixels. We only want to see part
of the room at once so we set a view of 800 x 400 and a port of 800 x 400, this means we only
see part of the room at any one time. We've set it to follow the object and keep it in the middle
of the room, obj_follow_me. We'll program this object later to make it move through the level.
Place one instance of obj_follow_me in the top of the room room_level_1.
Now go to the the background tab, check the 'draw backgound colour' check box and
choose a light blue colour.
Close any open windows.
Next we'll create some objects to declare variables needed for the game and to progress
through the splash screens.
Create a new object, obj_declare. No sprite is required. Put the code on the next pages
into a create event.

//Declare variables
score=5000;
health=100;
global.weapon=1;
global.level=1;

weapon_no=1;//handgun
global.weapon_info[weapon_no,1]="Hand Gun";//Weapon Name
global.weapon_info[weapon_no,2]=100;//Starting Number
global.weapon_info[weapon_no,3]=1;//Strength
global.weapon_info[weapon_no,4]=1;//Reload Speed
global.weapon_info[weapon_no,5]=1;//Cost
global.weapon_info[weapon_no,6]=5;//Aiming Speed
global.weapon_info[weapon_no,7]=spr_handgun;//Gun Sight for Weapon
global.weapon_info[weapon_no,8]=obj_damage_handgun;//Damage Area
for Weapon
global.weapon_info[weapon_no,9]=snd_handgun;//Sound When Firing
global.weapon_info[weapon_no,10]=snd_voice_handgun_selected;//snd
of voice weapon selected
global.weapon_info[weapon_no,11]=20//ammo pack size

weapon_no=2;//rifle
global.weapon_info[weapon_no,1]="Rifle";//Weapon Name
global.weapon_info[weapon_no,2]=25;//Starting Number
global.weapon_info[weapon_no,3]=2;//Strength
global.weapon_info[weapon_no,4]=2;//Reload Speed
global.weapon_info[weapon_no,5]=2;//Cost
global.weapon_info[weapon_no,6]=3;//Aiming Speed
global.weapon_info[weapon_no,7]=spr_rifle;//Gun Sight for Weapon
global.weapon_info[weapon_no,8]=obj_damage_rifle;//Damage Area for
Weapon
global.weapon_info[weapon_no,9]=snd_rifle;//Sound When Firing

211
BEN TYERS
global.weapon_info[weapon_no,10]=snd_voice_rifle_selected;;//snd of
voice weapon selected
global.weapon_info[weapon_no,11]=15//ammo pack size

weapon_no=3;//machinegun
global.weapon_info[weapon_no,1]="Machine Gun";//Weapon Name
global.weapon_info[weapon_no,2]=100;//Starting Number
global.weapon_info[weapon_no,3]=5;//Strength
global.weapon_info[weapon_no,4]=1;//Reload Speed
global.weapon_info[weapon_no,5]=5;//Cost
global.weapon_info[weapon_no,6]=2;//Aiming Speed
global.weapon_info[weapon_no,7]=spr_machinegun;//Gun Sight for
Weapon
global.weapon_info[weapon_no,8]=obj_machinegun;//Damage Area for
Weapon
global.weapon_info[weapon_no,9]=snd_machinegun;//Sound When Firing
global.weapon_info[weapon_no,10]=snd_voice_machinegun_selected;;//s
nd of voice weapon selected
global.weapon_info[weapon_no,11]=25//ammo pack size

weapon_no=4;//shotgun
global.weapon_info[weapon_no,1]="Shot Gun";//Weapon Name
global.weapon_info[weapon_no,2]=5;//Starting Number
global.weapon_info[weapon_no,3]=25;//Strength
global.weapon_info[weapon_no,4]=10;//Reload Speed
global.weapon_info[weapon_no,5]=50;//Cost
global.weapon_info[weapon_no,6]=4;//Aiming Speed
global.weapon_info[weapon_no,7]=spr_shotgun;//Gun Sight for Weapon
global.weapon_info[weapon_no,8]=obj_damage_shotgun;//Damage Area
for Weapon
global.weapon_info[weapon_no,9]=snd_shotgun;//Sound When Firing
global.weapon_info[weapon_no,10]=snd_voice_shotgun_selected;//snd
of voice weapon selected
global.weapon_info[weapon_no,11]=10//ammo pack size

weapon_no=5;//flamethrower
global.weapon_info[weapon_no,1]="Flame Thrower";//Weapon Name
global.weapon_info[weapon_no,2]=20;//Starting Number
global.weapon_info[weapon_no,3]=50;//Strength
global.weapon_info[weapon_no,4]=4;//Reload Speed
global.weapon_info[weapon_no,5]=50;//Cost
global.weapon_info[weapon_no,6]=4;//Aiming Speed
global.weapon_info[weapon_no,7]=spr_flamethrower;//Gun Sight for
Weapon

212
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
global.weapon_info[weapon_no,8]=obj_damage_flamethrower;//Damage
Area for Weapon
global.weapon_info[weapon_no,9]=snd_flamethrower;//Sound When
Firing
global.weapon_info[weapon_no,10]=snd_voice_flamethrower_selected;//
snd of voice weapon selected
global.weapon_info[weapon_no,11]=5//ammo pack size

weapon_no=6;//nuke
global.weapon_info[weapon_no,1]="Nuke";//Weapon Name
global.weapon_info[weapon_no,2]=1;//Starting Number
global.weapon_info[weapon_no,3]=1000;//Strength
global.weapon_info[weapon_no,4]=10;//Reload Speed
global.weapon_info[weapon_no,5]=1000;//Cost
global.weapon_info[weapon_no,6]=2;//Aiming Speed
global.weapon_info[weapon_no,7]=spr_nuke;//Gun Sight for Weapon
global.weapon_info[weapon_no,8]=obj_damage_nuke;//Damage Area for
Weapon
global.weapon_info[weapon_no,9]=snd_nuke;//Sound When Firing
global.weapon_info[weapon_no,10]=snd_voice_nuke_selected;;//snd of
voice weapon selected
global.weapon_info[weapon_no,11]=2//ammo pack size

Code explanation. This sets up the starting score (which will be used as money), the start-
ing health, the starting weapon number and starting level.
global.weapon array is used to store data for each weapon. This array uses two dimen-
sions the first being used for a weapon number, the second for information (variable, weapon
splash, sounds and sprites).
Place one instance of this object, obj_declare in the first room room_bonuses.
Create a new object, obj_splash_timer. No sprite is rquired. In the create event put the
code:
alarm[0]=90;

Create an event for alarm 0 and put in the following code:


room_goto_next();

Place one instance of this object in each of the rooms: room_bonuses and room_tutorial.
Create a new object, obj_menu_control. No sprite is required. Create a global mouse left
button released event and enter the GML code required to go to the room room_shop. The
GML code is:
room_goto(room_shop);

Place one instance in room room_splash_screen.


Next we'll create the sprites for the objects we set in weapon arrays previously.
The sprites will be used to show which weapon is selected in the game, each weapon will
have a different sprite. For each sprite set the sprite origin to the center of the gun's site, for
example the sprite spr_handgun as shown in Figure 12_7.

213
BEN TYERS

Figure 12_7. Showing sprite origin at gun sites center.

Repeat this process for the rest of the gun sprites so you have the sprite resource tree
looking like that below in Figure 12_8.

Figure 12_8. Showing sprites added.

Next we'll create some splash images. These will be used show how big the damage area
from a weapon shot is.

Load in the required sprites and set the origin as the center, for example:

214
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 12_9. Showing sprite spr_handgun_splash.

Repeat for the other sprites, as shown below in Figure 12_10.

Figure 12_10. Showing sprites added to resource tree.

Next we'll create the objects for these splashes. As we'll be repeating the same process
over and over again, we'll use a parent object. You can assign a parent object from another
object. First we'll create the parent object, obj_parent_splash.
So make an object, obj_parent_splash.
Make an 'End Step' event (note this is different from a normal step event). Then add the
GML to set it to destroy itself, as shown in Figure 12_11.

215
BEN TYERS

Figure 12_11 Adding destroy self action to end step event.

Programming like this with an end step event will ensure other objects that collide with
it have their step event executed before it is destroyed.

Now we'll create some objects and assign the parent object.

Create a new object obj_damage_handgun and assign the sprite spr_handgun_splash, then
set the parent to obj_parent_splash, as shown in Figure 12_12.

216
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 12_12. Showing sprite and parent object set for object obj_damage_handgun.

Repeat the process setting the appropriate sprites and setting the parent for the objects
shown in Figure 12_13 below, but do not do the machine gun splash.

Figure 12_13. Showing splashes objects added.

217
BEN TYERS
For the machine gun we'll do something different. We'll set up so it shoots 10 bullets in
rapid succession.
First create an object obj_damage_machinegun and set sprite as spr_machinegun_splash
and the parent as object obj_parent_splash.
Close this object.
Create a new object obj_machinegun. In a create event put:
alarm[0]=4;
count=1;

Put the following in an alarm 0 event:


count+=1;
if (global.weapon_info[3,2]>0)
{
instance_create(mouse_x,mouse_y,obj_damage_machinegun);
global.weapon_info[global.weapon,2]-=1;
alarm[0]=4;
}

else

{instance_destroy()}

And in a step event put:


if (count==10) {instance_destroy()}

This will check you have ammo if so it will create a weapon splash. Then this will repeat
10 times then destroy itself.

We'll now set-up the shop.


First create a new font, font_shop and set to arial size 18

Create a new room, room_shop. Set the background as bg_shop and set as 800x400 in
size.
Create a control object for the shop, obj_shop_control.
In the create event put:
if (global.level==1) {global.level_speed=2}

In a step event put:

for(ii=0; ii<=6; ii++){

if (keyboard_check_released(ord(string(ii)))) {
global.weapon=ii;
if (score>global.weapon_info[global.weapon,5]) ||
(score==global.weapon_info[global.weapon,5])
{
218
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
//take money off score
score=score-global.weapon_info[global.weapon,5];
//increase ammo no by one
global.weapon_info[global.weapon,2]+=1;
//play sound purchase complete
sound_play(snd_voice_purchase_complete);
}
else
{
//play not enough cash
sound_play(snd_voice_not_enough_cash);
};
}

if (keyboard_check_pressed(ord("0"))) score+=1000;

Code explanation: This will check for key press of 1 through 6. If you have enough money
it’ll add ammo to the weapon, reduce your cash and play the voice sound for purchase com-
plete. If you don’t have enough money it will play the voice sound not enough cash.

In a global right button release event put:


if (global.level==1) { room_goto(room_level_1)};

In a draw event put:


draw_set_font(font_shop);
draw_set_color (c_blue);
draw_text(50,50,"Weapon");
draw_text(270,50,"Ammo");
draw_text(350,50,"Power");
draw_text(450,50,"Cost");
draw_text(50,400,"Right Click To Start Next Level");
draw_text(50,425,"Buy Ammo Using Keys 1 2 3 4 5");
draw_text(575,450,"Cash:"+string(score));

for(i=1;i<7;i+=1){
weapon_no=i;
draw_text(50,50+(weapon_no*50),global. weapon_info[weapon_no,1]);
draw_text(270,50+(weapon_no*50),global. weapon_info[weapon_no,2]);
draw_text(350,50+(weapon_no*50),global. weapon_info[weapon_no,3]);
draw_text(450,50+(weapon_no*50),global. weapon_info[weapon_no,5]);
draw_text(25,50+(weapon_no*50),weapon_no);
};

Place one instance of this object in object room_shop. This will draw some info from the
array onto the screen.
219
BEN TYERS

Next we'll create an object so that the player knows how to use the shop. In a graphics
program of your choice create an image 200x200 pixels with the following info,name as
spr_shop_info, as shown in Figure 12_14.

Figure 12_14. Example Info For Shop.

Create an object, obj_shop_info. Assign this sprite and place one instance in the shop
room (as shown in Figure 12_15).
Now save and test your game. You should now be able to go through the splash screens
and to the shop, which will look like figure 12_15. Check you can buy ammo using keys 1 to
5. Upon clicking the right mouse button you should be taken to the level 1 room, which will
appear as blue.

Figure 12_15. Showing complete shop.

Next we'll create the main control object for game level.
220
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Firstly we'll create a new sprite, font_level, and set arial size 12 bold.
Create an object obj_weapon_control, no sprite is needed.

In the step event put:


x=mouse_x
y=mouse_y

// Detect Keypress - detect weapon


for(i=0; i<=6; i++){
if (keyboard_check_released(ord(string(i)))) {
global.weapon=i;
sound_play(global.weapon_info[global.weapon,10]);
}
}

if (health<0) {room_goto(room_game_over)};

if (health>100) {health=100};

The above code will change the selected weapon based on key press. It will also check
the value of health, ending game if less than 0, or reducing it if it is above 100.

In a global left mouse button pressed put:


if (global.weapon_info[global.weapon,2]>0 )

{
sound_play(global.weapon_info[global.weapon,9]);
global.weapon_info[global.weapon,2]-=1;
instance_create (x,y,global.weapon_info[global.weapon,8])
}

else

{
sound_play(snd_voice_no_ammo)
}

The above code will check you have any of the currently selected weapon's ammo. If
more than 1 it will create an instance of that weapon's splash, otherwise it'll play the voice for
no ammo.
In a global mouse right pressed event put:
global.weapon+=1;
if (global.weapon==7) {global.weapon=1}
sound_play(global.weapon_info[global.weapon,10]);

221
BEN TYERS
In a global mouse middle pressed also put:
global.weapon+=1;
if (global.weapon==7) {global.weapon=1}
sound_play(global.weapon_info[global.weapon,10]);

Both the above codes will change to the next weapon.


In a draw event put the following code:
//global.weapon_info[weapon_no,7]-draw_gun_sight
draw_sprite(global.weapon_info[global.weapon,7],0,x,y);

draw_set_font(font_level);
draw_set_color(c_blue);
//name
draw_text(view_xview+25,view_yview+540,global.weapon_info[global.we
apon,1]);
draw_text(view_xview+220,view_yview+540,"Ammo:");
draw_text(view_xview+350,view_yview+540,global.weapon_info[global.w
eapon,2]);
draw_text(view_xview+450,view_yview+540,"Damage:");
draw_text(view_xview+590,view_yview+540,global.weapon_info[global.w
eapon,3]);
draw_text(view_xview+630,view_yview+540,"Cash:"+string(score));

The above code will draw the weapons info at the bottom of the screen and the sprite for
the currently selected weapon.
Put in a draw health action from the score tab, as shown in Figure 12_16.

Figure 12_16. Using draw action to draw a health bar.

222
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Finally, set the depth to -60 as shown in Figure 12_17. Depth can be used to draw objects
in front of or behind other objects. So objects drawn -60 would draw above objects drawn at
0.

Figure 12_17. Setting the drawing depth.

Now close any open object windows, then place one instance of object obj_weapon_con-
trol in room room_level_1. Close the room window to apply changes.
Now save and test your game so far. Check that each weapon fires, the machine gun does
multiple shots, and that the health bar is drawn in the correct place and you can't fire a weapon
once you've run out of ammo.

Next we'll create a new type of background called a tile, we'll then add this to the room.
Click the Create a Background button on the title bar.
The load in the brick image and set as follows in Figure 12_18.

223
BEN TYERS

Figure 12_18. Setting an image to use as a tileset.

Click OK to close the window. Now open the room room_level_1. Go to the tile tab, then
set snap to 50x50 as shown in Figure 12_19 below.

Figure 12_19. Getting things ready for placing tiles by setting the snap to x 150 and y 100 (the
tile we're using is 150x50).

224
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Place a couple of tiles so the room looks like that in Figure 12_20.

Figure 12_20 adding tiles to room.

Next scroll the room along by clicking where shown below in Figure 12_21.

225
BEN TYERS

Figure 12_21. Click here to change room preview.

Create additional tiles along the whole length of the room.


When done the whole bottom of this room will look like that in Figure 12_22.

Figure 12_22. Showing segment of room with tiles added.

Now open the previously created object obj_follow_me. In the create event put:

226
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
motion_set(0,2);

This will set the object moving to the right at a speed of 2.


Add a step event and put:
if (x==14000) game_restart();

The above will set the object moving right. When it reaches 14000 the game will restart
(we will change this later).
Place one instance of this object in the far left of room room_level_1 as shown in Figure
12_23.

Figure 12_23. Showing obj_follow_me and obj_weapon_control at far left of room.

Now close any open windows. Save and test your game.
Now we'll create some objects to shoot at. First we'll make a tree that shows damage
when hit by a weapon.
227
BEN TYERS
Create a sprite spr_small_tree, and load in two images as shown in Figure 12_24. Set the
sprite origin to the bottom middle of the tree.

Figure 12_24 Showing sub-images for sprite spr_small_tree.

Create an object, obj_small_tree. In a create event put the code:


Image_no=1;

In a collision event with obj_parent_splash put:


image_no=0;

In a draw event put:


draw_sprite(spr_small_tree,image_no,x,y);

Close any open windows.


Open the room room_level_1 and place 20 or so of these trees along the bottom, as shown
in Figure 12_25.

228
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 12_25. Showing some tree objects placed in the room.

Close any open windows and save your game.


Now test you can damage the trees with each weapon.

Now create another object, obj_big_tree using the larger tree images. Program the same
as above.
Do the same with the wooden barrel. Place several of these in the room for level 1.

Next we'll make a moving object to shoot at. We'll create a cloud that moves across the
screen.
Make it the same as the previous objects, but change the create event code to:
image_no=1;
motion_set(180,3);

The above code will make it move to the left at speed 3. Remember to set the draw event
to the new sprite:
draw_sprite(spr_cloud,image_no,x,y);
if (bbox_right<view_xview) instance_destroy()

This code will draw the sprite, and destroy the instance if it is to the left of the view.
This will help the game to run faster, as if the cloud has gone past the screen it will
never be seen again so it’s wasting processing time by existing.
Close any open windows, open the room and add some of these clouds and barrels in the
level. Close the room to apply changes, then save and test your game.
Next we'll create a duck bonus and bonus level.
229
BEN TYERS
First we'll create the duck bonus room.
Create new room room_duck_bonus.
Set it to 800x400, set the background bg_duck_bonus.
Create an object, obj_duck_rifle_splash, set the sprite to and put the followig code in an
end step event:
instance_destroy();

Close the window to apply changes.

Create an object, obj_duck_weapon_control, set the sprite to spr_rifle, and program as


below:
Create event:
timer=2000;
current_timer=timer;
alarm[0]=timer;
sound_play(snd_voice_bonus_level);

Step Event:
current_timer-=1;
x=mouse_x
y=mouse_y

if (current_timer<1) {room_goto(room_shop)};

Global left mouse button pressed event:


instance_create(x,y,obj_duck_rifle_splash);
sound_play(snd_rifle);

Draw event:
draw_text(390,75,score);
draw_self();

//draw timer:
draw_text(10,10,current_timer);

Close any windows to apply changes.

Load in the duck sprite and name spr_duck, set the origin to the centre.
Create an object, obj_duck_bonus, and set the sprite to spr_duck.
Program as below:
Create event:
alarm[0]=50+random(150);

230
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
can_see=false;

Alarm 0 event:
can_see=true;
alarm[1]=5+random(50);

Alarm 1 event:
can_see=false;
alarm[0]=40+random(50);

Collision with obj_duck_rifle_splash:


if (can_see==true)
{
score+=200;
can_see=false;
alarm[0]=40+random(50);
}

Draw Event:
if (can_see==true)
{ draw_self()};

Close windows to apply changes.

Open the room, room_duck_bonus.


Place in 4 instances of obj_duck_bonus and one of obj_duck_weapon_control, so the
room looks like that below:

231
BEN TYERS

Figure 12_26. Showing Bonus Level.

Open object obj_menu_control.


Create key pressed event for key 'D' and set it to go to to room room_duck_bonus using
the code below:
room_goto(room_duck_bonus);

Save and test your game. Press D on the menu room to test the duck bonus level.
Now we'll set it up so if the player hits ten bonus ducks in the level, at the end they'll be
taken to the bonus duck level.
Create a new object obj_duck_for_level and set a new sprite spr_duck_level, setting
origin as center (note use the smaller duck image from the resource folder).
In a collision event with object obj_parent_splash put the code:
global.ducks_destroyed +=1;
instance_destroy();

Close windows to apply changes.


Now open object obj_follow_me, and change the create event to:
motion_set(0,2);
global.ducks_destroyed=0;
and change the step event to:
if (x==14000)
if (global.ducks_destroyed==10( room_goto(room_duck_bonus)
else
game_restart();

Apply any changes by closing the open windows.


Open room_level_1 and place 10 ducks in the level.
232
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Test your game twice, first time shooting all 10 ducks and check it goes to the bonus
room. Then check again without shooting all ducks, it should restart.

Next we'll create an explosion effect that will be used on the enemies.
Create an object, obj_exp_1, and create and set the sprite spr_exp_1, setting the origin to
center.
In the create event put:
image_alpha=1;

In a step event put:


image_alpha-=0.01;
if (image_alpha<0) {instance_destroy()}

And in the draw event put:


draw_self();

The code will change the alpha value (transparancy) of the sprite. It will gradually fade
then destroy itself when faded to 0.
Next we'll create a blood splatter effect used when an enemy shoots back at you. Create
a sprite spr_blood_effect and load in blood effect sprite, as shown below. Set the origin to the
center.

Figure 12_27. Showing images to use for spr_blood_effect

Create an object, obj_blood_effect, set the sprite to spr_blood_effect.


In the create event put:
image_alpha=1;
motion_set(270,4);
233
BEN TYERS
In the step event put:
image_alpha-=0.01;
if (image_alpha<0) {instance_destroy()}

In the draw event place:


draw_self();

A before the above code will gradually change the transparency, but also make it move
slowly down the screen.
Create a new object, obj_smoke, set the sprite as spr_smoke.
Create event put:
image_alpha=1;
motion_set(90,2);

Step Event put:


image_alpha-=0.02;

if (image_alpha<0) {instance_destroy()}

And in the draw event put:


draw_self();

The above will create the same effect as the previous objects, but will move up the screen.
Next load in two sprites, spr_orange_plane_whole, and spr_orange_plane_damaged.
Create an object obj_or_plane_whole and set the sprite spr_orange_plane_whole.
In the create event put:
motion_set(180,2);
my_health=global.level*5;
my_total_health=my_health;
alarm[0]=100+random(100);

In an alarm 0 event put:


instance_create(x,y,obj_blood_effect);
health-=5;
sound_play(snd_hit);
instance_create(x,y,obj_exp_1);
alarm[0]=100+random(100);

and in a step event put:


if (my_health<1)
{
score+=10*global.level;

234
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
instance_create(x,y,obj_or_plane_damaged);
instance_destroy();
}
if (my_health<1)
if (x <view_xview[0] -40) instance_destroy();

The above code will make a moving plane that randomly shoots back at the player.
Create another object, obj_or_plane_damaged and set the sprite as spr_or-
ange_plane_damaged.
In a create event put:
motion_set(270,4);

And in step event put:


if (y>360)
{
instance_create(x,y,obj_exp_1);
instance_create(x,y,obj_smoke);
sound_play(snd_explosion_1);
instance_destroy();
}

Close any open windows.


Now set object obj_spawn_or_plane with the sprite of the whole orange plane, as shown
in Figure 12_28. Make sure you uncheck the visible box (you will see it on the room preview
, but will be invisible when the game is in progress).

Figure 12_28. Setting sprite spr_orange_plane to object obj_spawn_or_plane. Uncheck the


visible box

235
BEN TYERS
Place the following code in the step event:
if (x <view_xview[0] +840)
{
instance_create(x,y,obj_or_plane_whole);
instance_destroy();
}

The above code will create an instance of obj_or_plane_whole when it's just outside the
view (with view width is 800 so 840 is 40 pixels to the right). The purpose for this is to stop
the plane from shooting at the player when it's not visible on the screen. There are other ways
of doing this, but this method is easy to understand.

Create a new object, obj_en_parent. Make a collision event with obj_parent_splash, as


shown in Figure 12_29.

Figrue 12_29. Object obj_en_parent collision event with obj_parent_splash.

In the collision event put the following code:


my_health-=global.weapon_info[global.weapon,3]

The above code will reduce enemy's health by the strength of the currrently selected
weapon.
Create a draw event and place in the following code:
if (my_health>0){
depth=-25;
draw_set_color(c_red);

draw_rectangle(x-50,y-30,x+50,y-36,false);
draw_set_color(c_lime);
draw_rectangle(x-50,y-30,x-50+ (my_health*100/my_total_health)
,
y-36,false);
depth=-20;
draw_self();

}
Close any open windows.
Now open object obj_or_plane_whole and set the object obj_en_parent as a parent, as
shown in Figure 12_30.

236
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 12_30. Setting a parent object.

Place several instances of object obj_spawn_or_plane in the level between the middle and
the top, as shown in Figure 12_31 below:

Figure 12_31. Shown objects obj_spawn_or_plane in room room_level_1.

Close the room window.


Now save and test your game.
237
BEN TYERS
Next we'll create a red plane that goes from left to right.
First create the sprites, spr_red_plane_whole and spr_red_plane_damaged, set the sprite
origin as the top middle of the wing, as shown in Figure 12_32 and 12_33.

Figure 12_32. Setting sprite spr_red_plane_whole.

Figure 12_33. Setting red plane damaged sprite.

238
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Create an object obj_red_plane_damaged and assign the sprite spr_red_plane_damaged.
In a create event put:
motion_set(270,4);

And in a step event put:


if (y>360)
{
instance_create(x,y,obj_exp_1);
instance_create(x,y,obj_smoke);
sound_play(snd_explosion_1);
instance_destroy();
}

Uncheck the visible option, as shown in 12_34 on the next page.

Figure 12_34. Uncheck the visible check box.

Close the object.

Create a new object: obj_red_plane_whole assign the sprite spr_red_plane_whole.


In a create event put:
motion_set(90,3);
my_health=global.level*5;
my_total_health=my_health;
239
BEN TYERS
alarm[0]=100+random(100);

In alarm 0 event put:


instance_create(x,y,obj_blood_effect);
health-=5;
sound_play(snd_hit);
instance_create(x,y,obj_exp_1);
alarm[0]=100+random(100);

In a step event put:


if (my_health<1)
{
score+=10*global.level;
instance_create(x,y,obj_red_plane_damaged);
instance_destroy();
}
if (x >view_xview[0]+840) instance_destroy();

Set the parent to obj_en_parent.


Close the object.
Create an object obj_spawn_red_plane, assign the sprite spr_red_plane_whole and in a
step event put:
if (x <view_xview[0] -40)
{
instance_create(x,y,obj_red_plane_whole);
instance_destroy();
}

Close the object.

Place a few of obj_spawn_red_plane on room room_level_1.


Save and test the game.

Next we'll create some health bonuses, which the player must shoot to collect.
They are:
1 - Apple
2 - Banana
5 - Melon
10 - Strawberry
25 – Pineapple
Load in the sprites and create folder for them, as shown in figure 12_35 below.

240
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Figure 12_35. Showing sprite bonuses in folder.

Next create an object obj_apple_bonus and assign the sprite spr_apple.


Create a collision event with obj_parent_splash.

Figure 12_36. Setting collison event with obj_parent_splash

Repeat the above process with each health bonus, changing the value added to health for
each as required. Create a folder and place these items in them, as shown in Figure 12_37.

Figure 12_37. Showing bonus health objects in a folder.

Place several of each in room room_level_1.


Save your game.
Test the game, get shot by the enemy a few times and check that shooting the bonuses
replenices your health.

Next we'll create some weapon bonuses.


Load in the sprites as shown in Figure 12_38 below.

241
BEN TYERS

Figure 12_38. Ammo pack sprites loaded in and put in folder.

Next create an object, obj_handgun_ammo and assign the sprite spr_handgun_ammo.

Create a collision with object obj_parent_splash and put this code:


weapon=1;
sound_play(snd_voice_extra_ammo);
global.weapon_info[weapon,2]+=global.weapon_info[weapon,11];
instance_destroy();

In a step event put:


if (x <view_xview[0]-40) instance_destroy();

Repeat the above procress for all 6 weapons, changing the code weapon=1 to weapon=2
through to weapon=6.
Put these into a folder, so it looks like figure 12_39.

Figure 12_39. Showing ammo pack objects in folder.

Place a few of each of these in room room_level_1.


Save and test the game.

Next we'll create a friendly object that you must not hit with your weapon.
Load in the hot air balloon sprite set as spr_hot_air_ballon and the damaged hot air bal-
loon as spr_hot_damaged. Set the sprite origin to bottom middle of the balloon for each.
Create a path, by clicking the path button on the title bar, as shown in figure 12_40.

242
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
Figure 12_40. Creating a new path.

Name as apth_balloon and similar to that shown below in Figure 12_41.

Figure 12_41. Showing path path_balloon.

Create a new object, obj_balloon_whole. Add a create event and the set path action from
the move-paths tab. Set as shown in Figure 12_42.

243
BEN TYERS
Figure 12_42. Setting the path to start in create event of obj_balloon_whole.

Next create a collision event with object obj_parent_splash. Put the code:
instance_create(x,y,obj_balloon_damaged);
sound_play(snd_voice_do_not_shoot);
health-=10;
instance_destroy();

Close the object.


Create a new object obj_balloon_damage and assign the sprite spr_hot_damaged.
In the create event put:
motion_set(270,4);

In step event put:


if (y>450) instance_destroy();

Close the object.


Place a few of obj_balloon_whole in the level room_level_1 and then save and test.

A GMZ file for this project is available in the download

244
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO

Chapter 1 3

Book Review

245
BEN TYERS

Congratulations for working your way through this book. You should now have a basic
understanding of D&D and GML. The skills you've learnt should enable you to create some
of your own basic games. Continue your learning in the second book in this series.
You should now know how to do the following:
[ ]- Load and save a project
[ ]- Load in a sprite (both singular and sub-images)
[ ]- Load in a sound
[ ]- Load in a background
[ ]- Create a path
[ ]- Create a script
[ ]- Set a font
[ ]- Create an object
[ ]- Create a room, go to another room

[ ]- Set a sprite origin


[ ]- Play a sound in D&D and GML\
[ ]- Set a path
[ ]- Use a script
[ ]- Set a font / font colour / allignment
[ ]- Assign a sprite to an object
[ ]- Draw a sprite assigned to an object
[ ]- Set a create event
[ ]- Create a Step / Begin Step / End Step event
[ ]- Create a destroy event
[ ]- Create a collision event
[ ]- Create a keyboard event
[ ]- Create various mouse events
[ ]- Create a draw event
[ ]- Use a moved fix action in D&D and GML
[ ]- Use a jump to random position action
[ ]- Set a path action
[ ]- Use a create instance action in D&D and GML
[ ]- Create and use alarms in D&D and GML
[ ]- Open a URL
[ ]- Restart a game
[ ]- Use conditional (if) in D&D and GML
[ ]- Use start and end block in D&D and GML
[ ]- Create code and enter GML
[ ]- Use, draw, change and check score and health
[ ]- Use variables, both real numbers and strings, and local, temporary and global
[ ]- Using ds lists

246
GAMEMAKER STUDIO BOOK – A BEGINNER’S GUIDE TO GAMEMAKER STUDIO
[ ]- Using arrays
[ ]- Creating and using control objects
[ ]- Loading data from text files
[ ]- Placing objects in a room
[ ]- Setting room name, width and height
[ ]- Using backgrounds as tiles
[ ]- Creating and using basic views
[ ]- Using parent objects
[ ]- A few graphical effects

Extra Ideas
Using the skills you've learnt in the book, here are some extra ideas for you to try:
Brick and Ball Game
1) Create backrounds for each level.
2) Create moving blocks.
3) Create a multi-ball special feature.
4) Create a menu with unlockable levels.
5) Add some game music.

Spot the Difference Game


1) Create some background music.
2) Create a countdown timer.
3) Create a bonus level.
4) Source you own graphics and make extra levels.
5) Add some splash screens detailing how to play.

Hangman Game
1) Create extra wordlists which the player can choose from.
2) Improve the quality of the graphics.
3) Create a countdown timer.
4) Create a head-to-head two player game where one player sets the word for the other to
guess.
5) Add sound effects/voices for correct/incorrect guesses.

Memory Card Game


1) Create a menu system.
2) Create extra levels.
3) Create a countdown timer.
4) Add sound effects.
5) Make cards move around in between guesses.

Tower Defence Game


1) Create new maps/levels.
2) Create new towers, including one that shoots multiple bullets.
247
BEN TYERS
3) Create new enemies.
4) Create a timed bonus level.
5) Create some graphical effects to make the appearance of the game better.

Side Scrolling Shooter Game


1) Create extra enemies, such as tanks, planes, helipcopters (sprites in download).
2) Create some background music.
3) Create more weapon types.
4) Create extra levels and a level unlock screen.
5) Make enemies stronger depending on level

248

You might also like