Chapter 3. A Big Picture Overview of How Things Work

Game Maker games consist of many different types of resources. At a minimum, every game must consist of at least one room. However, to really do anything, you must add different types of objects to your games and configure their appearance and behavior. Objects are the core components of every game, so a good understanding of them is essential. This chapter provides you with an overall view of how things work in Game Maker and then focuses in on objects, explaining how they are created and how to make them respond to events and perform actions. To help tie everything together, the chapter ends by walking you through the creation of a demo application, giving you the opportunity to make use of your new understanding of the objects and the Game Maker IDE.

An overview of the major topics covered in this chapter includes:

  • How objects, sprites, rooms, sounds, and backgrounds come together to create games

  • How to create objects and configure their properties

  • How to configure objects to respond to different types of events

  • How to use action icons to specify object behavior

Big Picture Time

As you learned in Chapter 2, every Game Maker game consists at an absolute minimum of at least one room, although games can consist of as many rooms as necessary. These rooms can serve as different locations or parts of a larger game world. Alternatively, in a game made up of different levels, you can use rooms as the basis for each new level. To bring your games to life, you need to add different objects to these rooms. These objects are things like planes, cars, tanks, and monsters as well as missiles, bullets, bouncing balls, and obstacles like walls.

Objects are the key elements upon which games are based. In order to be able to see them, objects must be assigned sprites. Sometimes objects are represented by more than one sprite to allow for the animation of that object. For example, the sprite shown in Figure 3.1, which consists of two subimages, might be used to animate the movement of a bug. If you look closely at both images, you will notice that the bug’s limbs are at different locations. By switching between the two images when the sprite moves, you can create the illusion that the sprite is walking.

Using a sprite with multiple subimages, you can animate sprite movement.

Figure 3.1. Using a sprite with multiple subimages, you can animate sprite movement.

Most objects are visible to the user during game play, but they don’t have to be. While some objects, such as walls, don’t do anything, most of the objects in games move around and interact with one another in some form. Objects can move on their own or under the control of the player. As objects move, they may collide within one another, such as when a player hits a ball with a bat in a baseball game or when a missile hits a spaceship in an outer space shootout game.

Players control certain objects in games. For example, in an adventure game the player may move the main character around the game world in search of treasure and adventure. In a Pac-man-style game, the player moves the Pac-man character around a maze. In addition, other things occur during game play that the player has little if any control over. For example, in Pac-man, ghosts move around the maze and sometimes chase the Pac-man.

The different things that occur during game play are referred to as events. Events occur for all sorts of reasons. For example, events automatically occur when a game is first started or when a room is first displayed. Using these events, your game can set certain things into motion, such as the movement of ghosts in Pactnan or the launching of missiles at enemy space ships in a space shootout game. Events also occur when the player does something. For example, events occur when the player presses keyboard keys or moves the mouse around. Events also occur when objects run into one another, creating collision events. Game Maker support dozens of different types of events.

A big part of game development is deciding to what events you want the objects to react. You specify the actions that objects make in response to events by assigning different action icons to events belonging to objects. For example, if a missile object collides with a spaceship object, you might specify a series of actions that might include:

  • Destroying the missile object

  • Destroying the spaceship object

  • Creating and displaying an explosion object

  • Playing a sound

  • Subtracting one from the number of player lives

  • Restarting the current room (level)

The actions outlined above represent only a small subset of the number of actions that Game Maker supports. As of the writing of this book, Game Maker 7.0 Pro supports 125 different action icons.

To make the rooms in your games more interesting, you will want to decorate them by either assigning them a background color or by using one or more graphic background images to create a suitable playing field or backdrop. In addition to using colorful and well-designed graphics for sprites and backgrounds to make your games visually appealing, you will also want to add sounds to your games to make them more realistic and fun. Use of sound usually involves the addition of sound effects that are played to identify when events occur, such as when a ball slams into a wall or when a missile hits a plane and blows it up. In addition to sound effects, most games include background music that helps to establish a mood and to convey a sense of urgency, suspense, excitement, etc.

To summarize, to create a game using Game Maker you must:

  • Create at least one room

  • Populate the room(s) with its objects (which are represented by sprites)

  • Specify the different types of events that the objects should respond to

  • Assign actions to objects that tell them what actions to perform when events occur.

Hint

The key components to any Game Maker game are objects, rooms, sprites, sounds, and backgrounds. In addition to these components, more advanced games may consist of other types of components, including paths, scripts, fonts, and timelines. This chapter’s primary focus is on objects. You’ll dig deeper into sprites, sounds, backgrounds, and rooms in Chapter 4. In addition, other game resources will be demonstrated in some of the book’s later chapters.

Understanding Objects

A critical component in any game is the objects that you define. These objects represent everything that the player sees and interacts with in the game, except for backgrounds. In addition, many games make use of invisible objects, which although unseen by the player, are used to control key activities within the game. A good understanding of objects, their relationship to one another, and their interactions with each other and the player is essential to any Game Maker developer.

Objects represent things like cars, ships, planes, monsters, bullets, missiles, and so on in games. Most, though not all, objects are represented by a graphical sprite. Objects are designed to react to events that occur during computer games, such as when the player presses a keyboard key or moves the mouse or when two objects collide with one another, such as when a missile hits a tank in a tank battle game. Objects are created by clicking on Resources > Create Object. This displays the Object Properties window as shown in Figure 3.2.

Adding a new object to a Game Maker game.

Figure 3.2. Adding a new object to a Game Maker game.

Objects are really just blueprints or templates that define all attributes of an entity in your game as well as the events that the entities respond to and the actions the entities take in response to those events. Once defined, you can add instances of objects to your game. Each instance that you add is a mirror copy of the object.

You can add as many instances of an object as you want to a game. As such, you can define an object representing an enemy fighter plane and then use it as the basis for instantiating any number of enemy aircraft in a computer game.

Setting Object Properties

Objects are complex entities that consist of a number of properties. Objects have a name, which must be unique within an application. By assigning an object a sprite, you make it possible for the game to display it. In addition, by displaying an object’s Visible property, you can control whether its sprite is visible or not. By enabling or disabling an object’s Solid property, you can determine whether an object can create a collision when it makes contact with other solid objects.

Objects also have a Depth property that determines whether they are drawn on top of or under other objects when they overlap one another. Objects with a higher depth value are drawn first. Objects with a lower value are drawn last (on top). You can even assign a negative value to an object to ensure that it is always drawn on top of other objects. Objects assigned the same depth are drawn in the order in which they are created.

By default, objects are deleted when they leave rooms. However, by enabling an object’s Persistent property, you can keep it alive for as long as you want, thus making it possible to move objects between rooms. An object’s Mask property is used when working with 3D objects to help determine when collisions occur.

Objects can also have child/parent relationships with one another. Objects in Game Maker support a mechanism known as inheritance, which provides you with a powerful means of managing and configuring common object properties and actions. Every object can be assigned a parent. Property changes made to a parent object are automatically reflected in its child objects. Thus if you create a game that uses an army of robots, you can create a parent robot object and configure it, and then, by assigning it as the parent object for other robot objects, automatically configure all of the child objects. That’s a real time-saver.

Hint

As already stated, parent objects can also have parent objects, but you need to make sure that you do not create any cyclical relations. In other words, you cannot assign a parent object’s child object as its parent object.

If necessary, you can further configure child objects. Any changes made to the child object that conflict with those specified in the parent object automatically override the parent’s settings. Objects inherit both the properties and actions of their parents. You can create as many levels of parent/child relationships as you need, in effect defining child, parent, and grandparent objects and so on. One common development technique that Game Maker developers often use is to create a master object and use that object to outline default properties and actions for other objects. This way, if you ever need to modify object behavior, all you need to do is to modify the master object. This can save you tons of time in creating and modifying your games and sure beats having to create objects from scratch or even creating new objects by copying existing ones.

Hint

If you elect to use the master object as an active character within a game, any collisions that occur with this object also apply to all of its child objects. So you’ll need to be careful if you use this approach. Note, however, that if a child object has a collision, the collision has no effect on the child’s parent object.

Configuring Objects to React to Events

In order for objects to do anything, you must configure them to respond to different types of events that occur during game play. Events are a type of message that Game Maker generates during game play, informing objects when things occur. Using Game Maker’s event-driven approach, you can specify different types of actions you want the object to take when different types of events occur. Table 3.1 provides a high-level overview of the different types of events to which all objects can be configured to respond.

Table 3.1. Game Maker Events

Event

Icon

Description

Create

Game Maker Events

Occurs when an instance is created

Destroy

Game Maker Events

Occurs when an instance is destroyed or deleted

Alarm

Game Maker Events

Occurs after a specified number of steps elapse (every instance supports up to 12 alarm events)

Step

Game Maker Events

Occurs continuously throughout application execution providing you with the ability to repeatedly execute actions during game play

Collision

Game Maker Events

Occurs when two instances collide (touch) one another during game play

Keyboard

Game Maker Events

Occurs when the player presses a keyboard key, allowing your application to repeatedly execute one or more actions for as long as a keyboard key is being pressed

Mouse

Game Maker Events

Occurs when the player moves the mouse or clicks on one of its buttons, allowing your application to respond to user input

Other

Game Maker Events

A collection of events that do not fit into other categories that can be used to initiate actions in response to events that occur, for example, when a game or room is started or ended, when a player runs out of lives or health, or when an object moves outside of a room

Draw

Game Maker Events

Allows you to take control of game activity when a sprite drawing event occurs, allowing you to draw a different sprite or to execute any number of alternative actions

Key Press

Game Maker Events

Occurs when the player presses down on a keyboard key allowing your application to respond when a keyboard key is initially pressed

Key Release

Game Maker Events

Occurs when the player releases a keyboard key, allowing your application to respond whenever a pressed key is released

Cancel

Game Maker Events

Closes the Event Selector window (not an event)

As you can see, Game Maker supports a considerable number of events. To specify the events you want to assign to an object, you click on the Object Properties window’s Add Event button located below the events list. This displays the Event Selector window shown in Figure 3.3.

Click on a button to specify the type of event you want an object to work with.

Figure 3.3. Click on a button to specify the type of event you want an object to work with.

Once added, events are displayed in the events list column of the Object Properties window.

Trick

You can drag and drop a copy of an event between objects. Doing so copies any actions associated with the event.

Adding Actions to Objects

Adding events to objects is only half of the story. In order to enable objects to respond to events, you must assign and configure specific types of actions to those events. Game Maker comes equipped with all kinds of predefined actions that it makes accessible on seven sets of tabs located on the right-hand side of the Object Properties window, shown in Figure 3.4 and as listed here:

Game Maker provides easy access to 125 different actions.

Figure 3.4. Game Maker provides easy access to 125 different actions.

  • Move. The actions that control the movement of objects.

  • Mainl. These actions create, modify, and destroy instances of objects; change the sprites assigned to objects; control sound playback; and control movement between different rooms.

  • Main2. These actions control timing within a game, allow a scene to be paused for a specified period of time, display text messages and game information, and provide the ability to restart, terminate, save, and load games.

  • Control. These actions perform the conditional execution of actions, execute GML code and scripts, and create and access variable data.

  • Score. These actions assist you in keeping track of player score, health, and lives.

  • Extra. These actions work with Game Maker’s particle system, enabling you to add various special effects to your games, including rain, snow, smoke, and explosions.

  • Draw. These actions facilitate the drawing of sprites within rooms, allowing you to take control of and manage Game Maker’s drawing operations.

To assign one or more actions to an event, you must select the event and then drag and drop actions onto the actions area. Each action is identified by a description icon that identifies what the action does. In addition, if you move the mouse pointer over an action, Game Maker will display a brief description of the action in a popup window.

Depending on the action selected, Game Maker may display a configuration window when you drop the action on the actions area, allowing you to specify how the action should execute. While configuration options may vary, two common parameters appear on most actions. These options include the Applies to and Relative options. For example, Figure 3.5 shows the window that appears when the Moved Fixed action is added to an event.

Most actions include the Applies to and Relative options located at the top and bottom of the Action Configuration window.

Figure 3.5. Most actions include the Applies to and Relative options located at the top and bottom of the Action Configuration window.

The Applies to option allows you to select one of three choices. Self sets the object to which the action belongs as the target for the action. When working with collision, the Other option lets you apply the action to the other object involved in the collision. Lastly, the Object option lets you specify the name of any object you want as the target of the action. By default, when assigning a numeric value of an object, Game Maker replaces its value with the value specified on the configuration window. However, by selecting the Relative option, you can instruct Game Maker to increment the value by the amount specified.

A quick review of all of the actions provided through the Game Maker IDE is provided in the sections that follow. This is followed by how to create a demo application, with specific focus on the definition of objects, events, and actions.

Hint

The sheer number of available actions can be a little difficult to take in all at once. I suggest you glance through the tables shown in the following sections and that you bookmark these pages so that you can come back to them later when you need to locate a specific type of action.

Controlling Object Movement

Game Maker provides a large number of actions that control the movement of objects. The actions, located on the Move tab, are outlined in Table 3.2.

Table 3.2. Game Maker’s Move Actions

Subcategory

Icon

Action

Edition

Description

Move

Game Maker’s Move Actions

Move Fixed

Lite/Pro

Moves an instance in one of a number of predefined directions

 
Game Maker’s Move Actions

Move Free

Lite/Pro

Moves an instance in a specified direction (between 0 and 360 degrees)

 
Game Maker’s Move Actions

Move Towards

Lite/Pro

Specifies a position and speed an instance should move toward

 
Game Maker’s Move Actions

Speed Horizontal

Lite/Pro

Sets the speed of an instance as it moves horizontally

 
Game Maker’s Move Actions

Speed Vertical

Lite/Pro

Sets the speed of an instance as it moves vertically

 
Game Maker’s Move Actions

Set Gravity

Lite/Pro

Specifies the direction and speed at which gravity affects an instance

 
Game Maker’s Move Actions

Reverse Horizontal

Lite/Pro

Reverses the horizontal direction of an instance

 
Game Maker’s Move Actions

Reverse Vertical

Lite/Pro

Reverses the vertical direction of an instance

 
Game Maker’s Move Actions

Set Friction

Lite/Pro

Applies friction to an instance as it moves

Jump

Game Maker’s Move Actions

Jump to Position

Lite/Pro

Jumps an instance to a specific location

 
Game Maker’s Move Actions

Jump to Start

Lite/Pro

Jumps an instance to the location where it was created

 
Game Maker’s Move Actions

Jump to Random

Lite/Pro

Jumps an instance to a random location within a room

 
Game Maker’s Move Actions

Align to Grid

Lite/Pro

Ensures that an instance’s location is kept in alignment with the room’s grid

 
Game Maker’s Move Actions

Wrap Screen

Lite/Pro

Moves an instance exiting one side of a room to the other side of the room

 
Game Maker’s Move Actions

Move to Contact

Lite/Pro

Moves an instance until it collides with another instance

 
Game Maker’s Move Actions

Bounce

Lite/Pro

Bounces an instance away from another instance when a collision occurs

Paths

Game Maker’s Move Actions

Set Path

Lite/Pro

Instructs an instance to follow a specific path

 
Game Maker’s Move Actions

End Path

Lite/Pro

Instructs an instance to stop on its specified path

 
Game Maker’s Move Actions

Path Position

Lite/Pro

Changes an instance’s position on a path

 
Game Maker’s Move Actions

Path Speed

Lite/Pro

Modifies the speed at which an instance moves along a path

Steps

Game Maker’s Move Actions

Step Towards

Lite/Pro

Instructs an instance to move toward a position on a path

 
Game Maker’s Move Actions

Step Avoiding

Lite/Pro

Moves an instance along a path while attempting to avoid any obstacles that may be in the way

Actions that Affect Objects, Sprites, Sounds, and Rooms

Game Maker has a large number of actions that can do things like create instances of objects, change sprites, play sounds, and move between the different rooms that make up your games. These actions, outlined in Table 3.3, are located on the Main1 tab.

Table 3.3. Game Maker’s Main1 Actions

Subcategory

Icon

Action

Edition

Description

Objects

Game Maker’s Main1 Actions

Create Instance

Lite/Pro

Creates a new instance of a specified object

 
Game Maker’s Main1 Actions

Create Moving

Lite/Pro

Creates a new object, assigning it a speed and direction

 
Game Maker’s Main1 Actions

Create Random

Lite/Pro

Creates an instance using a pool of 1 to 4 objects at a specified location

 
Game Maker’s Main1 Actions

Change Instance

Lite/Pro

Changes the current instance of an object into an instance of another object

 
Game Maker’s Main1 Actions

Destroy Instance

List/Pro

Destroys an instance of an object

 
Game Maker’s Main1 Actions

Destroy at Position

Lite/Pro

Destroys any instances within a specified area

Sprite

Game Maker’s Main1 Actions

Change Sprite

Lite/Pro

Changes the sprite or subimage used to represent an instance

 
Game Maker’s Main1 Actions

Transform Sprite

Pro

Changes the size and orientation of an instance’s sprite

 
Game Maker’s Main1 Actions

Color Sprite

Pro

Changes a sprite’s color by blending its colors with a specified color

Sounds

Game Maker’s Main1 Actions

Play Sound

Lite/Pro

Plays a specified Sound resource

 
Game Maker’s Main1 Actions

Stop Sound

Lite/Pro

Stops playback of a specified Sound resource

 
Game Maker’s Main1 Actions

Check Sound

Lite/Pro

Checks to see if a specified Sound resource is being played

Rooms

Game Maker’s Main1 Actions

Previous Room

Lite/Pro

Moves to the game’s previous room

 
Game Maker’s Main1 Actions

Next Room

Lite/Pro

Moves to the game’s next room

 
Game Maker’s Main1 Actions

Restart Room

Lite/Pro

Restarts a room back to its initial state

 
Game Maker’s Main1 Actions

Different Room

Lite/Pro

Moves to a specified room

 
Game Maker’s Main1 Actions

Check Previous

Lite/Pro

Checks to see if a previous room exists

 
Game Maker’s Main1 Actions

Check Next

Lite/Pro

Checks to see if the next room exists

Controlling Game Timing, Restarts, and Resources

Game Maker also provides access to actions that you can use to control timing within a game, allow a scene to be paused for a specified period of time, and display text messages and game information. In addition, there are actions that provide you with the ability to restart, terminate, save, and load games. These actions, located on the Main2 tab, are outlined in Table 3.4.

Adding Actions that Control Object Execution

Actions located on the Control tab, listed in Table 3.5, control when other types of actions are performed. These actions involve some sort of analysis in which a condition is examined. If the condition proves true, one or more additional actions are performed; otherwise, they are skipped. Other actions let you specify actions to be performed in the event an analysis proves false. Using Start blocks and End blocks you can even group collections of actions together, allowing you to conditionally control the execution of all the actions embedded within the block, in very much the same manner that programmers control the conditional statement execution when writing program code.

Table 3.4. Game Maker’s Main2 Actions

Subcategory

Icon

Action

Edition

Description

Timing

Game Maker’s Main2 Actions

Set Alarm

Lite/Pro

Sets one of twelve alarm clocks for an instance

 
Game Maker’s Main2 Actions

Sleep

Lite/Pro

Pauses a scene for a specified amount of time

 
Game Maker’s Main2 Actions

Set Time Line

Lite/Pro

Assigns a timeline to an instance

 
Game Maker’s Main2 Actions

Time Line Position

Lite/Pro

Sets or modifies the position within a timeline

Info

Game Maker’s Main2 Actions

Display Message

Lite/Pro

Displays a text string in a dialog window

 
Game Maker’s Main2 Actions

Show Info

Lite/Pro

Displays game information in a window

 
Game Maker’s Main2 Actions

Show Video

Pro

Plays a video

Game

Game Maker’s Main2 Actions

Restart Game

Lite/Pro

Restarts a game

 
Game Maker’s Main2 Actions

End Game

Lite/Pro

Terminates a game

 
Game Maker’s Main2 Actions

Save Game

Lite/Pro

Saves the current status of a game

 
Game Maker’s Main2 Actions

Load Game

Lite/Pro

Loads game status for a previously saved game

Resources

Game Maker’s Main2 Actions

Replace Sprite

Pro

Replaces a sprite with an image from a graphic file

 
Game Maker’s Main2 Actions

Replace Sound

Pro

Replaces a sound with a sound loaded from an audio file

 
Game Maker’s Main2 Actions

Replace Background

Pro

Replaces a background with an image loaded from a graphic file

Table 3.5. Game Maker’s Control Actions

Subcategory

Icon

Action

Edition

Description

Questions

Game Maker’s Control Actions

Check Empty

Lite/Pro

Determines if an instance would generate a collision if placed in a specified location (e.g., to determine if it is safe to move the instance)

 
Game Maker’s Control Actions

Check Collision

Lite/Pro

Determines if a collision has occurred

 
Game Maker’s Control Actions

Check Object

Lite/Pro

Determines if an instance has come into contact with another specified instance

 
Game Maker’s Control Actions

Test Instance Count

Lite/Pro

Counts the total number of instances for a specified object

 
Game Maker’s Control Actions

Test Chance

Lite/Pro

Generates a random value by rolling a virtual die

 
Game Maker’s Control Actions

Check Question

Lite/Pro

Interacts with the player by displaying a text string and prompts the player to click on a Yes or No button

 
Game Maker’s Control Actions

Test Expression

Lite/Pro

Evaluates an expression and executes the next action if the expression evaluates as being true

 
Game Maker’s Control Actions

Check Mouse

Lite/Pro

Determines whether a mouse button is being pressed

 
Game Maker’s Control Actions

Check Grid

Lite/Pro

Determines whether an object is evenly aligned with the grid

Other

Game Maker’s Control Actions

Start Block

Lite/Pro

Specifies the beginning of a block of actions

 
Game Maker’s Control Actions

Else

Lite/Pro

Executes the next action when the results of the previous evaluation proves false

 
Game Maker’s Control Actions

Exit Event

Lite/Pro

Stops the execution of actions for the current event

 
Game Maker’s Control Actions

End Block

Lite/Pro

Specifies the end of a block of actions

 
Game Maker’s Control Actions

Repeat

Lite/Pro

Repeats the execution of one or more blocks a specified number of times

 
Game Maker’s Control Actions

Call Parent Event

Lite/Pro

Calls an event within a parent object

Code

Game Maker’s Control Actions

Execute Code

Lite/Pro

Executes GML code typed into the action form

 
Game Maker’s Control Actions

Execute Script

Lite/Pro

Executes GML code stored as a script

 
Game Maker’s Control Actions

Comment

Lite/Pro

Adds a comment line to the actions lists, displays text in italic

Variables

Game Maker’s Control Actions

Set Variable

Lite/Pro

Creates a variable and assigns a value to it

 
Game Maker’s Control Actions

Test Variable

Lite/Pro

Evaluates the value assigned to a variable

 
Game Maker’s Control Actions

Draw Variable

Lite/Pro

Draws (displays) the value assigned to a variable

Keeping Score and Managing Player Lives and Health

Game Maker maintains a built-in score feature that makes it easy for you to keep track of the player’s score. Game Maker also facilitates the tracking of player lives, which you can interact with and control using various actions. Lastly, Game Maker maintains a mechanism for assigning and tracking a player’s health that, like score and lives, can be managed using various actions. All of these actions, outlined below in Table 3.6, are available on the Score tab.

Creating Special Effects and Playing Music CDs

The actions located on the Extra tab, outlined in Table 3.7, are designed to work with Game Maker’s particle system, which can add a variety of special effects to your games. These special effects include things like fireworks, rain, and snow, and are made possible through Game Maker’s built-in particle system.

Hint

You can exercise even more detailed control over Game Maker’s particle system using functions made available to scripts written in GML. You will learn about programming using GML later in this book, in Chapters 9 through 11.

Particles are small, consisting of individual pixels or small sprites. A subset of Game Maker’s particle system can be accessed through different particle actions. Particles have a shape, size, and color. They exist for a limited amount of time and move in a specified speed and direction and are affected through the application of gravity. Particles are created using particle emitters and can be created in bursts or a constant stream. Game Maker allows you to work with up to eight particle emitters at a time. Also included on the Extra tab are actions that allow you to play and control the playback of CDs.

Drawing Shapes, Sprites, and Text

The default behavior in Game Maker is for games to manage the drawing of sprites within rooms. However, using various actions made available on the Draw tab, outlined in Table 3.8, you can modify this behavior and dictate how drawing operations are handled.

Table 3.6. Game Maker’s Score Actions

Subcategory

Icon

Action

Edition

Description

Score

Game Maker’s Score Actions

Set Score

Lite/Pro

Sets or changes the player’s score

 
Game Maker’s Score Actions

Test Score

Lite/Pro

Evaluates the value of the player’s score

 
Game Maker’s Score Actions

Draw Score

Lite/Pro

Draws (displays) the value assigned to the player’s score

 
Game Maker’s Score Actions

Show Highscore

Lite/Pro

Displays the top ten scores for the game in a highscore list table

 
Game Maker’s Score Actions

Clear Highscore

Lite/Pro

Clears out the values stored in the highscore list table

Lives

Game Maker’s Score Actions

Set Lives

Lite/Pro

Sets or changes the number of lives the player has left in the game

 
Game Maker’s Score Actions

Test Lives

Lite/Pro

Evaluates the value of lives the player has left in the game

 
Game Maker’s Score Actions

Draw Lives

Lite/Pro

Draws (displays) the number of lives that the player has left in the game

 
Game Maker’s Score Actions

Draw Life Images

Lite/Pro

Substitutes graphic images representing player lives in place of text when displaying the number of lives remaining

Health

Game Maker’s Score Actions

Set Health

Lite/Pro

Sets or changes the player’s health

 
Game Maker’s Score Actions

Test Health

Lite/Pro

Evaluates the value of the player’s health

 
Game Maker’s Score Actions

Draw Health

Lite/Pro

Draws (displays) the value assigned to the player’s health

 
Game Maker’s Score Actions

Score Caption

Lite/Pro

Allows you to specify whether Game Maker should display the player’s score, lives, and health in the game window’s titlebar

Putting Everything Together

Okay, now that we have reviewed the overall big picture of game development using Game Maker and spent some time focusing on the importance of objects and their support for events and actions, let’s work on a demo program named BouncingBall that will help tie everything together. To begin, start Game Maker, or if Game Maker is already running, click on File > New to create a new application. In response, the Game Maker IDE appears as shown in Figure 3.6.

Beginning the development of a New Game Maker application.

Figure 3.6. Beginning the development of a New Game Maker application.

Table 3.7. Game Maker’s Extra Actions

Subcategory

Icon

Action

Edition

Description

Particles

Game Maker’s Extra Actions

Create Part System

Pro

Creates a particle system

 
Game Maker’s Extra Actions

Destroy Part System

Pro

Destroys a particle system

 
Game Maker’s Extra Actions

Clear Part System

Pro

Clears out any currently displayed particles

 
Game Maker’s Extra Actions

Create Particle

Pro

Creates a specified particle type

 
Game Maker’s Extra Actions

Particle Color

Pro

Sets the color used when drawing a particle

 
Game Maker’s Extra Actions

Particle Life

Pro

Specifies how long a particle is to remain visible

 
Game Maker’s Extra Actions

Particle Speed

Pro

Assigns the speed and direction used when particles move

 
Game Maker’s Extra Actions

Particle Gravity

Pro

Allows you to affect the movement of particles by applying gravity to them

 
Game Maker’s Extra Actions

Particle Secondary

Pro

Allows you to create new particles from existing ones

 
Game Maker’s Extra Actions

Create Emitter

Pro

Creates up to eight particle emitters, which are required to generate particles

 
Game Maker’s Extra Actions

Destroy Emitter

Pro

Destroys a specified particle emitter

 
Game Maker’s Extra Actions

Burst from Emitter

Pro

Instructs a particle emitter to begin generating particles

 
Game Maker’s Extra Actions

Stream from Emitter

Pro

Instructs Game Maker to begin streaming a specified number of particles

CD

Game Maker’s Extra Actions

Play CD

Pro

Plays tracks located on a CD

 
Game Maker’s Extra Actions

Stop CD Pause CD

Pro

Stops CD playback

 
Game Maker’s Extra Actions

Pauses CD

Pro

Pauses CD playback

 
Game Maker’s Extra Actions

Resume CD

Pro

Resumes CD playback

 
Game Maker’s Extra Actions

Check CD

Pro

Checks to see if there is a CD in the computer’s default CD drive

 
Game Maker’s Extra Actions

Check CD Playing

Pro

Checks to see if the computer’s default CD contains a CD

Other

Game Maker’s Extra Actions

Set Cursor

Pro

Replaces the mouse pointer with a sprite

 
Game Maker’s Extra Actions

Open Webpage

Pro

Opens a specified web page using the player’s default web browser

Table 3.8. Game Maker’s Draw Actions

Subcategory

Icon

Action

Edition

Description

Drawing

Game Maker’s Draw Actions

Draw Sprite

Lite/Pro

Draws a sprite and subimage at a specified position

 
Game Maker’s Draw Actions

Draw Background

Lite/Pro

Draws a background at a specified position

 
Game Maker’s Draw Actions

Draw Text

Lite/Pro

Draws text at a specified position

 
Game Maker’s Draw Actions

Draw Scaled Text

Pro

Draws text using a specified horizontal and vertical scaling at a specified position

 
Game Maker’s Draw Actions

Draw Rectangle

Lite/Pro

Draws a rectangle shape based on specified attributes

 
Game Maker’s Draw Actions

Horizontal Gradient

Pro

Draws a rectangle using a horizontally drawn gradient color

 
Game Maker’s Draw Actions

Vertical Gradient

Pro

Draws a rectangle using a vertically drawn gradient color

 
Game Maker’s Draw Actions

Draw Ellipse

Lite/Pro

Draws an ellipse using specified attributes

 
Game Maker’s Draw Actions

Gradient Ellipse

Pro

Draws an ellipse using gradient color

 
Game Maker’s Draw Actions

Draw Line

Lite/Pro

Draws a line between two specified sets of coordinates

 
Game Maker’s Draw Actions

Draw Arrow

Lite/Pro

Draws an arrow between two specified sets of coordinates

Settings

Game Maker’s Draw Actions

Set Color

Lite/Pro

Specifies the color to be used when performing a drawing operation

 
Game Maker’s Draw Actions

Set Font

Lite/Pro

Specifies the font type and attribute data used when drawing text

 
Game Maker’s Draw Actions

Set Full Screen

Lite/Pro

Changes screen display mode to either full screen or a window

Other

Game Maker’s Draw Actions

Take Snapshot

Pro

Captures a screen shot of the game, storing it as a bitmap (.bmp) file

 
Game Maker’s Draw Actions

Create Effect

Pro

Creates various effects like rain, snow, smoke, and explosions

Once complete, the demo will display a window that shows a purple ball bouncing around the screen. The demo will execute within a single window. Each time the ball moves across the screen, it eventually makes contact (collides) with a wall that surrounds the window. After hitting the wall, the ball will bounce off, heading in a different direction. In addition, each time the ball collides with one of the game’s four walls a sound is played.

In order to create this game, you will need to perform a number of steps, as outlined here:

  1. Define two sprites, one to represent the purple ball, and one to represent the wall.

  2. Define the sound that will be use to generate the game’s sound effect.

  3. Configure the game’s background.

  4. Define two objects, one representing the ball and another representing the wall object.

  5. Add a room to the game; populate the room with instances of both objects and configure various room properties.

  6. Configure the ball object to respond to various events and perform specificactions.

Once you have completed these steps, you will be able to save and run the demo.

Step 1—Defining Sprites Used by the Demo

The first step in creating the BouncingBall demo is to create the sprites it will use to represent objects during game play. While you can certainly use Game Maker’s built-in graphic editor to create your sprites from scratch, this editor only provides basic editing capabilities. Most game developers elect instead to either create their sprites using a more powerful third-party tool or to acquire their sprites from other sources, such as purchasing them from professional graphic artists or myriad of sprite packages that can be purchased and downloaded from the Internet.

For this demo, you will use two sprites supplied by Game Maker (as part of the collection of sprites that it stores by default in a collection of folders located at C:Program FilesGame Maker7Sprites). Let’s begin by creating a sprite for the game’s ball. To do so, click on Resources > Create Sprite. This will add a new sprite to the application and open the Sprite Properties window, as shown in Figure 3.7.

Adding a new sprite to the Demo application.

Figure 3.7. Adding a new sprite to the Demo application.

Type spr_ball in the Name file and then click on the Load Sprite button. Using the Open dialog window that appears, drill down into the SpritesVarious folder, select the Ball2.ico file, and then click on the Open button. A picture of the purple ball should be visible when you are returned to the Sprite Properties window. Click on OK to close the Sprite Properties window.

Repeating the steps outlined above, create a second sprite, this time naming it spr_wall and loading Square.ico file, also located in the SpritesVarious folder. These two sprites are the only sprites that you will need to define to create the BouncingBall demo program.

Step 2—Defining the Game’s Sound Effect

The next step in the development of the demo program is to define and generate a sound effect that will be played whenever the ball collides with and bounces off one of the game’s walls. To do so, click on Resources > Create Sound. This will open the Sound Properties window as shown in Figure 3.8. Assign a name of snd_collision to the sound. To import the sound file used as the basis for defining this sound resource, click on the Load Sound button and drill down into the C:Program FilesGame Maker7Sounds folder, select the beep2.wav file, and click on the Open button. When done, the Sound Properties window should look like the example shown in Figure 3.8.

Hint

As you can see in Figure 3.8, Game Maker allows you to configure numerous properties that affect the playback of sounds. You will learn about these properties in Chapter 4.

Adding a new sound to the demo application.

Figure 3.8. Adding a new sound to the demo application.

Step 3—Configuring the Game’s Background

With the demo’s sprites and sound resources now defined, the next step is to define the application’s background. To do so, click on Resources > Create Background. In response, Game Maker displays the Background properties window. Once displayed, enter bck_field into the Name file and then click on the Load Background button and drill down into the C:program FilesGame Maker7Backgrounds folder, select the gray2.wav file, and click on the Open button. When done, the Background Properties window should look like the example shown in Figure 3.9.

Hint

As you can see in Figure 3.9, Game Maker lets you specify a number of different properties that affect the appearance of backgrounds. You will learn about these properties in Chapter 4.

Adding a background to the demo application.

Figure 3.9. Adding a background to the demo application.

Step 4—Defining Ball and Wall Objects

As previously stated, the core components of any Game Maker application are the objects that interact with one another and the player. To create the Boun-cingBall demo, you need to define two objects, a ball object and a wall object. To create the ball object, click on Resources > Create Object. In response, the Object Properties window is displayed. Next, type obj_ball in the Name field and then click on the context menu icon located at the end of the Sprite text field. In response, a context menu is displayed that lists all of the sprites that have been defined in the application. Select the spr_ball object by clicking on its name in the context list. At this point, the Object Properties screen should look like the example shown in Figure 3.10.

Defining an object to represent a bouncing ball.

Figure 3.10. Defining an object to represent a bouncing ball.

Click on the OK button to close the Object Properties window. Now, repeating the steps outlined above, create a new object named obj_wall and assign it the spr_wall sprite, as demonstrated in Figure 3.11.

Defining an object to represent a solid wall.

Figure 3.11. Defining an object to represent a solid wall.

Before closing the Object properties window for the obj_wall object, enable the Solid property. This is necessary to ensure that a collision event occurs when the obj_ball object comes into contact with it.

Step 5—Adding a Room to the Game and Configuring Room Properties

Now that the application’s objects have been created, you need to create a room within which the objects can be placed and interact with one another. To do so, click on Resources > Create Room. In response, the Room Properties window appears as shown in Figure 3.12.

Defining a room within which the objects that make up the application will interact.

Figure 3.12. Defining a room within which the objects that make up the application will interact.

Once created, you need to add instances of the objects that make up the demo application to the room. Let’s begin by adding as many instances of the obj_wall object as are needed to completely close in the entire room. To do so, click on the context menu icon located at the end of the object name file located on the middle of the Objects tab and then select the obj_wall object. You should now see the object’s sprite displayed at the top of the Objects tab. Now, using the mouse pointer, left-click on the upper-left grid square. When you do, an instance of the obj_wall object is displayed in that location in the room. Left-click on the upper-left square just to the right of the instance that you just added to add another object. Repeating this process, add as many instances of the obj_wall object as needed to wall in the entire outer perimeter of the room.

Trick

If you need to add entire rows or columns of the same object, you can quickly do so by moving the mouse pointer to the location where you want to place the first instance of the object and then press and hold the Shift key while also pressing and holding down the left mouse button as you move the mouse. In response, Game Maker will automatically add repeated instances of the object to the window for you.

Once you have completed the above task, you need to add an instance of the obj_ball object to the center of the room. To do so, click on the context-menu icon next to the object name field and select the obj_ball object. Next, left-click just once in the middle of the room. At this point, the room should look like the example shown in Figure 3.13.

Hint

If you want to delete an object instance from a room, all you have to do is right-click on it.

Before closing the Room Properties window, let’s assign the room a name and specify a text string to be displayed in the application window’s titlebar area. To do so, click on the Settings tab and then enter Level1 in the Name field and then type Bouncing Ball Demo in the Caption for the room field, as demonstrated in Figure 3.14. When you are done, click on the green checkmark button located on the Room Properties window’s toolbar to close the Room Properties window.

Hint

As you can see in Figures 3.13 and 3.14, Game Maker lets you specify a number of different properties that affect the appearance and operation of rooms. You will learn about these properties in Chapter 4.

Designing the layout of the game’s room.

Figure 3.13. Designing the layout of the game’s room.

You can display any text you want in the application’s window when the room is loaded.

Figure 3.14. You can display any text you want in the application’s window when the room is loaded.

Step 6—Developing Program Logic for the Ball Object

At this point, you have added and configured all of the different resources needed by the demo application. If you want, you can run the application by clicking on the Green arrow button located on the Game Maker toolbar. In response, Game Maker will load the application and you will see the purple ball and the surrounding walls. However, because you have not yet added any program logic to the game, nothing will happen.

There are two objects in this application. The obj_wall object does not do anything, meaning that it does not respond to any events or execute any actions. The obj_ball object, on the other hand, is supposed to move around the room and bounce off the walls. To set this up, you need to drill down into the Object folder located in the resource folder tree and then double-click on the obj_ball object to re-open its properties window.

In order to get things started, you need to provide instructions to the obj_ball object that will make it move. To accomplish this, you need to first add the Create event to the obj_ball object and then add the Moved Fixed actions to it. To add the Create event, click on the Add Event button located at the bottom of the events list area. In response, the Event Selector window is displayed. Click on the Create button to add the Create event to the object’s events list. Now, select the Create event in the events list and click on the Move tab located on the right-hand side of the Object Properties window. Next, drag and drop an instance of the Moved Fixed icon onto the actions area. When you do, the Move Fixed window appears as shown in Figure 3.15, allowing you to configure the operation of this action.

Using the Move Fixed action, you can instruct Game Maker to move an object in any of up to eight randomly selected directions at any speed you specify.

Figure 3.15. Using the Move Fixed action, you can instruct Game Maker to move an object in any of up to eight randomly selected directions at any speed you specify.

For this demo, the ball will begin moving in one of four randomly selected directions. To set this up, click on each of the four diagonally oriented arrows. As you click on each arrow, it will turn from blue to red, indicating its selection. Next, in order to get the ball moving, specify a value of 8 in the Speed text field. This setting instructs Game Maker to begin moving the ball at a speed of 8 pixels per step. In Game Maker, activity is measured in steps. By default, Game Maker takes 30 steps every second.

Hint

A step is a period of time in which Game Maker performs operations, such as moving sprites around in a room. By default, Game Maker executes 30 steps every second. However, as will be explained in Chapter 4, you can override this behavior by modifying the Speed setting located on the Room Properties Settings tab. A pixel (picture element) is the smallest addressable area that can be drawn on the screen or window.

Click on the OK button to save the changes outlined above. Game Maker will respond by closing the Move Fixed window, leaving the Object Properties window visible. At this point, the Object Properties window for the obj_ball object should look like the example shown in Figure 3.16.

Configuring this instance of the obj_ball object’s direction and speed.

Figure 3.16. Configuring this instance of the obj_ball object’s direction and speed.

If you try running the demo at this point, you will see that when initially started, the ball will randomly move in one of four possible directions. However, instead of bouncing off the walls that make up the perimeter of the game window, the ball keeps moving and disappears. Obviously, this is not how things should work. To correct the situation, you need to add a Collision event to the obj_ball object and then add an action that instructs the ball to bounce away from walls when it comes into contact with them. To accomplish this, click on the Add Event button and then click on the Collision button when the Event Selector window appears. In response, Game Maker will display a context menu, listing all of the objects defined in the application. Click on the obj_wall object. This tells Game Maker that you want to do something whenever the ball collides with a wall.

Now that you have configured the required collision event, select it and then drag and drop the Bounce action (located on the Move tab) to the actions area. When you do, the Bounce window appears. You do not need to make any changes on this window, so click on its OK button to close it. To make the demo more interesting, let’s add an action that plays a sound effect whenever a collision occurs with the ball and a wall. To set this up, click on the Main1 tab and then drag and drop the Play Sound icon onto the actions area. In response, Game Maker will display the Play Sound window. To tell Game Maker what sound you want it to play, click on the context menu icon located at the end of the sound field. Game Maker will then display a context list showing all of the Sounds added to the application. Click on the entry for the snd_collision sound, which you previously added to the application. At this point, the Object Properties window for the obj_ball object should look like the example shown in Figure 3.17.

All of the program logic required to automate the movement of the balls has now been defined.

Figure 3.17. All of the program logic required to automate the movement of the balls has now been defined.

Running the Demo Program

Assuming that you followed along carefully with the instructions provided in the previous sections, your copy of the BouncingBall demo should be ready for execution. To test it, click on Run > Run normally or click on the Run the game button located on the IDE’s toolbar. In response, the Game Maker IDE will disappear and within a few moments the demo will load and execute, as demonstrated in Figure 3.18.

The purple ball will bounce around the window until you decide to close the application.

Figure 3.18. The purple ball will bounce around the window until you decide to close the application.

As you observe the execution of the demo, note the smooth movement of the ball as it glides across the screen, bouncing off each wall in different directions. Also note that every time the ball collides with a wall, the game’s sound effect is played. Further, take note that the text “Bouncing Ball Demo” is visible in the application window’s titlebar. Although it is not a very complex application, the development of this demo application has shown you the basic steps that you need to follow when creating Game Maker games and has demonstrated how Game Maker’s drag-and-drop icon-based approach to program development works.

Once you are done watching the bouncing ball, close the demo application. The Game Maker IDE will reappear. At this point, you may want to save the demo application. To do so, click on File > Save and specify a filename of BouncingBall when prompted to name your application. Game Maker will then save your game in whatever location you specified. You can later reopen the application by clicking on File > Open or by double-clicking on its file icon, as shown in Figure 3.19

Game Maker assigns a file extension of .gmk to your application.

Figure 3.19. Game Maker assigns a file extension of .gmk to your application.

Summary

This chapter provided you with a big picture overview of how objects, sprites, backgrounds, sounds, and rooms are used in the creation of Game Maker games. Since the formulation of objects is the most important part of the game development process, the chapter focused on providing you with a solid understanding of how objects are defined and an outline of all of the different events and action icons that are available to you through the Game Maker IDE. To help tie everything together, the chapter concluded with a demo project that showed you the basic steps involved in application creation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset