2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In...

74
2D Platform Table of Contents 1. Making the Main Character 2. Making the Main Character Move 3. Making a Platform 4. Making a Room 5. Making the Main Character Jump 6. Making a Chaser 7. Setting Lives and Health 8. Throwing Objects in Several Directions 9. Adding Prizes 10.Displaying Lives and Health 11.Making a Second Chaser 12.Adding a Goal 13.Adding a Title Screen and Music 14.Atmosphere 15.Making the Boss 16.Making the Boss Move 17.Making the Boss Jump 18.Making the Boss Attack 19.Adding Health to the Boss 20.Making the Boss Hit the Main Character 21.Adding the Victory Screen © 2009 TechKnowHow, Inc.

Transcript of 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In...

Page 1: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform

Table of Contents

1. Making the Main Character

2. Making the Main Character Move

3. Making a Platform

4. Making a Room

5. Making the Main Character Jump

6. Making a Chaser

7. Setting Lives and Health

8. Throwing Objects in Several Directions

9. Adding Prizes

10.Displaying Lives and Health

11.Making a Second Chaser

12.Adding a Goal

13.Adding a Title Screen and Music

14.Atmosphere

15.Making the Boss

16.Making the Boss Move

17.Making the Boss Jump

18.Making the Boss Attack

19.Adding Health to the Boss

20.Making the Boss Hit the Main Character

21.Adding the Victory Screen

© 2009 TechKnowHow, Inc.

Page 2: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 1

Making the Main Character

We will start creating our platform game by making the main character. The player will control this character with the arrow keys. This character will face left or right depending on the which way it is moving.

1. First, we will add a sprite to represent our main character. A sprite is just a picture; it does not have any game logic associated with it. We will add two sprites, one for each direction that the main character can face. We'll start with the right one.

• Click Create a Sprite.◦ Set the Name to spriteMainRight.

◦ Click Load Sprite and select a character that faces to the right. Your instructor will show you where to find the small character library and help you choose a sprite.

◦ Deselect Precise collision checking.

◦ Under Bounding Box, select Full image.

◦ Click OK.

We select Full image to keep our main character from getting stuck when it turns around.

You may find that the sprite you chose actually faces to the left. If this is the case, when you follow the next step, flip spriteMainRight instead of spriteMainLeft.

© 2009 TechKnowHow, Inc. 1/21

Page 3: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 12. Next, we'll duplicate our main character sprite and flip it to make it face to the left.

• Right-click spriteMainRight in the Sprites list on the left side of the window and select Duplicate.

◦ Set the Name to spriteMainLeft.◦ Click Edit Sprite.

◦ Select Transform → Mirror Horizontal.

◦ Click the green checkmark.◦ Click OK.

3. We now have two sprites for the main character. Next, we need to make an object so we will be able to place our main character in our room.

• Click Create an Object.◦ Set the Name to objectMain.◦ Set the Sprite to spriteMainRight.

◦ Click OK.

Save your work. Next, we will add movement to our main character.

© 2009 TechKnowHow, Inc. 2/22

Page 4: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 2

Making the Main Character Move

Next, we'll add controls to the main character. We'll start with adding movement to the left and right. When the player presses the left arrow key, the main character will move to the left and when the player presses the right arrow key, it will move to the right.

1. We'll start by adding the event for the left key. When the player presses the left key, the main character will turn to face the left. Then, if the space to the left of the main character is unoccupied, the main character will move to the left. We will use the Keyboard type of event so that the event will happen repeatedly as long as the player holds the key down.

• Open objectMain.• Click Add Event and select

Keyboard → Left.• On the Main 1 tab, add a

Change Sprite action.◦ Set sprite to spriteMainLeft.◦ Set subimage to -1. This tells

Game Maker to run the entire animation (if the sprite is animated).

◦ Click OK.

• On the Control tab, add a Check Empty action.◦ Set x to -6.◦ Set y to 0.◦ Set objects to Only solid.◦ Select Relative.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/3

Page 5: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 2• On the Move tab, add a

Speed Horizontal action.◦ Set hor. speed to -5.◦ Click OK.

2. Next, we'll add the event for the right key. Since the actions will be very similar to the actions in the Keyboard Left event, we will duplicate that event to get started.

• Right-click on the Keyboard Left Event we already made.

• Click Duplicate Event and select Keyboard → Right.

• Double click on the Change Sprite action we already made. It should read “Change sprite into spriteMainLeft”.◦ Set sprite to spriteMainRight.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/3

Page 6: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 2• Double click on the Check Empty

action we already made. It should read “If a position is collision free”.◦ Set x to 6.◦ Click OK.

• Double click on the Speed Horizontal action we already made. It should read “Set the horizontal speed”.◦ Set hor. speed to 5.◦ Click OK.

3. To stop the main character's movement when the player releases a key, we will add friction. This will gradually slow the main character to a stop.

• Click Add Event and select Create.

• On the Move tab, add a Set Friction action.◦ Set friction to 0.5.◦ Click OK.

• Click OK to close the Object Properties window.

Save you work. We are almost ready to test our game. Next, we'll add a platform for our character to stand on.

© 2009 TechKnowHow, Inc. 3/3

Page 7: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 3

Making a Platform

We will make a sprite and an object for the platforms in our game. These platforms are what the main character stands on and will be what you use to design your levels.

1. First we need to choose a sprite for the platform.• Click Create a Sprite.

◦ Set the Name to spritePlatform.◦ Click Load Sprite and select a

platform. Your instructor will show you where to find the platforms library.

◦ Deselect Precise collision checking.

◦ Click OK.

2. Next, we need to make an object for the platform.• Click Create an Object.

◦ Set the Name to objectPlatform.◦ Set the Sprite to spritePlatform.◦ Select Solid.◦ Click OK.

If you like, you can add many different platforms for the main character to stand on. Just make sure that the sprites for any new platforms use a Full image bounding box and the objects are Solid.

Save your work. Next, we'll add a room so that we can test our game.

© 2009 TechKnowHow, Inc. 1/1

Page 8: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 4

Making a Room

Next, we will add the first room (level) to our game. We'll also add a background to bring some scenery into our room.

1. First, we need to add a background that will fill the room.

• Click Create a Background.◦ Set the Name to backgroundLevel1.

◦ Click Load Background and select a tileable background. Your instructor will show you where to find the correct library.

◦ Click OK.

2. Next, we'll add a room. We need to set it up so that it will scroll and along follow the main character. We will also set it to display our background.

• Click Create a Room.◦ Click the backgrounds tab.◦ Set the background to backgroundLevel1 by clicking where it says “<no background>”

© 2009 TechKnowHow, Inc. 1/3

Page 9: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 43. Next, we'll set up the room size. We will make the room long so that the screen

will scroll as the player travels through the level.

• Click the settings tab.◦ Set the Name to roomLevel1.◦ Set the Caption to anything you

like. This will display at the top of the game window.

◦ Set the Width to 1280 or 2560.

4. Next, we need to set up a “view” so the screen will scroll. Using a view is like looking into a house through a window. You can only see a small portion of the room at a time. By using views, the player can see just the portion of the room the main character is in.

• Click on the Views Tab. ◦ Select Enable the use of Views.

◦ Select Visible when room starts.

◦ Under Object following, select objectMain by clicking where it says “<no object>”.

◦ Set Hbor to 256. This sets how close the main character can get to the edge of the screen.

◦ Set Vbor to 128.

© 2009 TechKnowHow, Inc. 2/3

Page 10: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 45. Lastly, we need to place some objects, like our main character and some

platforms, in our room.

• Set Snap X to 43.

• Set Snap Y to 32. You may find it helpful to use the Top value of the platform sprite's bounding box.

• Click on the objects tab.

◦ Add objectMain and a couple objectPlatforms to your room.

◦ To select which object to add, click on the large space on the left side of the Room Properties window and choose an object.

◦ To place an object, click where you'd like to the object to go. Right-click an object to delete it.

◦ Hold the Shift key, click, and drag the mouse to place multiple copies of an object.

◦ Click the green check mark to save the room.

Save and test your game (by pressing the green play button on the top menu bar). Make sure that the main character can move left and right. Make sure that it faces the direction it is moving. Make sure that if you let go of a key, it slows down and stops.

We haven't added gravity or jumping to the main character yet. Also, it will not collide with platforms. We'll add that next.

© 2009 TechKnowHow, Inc. 3/3

Page 11: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 5

Making the Main Character Jump

Next, we'll need to make our main character jump. This will allow it to navigate around the level and avoid enemies.

1. First, we will set up an event so that when the player presses the up key, the main character jumps in the air.

• Open objectMain.• Click Add Event and select

Key Press→ Up.

1. On the Control tab, add a Check Collision action.◦ Set x to 0.◦ Set y to 1.◦ Set objects to Only Solid.◦ Select Relative.◦ Click OK.

• On the Control tab, add a Start Block action.

• On the Move tab, add a Speed Vertical action.◦ Set vert. speed to -25.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/4

Page 12: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 5• On the Draw tab, add a

Create Effect action.◦ Set type to explosion.◦ Set x to 16.◦ Set y to 64.◦ Set size to medium.◦ Set color to any color.◦ Set where to below objects.◦ Select Relative.◦ Click OK.

• On the Control tab, add an End Block action.

2. To bring our main character back to the ground, we'll add gravity. If it is in the air (there is nothing under the main character), gravity will pull the main character downward. We will use the step event (a new step happens every 1 / 30th of a second) to continuously check whether to apply gravity or not.

• Still in objectMain, click Add Event and select Step → Step.

• On the Control tab, add a Check Empty action.◦ Set x to 0.◦ Set y to 1.◦ Set objects to Only solid◦ Select Relative.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/4

Page 13: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 5• On the Move tab, add a Set Gravity

action.◦ Set direction to 270. In Game

Maker, directions are in degrees. 270 is down.

◦ Set gravity to 1.5.◦ Click OK.

• On the Control tab, add an Else action.

• On the Move tab, add a Set Gravity action.◦ Set direction to 270. ◦ Set gravity to 0.◦ Click OK.

3. We'll add two more actions to this event to prevent the main character from moving too quickly as it falls. This will keep the main character from skipping through platforms.

• Still in objectMain, click on the Step we already made.

• On the Control tab, add a Test Variable action.◦ Set variable to vspeed.◦ Set value to 12.◦ Set operation to larger than.◦ Click OK.

© 2009 TechKnowHow, Inc. 3/4

Page 14: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 5• On the Move tab, add a

Speed Vertical action.◦ Set vert. speed to 12.◦ Click OK.

4. Lastly, we need to add a script to handle the collisions between the main character and the platforms. Scripts allow you to create additional instructions. They are commonly used for custom or complex actions that would be difficult to create with the action icons.

• On the top menu bar, click on Scripts → Import Scripts.

• Load the script file for this game. Your instructor will show you where it is.

• Back in objectMain, click Add Event and select Step → End Step.

• On the Control tab, add an Execute Script action.◦ Set script to handle_platforms.◦ Click OK.

Save and test your game. Make sure that your main character can jump and land on platforms. Make sure that you place platforms under your main character so that it doesn't fall out of the room.

© 2009 TechKnowHow, Inc. 4/4

Page 15: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 6

Making a Chaser

To make our levels more interesting, we will add chasers that patrol platforms. The main character will need to avoid these chasers to complete the level.

1. This chaser will move left and right and also face in the direction it is moving, so we need to load a sprite that faces to the right.

• Click Create a Sprite.◦ Set the Name to spriteChaser1Right.

◦ Click Load Sprite and select a chaser sprite facing to the right. You instructor will show you where to find the small characters library and help you choose a sprite.

◦ Deselect Precise collision checking.

◦ Under Bounding Box, select Full image.

◦ Click OK.

You may find that the sprite you chose is facing to the left. If that is the case, in the next step, flip spriteChaser1Right, instead of spriteChaser1Left.

© 2009 TechKnowHow, Inc. 1/6

Page 16: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 62. Since we want our chaser to face to the left and right, we need to duplicate the right facing

sprite and flip it.

• Right-click spriteChaser1Right in the Sprites list on the left side of the window and select Duplicate.

◦ Set the Name to spriteChaser1Left.

◦ Click Edit Sprite.

◦ Select Transform → Mirror Horizontal.

◦ Click the green checkmark.◦ Click OK.

3. Before we get started on the object for our chaser, we need to create a helper object. This object will be invisible and will turn the chaser around when they collide. This will keep the chasers from running off the end of a platform.

• Click Create a Sprite.◦ Set the Name to spriteUTurn.◦ Click Load Sprite and load the

U-turn marker. Your instructor will show you where it is.

◦ Deselect Precise collision checking.

◦ Deselect Preload texture.◦ Under Bounding Box, select

Full image.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/6

Page 17: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 64. Next, we need to add an object so we can use it with our chaser.

• Click Create an Object.◦ Set the Name to objectUTurn.◦ Set the Sprite to spriteUTurn.◦ Deselect Visible.◦ Click OK.

5. Next, we'll add an object for our chaser, so we can add logic to it and place it in the level.

• Click Create an Object.◦ Set the Name to objectChaser1.◦ Set the Sprite to spriteChaser1Right.

6. We'll start setting up our chaser by adding a create event. This will make the chaser start moving either to the left or the right.

• In objectChaser1, click Add Event and select Create.

• On the Move tab, add a Move Fixed action.◦ Set Direction to Left and Right.

When we select multiple directions, the chaser will randomly choose in which direction to move.

◦ Set Speed to 5.◦ Click OK.

© 2009 TechKnowHow, Inc. 3/6

Page 18: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 67. Next, we'll add the collision between the chaser and the helper object. When they collide, the

chaser will turn around and head in the other direction.

• Still in objectChaser1, click Add Event and select Collision → objectUTurn.

• On the Move tab, add a Reverse Horizontal action.◦ Click OK.

© 2009 TechKnowHow, Inc. 4/6

Page 19: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 68. Since we don't really know which way the chaser is moving, we'll need to find out which

sprite to use. Since the horizontal speed of the chaser is positive when the chaser is moving to the right and negative when it is moving to the left, we can check the current horizontal speed and choose which sprite to show based on that.

• Click Add Event and select Draw.

• On the Control tab, add a Test Variable action.◦ Set variable to hspeed.◦ Set value to 0.◦ Set operation to larger than.◦ Click OK.

• On the Draw tab, add a Draw Sprite action.◦ Set sprite to spriteChaser1Right.

◦ Set x to 0.◦ Set y to 0.◦ Set subimage to -1.◦ Select Relative.◦ Click OK.

• On the Control tab, add an Else action.

• On the Draw tab, add a Draw Sprite action.◦ Set sprite to spriteChaser1Left.◦ Set x to 0.◦ Set y to 0.◦ Set subimage to -1.◦ Select Relative.◦ Click OK.

© 2009 TechKnowHow, Inc. 5/6

Page 20: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 69. Lastly, we need to make sure that a chaser turns around when it runs into a platform on it's

left or right. We will make the U-turn object the parent of the platform. This means that platform can pretend to be a U-turn object and will do everything the U-turn object does (specifically, it will turn the chaser around when they collide).

• Open objectPlatform.• Set Parent to objectUTurn.

Open roomLevel1 and place some chasers in the room. Make sure that you place U-turn objects on the edges of the platforms to keep the chasers from falling off. Look at the picture below for an example.

Save and test your game. Make sure your chasers move left and right. Note that there will not be any reaction if the main character collides with the chaser. We'll add that soon. Next, we'll add health and lives to the main character.

© 2009 TechKnowHow, Inc. 6/6

Page 21: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 7

Setting Lives and Health

Before we can add collisions between the main character and the chasers, we need to give the main character lives and health. Then, we'll take health away every time the main character collides with an enemy.

1. We'll start by adding a setup object. When the game begins, this object will give the main character full health and a handful of lives. It will also set up the game window to show the current lives, score and health in the title bar. For now, we'll place this object in the first level, but when we add a title screen, we'll move this object there.

• Click Create an Object.◦ Set the Name to objectStart.◦ Deselect Visible.

© 2009 TechKnowHow, Inc. 1/6

Page 22: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 72. Now, we'll add a Game Start event to set up the player's health and lives.

• In objectStart, click Add Event and select Other → Game Start.

• On the Score tab, add a Set Health action.◦ Set value to 100.◦ Click OK.

• On the Score tab, add a Set Lives action.◦ Set new lives to 3.◦ Click OK.

• On the Score tab, add a Score Caption action.◦ Set show lives to show.◦ Set show health to show.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/6

Page 23: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 73. Now we can add the collision between the main character and the chasers. When a chaser

collides with the main character, the player loses some health and the main character bounces away from the enemy.

• Open objectMain and click Add Event and select Collision → objectChaser1.

• On the Score tab, add a Set Health action.◦ Set value to -10.◦ Select Relative.◦ Click OK.

• On the Move tab, add a Speed Vertical action.◦ Set vert. speed to

sign(y - other.y) * 10 . This calculates the vertical direction the main character should move to bounce away from the chaser after a collision.

◦ Click OK.• On the Move tab, add a

Speed Horizontal action.◦ Set hor. speed to

sign(x - other.x) * 10 .◦ Click OK.

© 2009 TechKnowHow, Inc. 3/6

Page 24: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 74. When the main character loses all it's health, it loses a life. It's also placed back

at it's starting position to try again. We will need to set the previous position of the character manually because of the way the script in the End Step event works.

• Still in objectMain, click Add Event and select Other → No More Health.

• On the Score tab, add a Set Lives action.◦ Set new lives to -1.◦ Select Relative.◦ Click OK.

• On the Move tab, add a Jump to Start action.◦ Click OK.

• On the Control tab, add a Set Variable action.◦ Set variable to xprevious.◦ Set value to x.◦ Click OK.

© 2009 TechKnowHow, Inc. 4/6

Page 25: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 7• On the Control tab, add a

Set Variable action.◦ Set variable to y previous .◦ Set value to y.◦ Click OK.

• On the Score tab, add a Set Health action.◦ Set value to 100.◦ Click OK.

5. When the main character runs out of lives, the game is over. We'll show the high score table and ask the player if they would like to try again.

• Click Add Event and select Other → No More Lives.

• On the Main 2 tab, add a Display Message action.◦ Set message to Game Over.◦ Click OK.

• On the Score tab, add a Show Highscore action.◦ Click OK.

© 2009 TechKnowHow, Inc. 5/6

Page 26: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 7• On the Control tab, add a

Test Question action.◦ Set question to Do you want to

play again?◦ Click OK.

• On the Main 2 tab, add a Restart Game action.

• On the Control tab, add an Else action.

• On the Main 2 tab, add an End Game action.

Open roomLevel1 and place objectStart anywhere in the room.

Save and test your game. Make sure that you can collide with the chasers. Make sure you can lose all your health and all your lives. Try to restart the game after you lose. Try to quit the game after you lose. Next, we'll give the main character the ability to defend itself.

© 2009 TechKnowHow, Inc. 6/6

Page 27: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 8

Throwing Objects in Several DirectionsNow that we have chasers running all over our platforms, we need to give the main character a way to defend itself. We'll make the main character throw an object in the direction it is facing when the player presses a key. This thrown object will defeat any chaser it hits.

1. First, we need to create a sprite that will show what our thrown object looks like.

• Click Create a Sprite.◦ Set the Name to spriteMainThrow.

◦ Click Load Sprite and select an object to be thrown. Your instructor will show you where to find the small objects library.

◦ Deselect Precise collision checking.

◦ Click OK.

2. Next, we'll add an object so that we can add logic to the thrown object.

• Click Create an Object.◦ Set the Name to objectMainThrow.

◦ Set the Sprite to spriteMainThrow.

◦ Click OK.

© 2009 TechKnowHow, Inc. 1/5

Page 28: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 83. We will need to remember what direction the player is facing. We'll use a variable to store

the current facing direction whenever the player presses the left or right key.

• Open objectMain.• Click on the Create Event we

already made.• On the Control tab, add a

Set Variable action.◦ Set variable to facingDirection.◦ Set value to 0.◦ Click OK.

4. When the player presses the left key, we want to remember that the character is facing to the left. We'll store 180 in our variable (which in Game Maker stands for left).

• Still in objectMain, click on the Left Keyboard Event we already made.

• On the Control tab, add a Set Variable action.◦ Set variable to facingDirection.◦ Set value to 180.◦ Click OK.

• Click and drag this new action to the top of the Actions list.

© 2009 TechKnowHow, Inc. 2/5

Page 29: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 85. Next, we'll store a 0 (which in Game Maker stands for right) when the player presses the

right key.

• Still in objectMain, click on the Right Keyboard Event we already made.

• On the Control tab, add a Set Variable action.◦ Set variable to facingDirection.◦ Set value to 0.◦ Click OK.

• Drag this action to the top of your list.

© 2009 TechKnowHow, Inc. 3/5

Page 30: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 86. Now we will tell our main character to throw an object whenever the space bar

is pressed. It will throw the object in the direction stored in the facingDirection variable (0 for right and 180 for left).

• Click Add Event and select Key Press → Space.

• On the Main 1 tab, add a Create Moving action.◦ Set object to objectMainThrow.◦ Set x to 0.◦ Set y to 0.◦ Set speed to 8.◦ Set direction to facingDirection.◦ Select Relative.◦ Click OK.

• Click OK to close the Object Properties window.

7. Now that our main character can throw objects, we need to add a couple collisions. First, we'll add a collision between the thrown object and the platform so that thrown objects can't pass through platforms.

• Open objectMainThrow.• Click Add Event and select

Collision → objectPlatform.

• On the Main 1 tab, add a Destroy Instance action.◦ Click OK.

© 2009 TechKnowHow, Inc. 4/5

Page 31: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 88. Lastly, we'll add the collision between the thrown object and the chaser. When

the main character defeats a chaser, it also gains some points.

• Click Add Event and select Collision → objectChaser1.

• On the Score tab, add a Set Score action.◦ Set new score to 25.◦ Select Relative.◦ Click OK.

• On the Main 1 tab, add a Destroy Instance action.◦ Click OK.

• On the Main 1 tab, add a Destroy Instance action.◦ Under Applies to, select Other.◦ Click OK.

Save and test your game. Make sure that you can throw in both directions (left and right). Make sure that you can defeat the chasers with the thrown object. Make sure that you can't throw the object through the platforms. Next, we'll add prizes for the main character to collect.

© 2009 TechKnowHow, Inc. 5/5

Page 32: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 9

Adding Prizes

We will add a prize for the player to collect for points. This will give the player extra incentive to explore the level.

1. First, we will create a sprite to show what our prize will look like.

• Click Create a Sprite.◦ Set the Name to spritePrize1.◦ Click Load Sprite and select a

prize sprite. Your instructor will show you where to find the small objects library.

◦ Deselect Precise collision checking.

◦ Click OK.

2. Next, we'll create an object so that we can add logic to it and place it in our room.

• Click Create an Object.◦ Set the Name to objectPrize1.◦ Set the Sprite to spritePrize1.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/2

Page 33: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 93. When the main character collides with the prize it will gain points and the prize will

disappear.

• Open objectMain.• Click Add Event and select

Collision → objectPrize1.• On the Main 1 tab, add a

Destroy Instance action.◦ Under Applies to, select Other.◦ Click OK.

• On the Score tab, add a Set Score action.◦ Set new score to 25.◦ Select Relative.◦ Click OK.

• On the Draw tab, add a Create Effect action.

◦ Under Applies to, select Other.◦ Set type to star.◦ Set x to 16.◦ Set y to 16.◦ Set size to large.◦ Set color to any color.◦ Set where to above objects.◦ Select Relative.◦ Click OK.

Open roomLevel1 and add some prizes to your room. Place some of them in hard to reach places to encourage players to risk losing a life for a greater score. By strategically placing prizes, you can encourage players to explore your entire level.

Save and test your game. Make sure that you can collect your prizes and that your score increases every time you pick one up. Next, we'll add an on-screen display to show the player's health and score.

© 2009 TechKnowHow, Inc. 2/2

Page 34: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 10

Displaying Health and Score

We will add an object that will display the health and score on the screen. This will make it easier for the player to see the main character's health and keep track of the score.

1. First, we will create an object for the display. It won't have a sprite associated with it because we will be creating our own Draw event for it. We'll set the depth of this object to be lower than all the others so that it displays on top of everything.

• Click Create an Object.◦ Set the Name to objectDisplay◦ Set the Depth to -1000.◦ Click OK.

2. To draw text on the screen, we need to create a font. This will define how the score displays on the screen.

• Click Create a Font.◦ Set the Name to fontScore.◦ Set the Font to anything you

like.◦ Set the Size to 12.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/3

Page 35: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 103. We will define the draw event to display the health and the score. We will use

some variables provided by Game Maker to make sure that the display always stays in the upper corner of the screen.

• Open objectDisplay.• Click Add Event and select Draw.• On the Score tab, add a

Draw Health action.◦ Set x1 to view xview[0] + 16

Note the underscore after “view”. Make sure you use brackets [] and not parentheses ().

◦ Set y1 to view yview[0] + 16 Note the underscore after “view”.

◦ Set x2 to view xview[0] + 192 Note the underscore after “view”.

◦ Set y2 to view yview[0] + 28 Note the underscore after “view”.

◦ Set back color to black.◦ Set bar color to green to red◦ Click OK.

• On the Draw tab, add a Set Font action.◦ Set Font to fontScore.◦ Set align to right.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/3

Page 36: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 10• On the Draw tab, add a Set Color

action.◦ Set color to any color. This will

be the color of the text showing the score.

◦ Click OK.

• On the Score tab, add a Draw Score action.◦ Set x to view xview[0] + 192

(note the underscore after “view”).

◦ Set y to view yview[0] + 32 (note the underscore after “view”).

◦ Click OK.

Open roomLevel1 and place objectDisplay somewhere in the room.

Save and test your game. Make sure that the displays shows your health and score. Next we'll add a second variety of chaser.

© 2009 TechKnowHow, Inc. 3/3

Page 37: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 11

Making a Second Chaser

To add even more danger to our game, we'll add a second type of chaser. This chaser will move up and down through the air. This chaser will be especially dangerous. If this chaser lands on the main character, the main character can lose a large amount of health.

1. First, we need to load a sprite. This chaser will not change directions, so it would be best to pick a sprite that faces forward, but you can choose any sprite that you like.

• Click Create a Sprite.◦ Set the Name to spriteChaser2.◦ Click Load Sprite and select a

sprite for the chaser. Your instructor will show you where to find the chaser library and help you choose a sprite.

◦ Deselect Precise collision checking.

◦ Click OK.

2. Next, we'll make an object for our second chaser. It will be similar to the first chaser, so we can duplicate the first chaser's object to get started.

3.• Right-click on the objectChaser1

and select Duplicate.

• Set the Name to objectChaser2.• Set the Sprite to spriteChaser2.

© 2009 TechKnowHow, Inc. 1/5

Page 38: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 114. To set our second chaser, we need to edit a few events. We'll start with the

create event. We need to change it's movement from moving left and right to moving up and down.

• In objectChaser2, click on the Create Event we already made.

• Double click on the Move Fixed action we already made. It should read “Start moving in a direction.”◦ Deselect the Left and Right

arrows.

◦ Select the Up and Down arrows.

◦ Click OK.

© 2009 TechKnowHow, Inc. 2/5

Page 39: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 115. Next, we need to change how the chaser reacts when it collides with the U-turn helper

object. Since this chaser is traveling up and down, we need to reverse it's vertical movement, instead of it's horizontal movement.

• Still in objectChaser2, click on the Collision with objectUTurn Event we already made.

• Right click the Reverse Horizontal Direction action we already made and select Delete.

• On the Move tab, add a Reverse Vertical action.◦ Click OK.

© 2009 TechKnowHow, Inc. 3/5

Page 40: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 116. Lastly, since this chaser will not change sprites, so we can delete the draw event.

• Still in objectChaser2, right click on the Draw Event we already made and select Delete Event.

• Click OK to close the Object Properties window.

7. Now that our new chaser is ready, we can add the collision with the main character. Again, it will react exactly the same way as the first chaser, so we can duplicate that event.

• Open objectMain.• Right click on the

Collision with objectChaser1 Event we already made and select Duplicate Event.

• Select Collision → objectChaser2.

8. Finally, we need to add the collision between our new chaser and the main character's thrown object. Once again, it will react the same way as the first chaser, so we can duplicate that event.

• Open objectMainThrow.• Click on the

Collision with objectChaser1 Event we already made and select Duplicate Event.

• Select Collision → objectChaser2.

© 2009 TechKnowHow, Inc. 4/5

Page 41: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 11Now open your room and place this new chaser wherever you like. Make sure that you place U-turn helper objects to make sure that your chaser stays in the room.

Now save and test your game. Make sure that your new chaser moves up and down and stays inside the room. Make sure that you can hit the chaser with the main character's thrown object. Make sure that the chaser can hit the main character and take health. Next, we'll add a goal that will bring the character to the next level when it reaches it.

© 2009 TechKnowHow, Inc. 5/5

Page 42: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 12

Making a Goal

Next, we'll make a goal that the main character must reach to complete the level. When the main character touches this goal, it will advance to the next level to challenge the boss.

1. First, we need to add a sprite for the goal to define what it will look like.

• Click Create a Sprite.◦ Set the Name to spriteGoal.◦ Click Load Sprite and select a

goal sprite. Your instructor will show you where to find the large objects library.

◦ Click OK.

2. Next, we'll add an object for our goal so we can place it in our room.

• Click Create an Object.◦ Set the Name to objectGoal.◦ Set the Sprite to spriteGoal.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/3

Page 43: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 123. We'll add a collision between the main character and the goal. When the main character

reaches the goal, the player will gain points, see a message, and jump to the next level.

• Open objectMain.• Click Add Event and select

Collision → objectGoal.

• On the Score tab, add a Set Score action.◦ Set new score to 1000.◦ Select Relative.◦ Click OK.

• On the Main 2 tab, add a Display Message action.◦ Set message to something like

Look out! Here comes the boss!◦ Click OK.

• On the Main 1 tab, add a Next Room action.◦ Set transition to anything you

like.◦ Click OK.

• Open roomLevel1 and place objectGoal in the room.

© 2009 TechKnowHow, Inc. 2/3

Page 44: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 124. Lastly, we will create the boss room. Our boss will have a number of actions it can take,

but it works best when it can rest on flat ground. To prepare our boss room, we will just line to borders of the room with platforms, so that neither character can escape.

• Click Create a Room.• Set Snap X to 43.• Set Snap Y to 32. You may find it

helpful to set this the the Top value of your platform's Bounding Box.

• On the settings tab, set the Name to roomLevel2.

• On the backgrounds tab, set the background to backgroundLevel1.

• On the objects tab, place objectPlatforms around the border of the room.

• Place objectMain at the top of the room.

• Place objectDisplay somewhere in the room.

Once we build the boss, we will add it to this room. For now, we are just creating this room to test our goal.

Save and test your game. Make sure you can reach the goal. Make sure that when you touch it, you are brought to the boss room. Before we dive into the boss, we'll add some music and a title screen to our game.

© 2009 TechKnowHow, Inc. 3/3

Page 45: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 13

Adding a Title Screen and Music

We will add an interesting title screen that will appear before our game starts. This gives the player a chance to understand what kind of game this is before being dropped into the action. We'll also add some background music to further improve the feel of the game.

1. First, we'll load a background for our title screen. Then, we'll edit it by writing the title of the game and how to start. Be careful while editing the background. If you click away from any text (the dotted border disappears), you will not be able to edit it any more. If you make a mistake and can't undo it, close the Image Editor window and answer Don't Save when it asks if you want to save.

• Click Create a Background.

• Set the Name to backgroundTitle.• Click Load Background and select

any background you like.• Click Edit Background.

◦ On the top menu bar, select Text → Font...

◦ Choose any Font that you like.◦ Set the Size to anything between

24 to 72.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/4

Page 46: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 13◦ Click the Draw Text tool.

◦ Click anywhere on the image and type the title of the game.

◦ Click OK.

◦ Position your text anywhere you like.

◦ Click the Draw Text tool again to drop the text in place.

◦ On the top menu bar, select Text → Font...

◦ Set the Size to 24.◦ Click anywhere in the image and

type Press any key.◦ Click OK.◦ Continue to edit the image as you

like.◦ Click the Green Check when

you're happy with your image.

• Click OK.

2. Now, we can add a room for the title screen.

• Click Create a Room.

• Click the settings tab.• Set the Name to roomTitle.

• Click on the backgrounds tab.• Click on <no background> and

select backgroundTitle.• Click the objects tab.• Place objectStart anywhere in the

room.

© 2009 TechKnowHow, Inc. 2/4

Page 47: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 13

3. We need to make a couple changes to objectStart which will let us start the game from the title screen.

• Open objectStart.• Click Add Event and select

Key Press → Any Key.

• On the Main 1 tab, add a Next Room action.◦ Select any transition.◦ Click OK.

4. Next, we'll add a music resource to play at the beginning of the game.

• Click Create a Sound.◦ Set the Name to musicBackground.

◦ Click Load Sound and select a song you'd like to hear. Your instructor will show you where the music library is.

◦ Click Open.◦ Click the Green Play Arrow to

hear the sound.◦ Click the Red Stop Button to

stop listening.◦ Repeat this process until you

find a sound you like.◦ Click OK.

© 2009 TechKnowHow, Inc. 3/4

Page 48: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 135. Now, we'll add an event to play our music when the game starts.

• Back in objectStart. click on the Game Start Event we already made.

• On the Main 1 tab, add a Play Sound action.◦ Set sound to musicBackground.◦ Set loop to true.◦ Click OK.

6. We want our title screen to show up before the first level, so it needs to be first in the list of rooms.

• Click and drag roomTitle above roomLevel1 so that is first in the Rooms list.

Open roomLevel1 and right-click to delete objectStart from the room. You can identify objectStart by moving your mouse over each blue ball with a red question mark in your room and checking the name in the lower left of the screen.

Save and test your game and make sure that your title screen shows at the beginning of the game. Make sure that when you restart the game it brings you back to the title screen. Next, we'll add some special effects to our game.

© 2009 TechKnowHow, Inc. 4/4

Page 49: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 14

Atmosphere

For the second level, we'll add more visual interest by adding a full screen effect such as rain or snow. This will add more atmosphere to the boss encounter.

1. First, we need to add an object that will generate the effect.

• Click Create an Object.◦ Set the Name to

objectAtmosphere.

• Click Add Event and select Step → Step.

• On the Control tab, add a Test Chance action.◦ Set sides to 5. This means that

there is a 1 in 5 chance that the effect will appear this step.

◦ Click OK.

© 2009 TechKnowHow, Inc. 1/2

Page 50: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 14• On the Draw tab, add a

Create Effect action.◦ Set type to any effect. The

effects that work best are snow, rain, and cloud.

◦ Set x to 0.◦ Set y to 0.◦ Set size to medium.◦ Set color to any color.◦ Set where to below objects.◦ If you did not chose rain or

snow as your effect, select Relative.

◦ Click OK.

Open roomLevel2 and place this object anywhere. If you chose an effect other than rain or snow, you may want to place more than one instance around your room. The effect will appear where you place this object.

Save and test your game. You can drag roomLevel2 to the top of the rooms list to test it without having to play through the entire game. Make sure that your effect shows up in your second level. Next, we'll get started building our boss.

© 2009 TechKnowHow, Inc. 2/2

Page 51: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 15

Making the Boss

Now, we'll create the final enemy of the game: the Boss. Our boss will have three different behaviors that it can switch between. It can move towards the main character, jump in the air, or throw a set of objects.

The boss always starts off running. After running towards the main character, it will randomly choose to jump or throw some objects. After it finishes either action, it again runs towards the main character, starting the cycle again.

1. We'll start by adding a sprite to represent our boss. We'll start with just one sprite for all three behaviors, but later you can make a different sprite for each.

• Click Create a Sprite.◦ Set the Name to spriteBoss.◦ Click Load Sprite and select

large boss character sprite. Your instructor will show you where to find the large character library.

◦ Deselect Precise collision checking.

◦ Deselect Preload texture.◦ Click OK.

2. Next, we'll add an object for the boss. This object will be the base object. We will have two others so that there is one for each type of behavior.

• Click Create an Object.◦ Set the Name to objectBoss.◦ Set the Sprite to spriteBoss.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/2

Page 52: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 153. We'll duplicate the boss object to make the other two behavior objects. We'll start with the

jumping behavior. We'll make the the main boss object the parent of both of these new behavior objects so that we can define actions and events for the main boss object and they will apply to all three.

• Right-click on objectBoss we already made and select Duplicate.

• Set the Name to objectBossJump.• Set Parent to objectBoss.• Click OK.

4. Next, we'll duplicate the main boss object again for the throwing behavior.

• Right-click on objectBoss we already made and select Duplicate.

• Set the Name to objectBossAttack.• Set Parent to objectBoss.• Click OK.

Save your work, but don't test just yet. Our boss is far from ready. Next, we'll set up the running behavior.

© 2009 TechKnowHow, Inc. 2/2

Page 53: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 16

Making the Boss Move

Now, we'll set up the running behavior. In this mode, the boss will run towards the main character for a little while. After that time, the boss will randomly choose whether to jump or throw some objects.

1. We'll start by adding a create event to our boss. We'll set an alarm for the when the boss should start moving. This is most important when the boss goes back to the running behavior after jumping or throwing something. This gives the main character a moment to try and hit the boss.

• Open objectBoss• Click Add Event and select Create.

• On the Main 2 tab, add a Set Alarm action.◦ Set number of steps to 15.

Fifteen steps is half a second.◦ Set alarm no. to Alarm 0.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/4

Page 54: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 162. When the alarm goes off the boss will start moving towards the main character. We'll set a

second alarm (separate from the Alarm 0) for when the boss should stop and choose a new behavior.

• Click Add Event and select Alarm → Alarm 0.

• On the Control tab, add a Test Variable action.◦ Set variable to objectMain.x.◦ Set value to x.◦ Set operation to smaller than.◦ Click OK.

• On the Move tab, add a Move Fixed action.◦ Set Direction to Left.◦ Set Speed to 5.◦ Click OK.

• On the Control tab, add an Else action.

• On the Move tab, add a Move Fixed action.◦ Set Direction to Right.◦ Set Speed to 5.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/4

Page 55: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 16• On the Main 2 tab, add a

Set Alarm action.◦ Set number of steps to 30.◦ Set alarm no. to Alarm 1.◦ Click OK.

3. When the second alarm goes off, the boss will randomly choose a new behavior. Most of the time it will choose to jump, but sometimes it will choose to throw something.

• Click Add Event and select Alarm → Alarm 1.

• On the Control tab, add a Test Chance action.◦ Set sides to 4.◦ Click OK.

• On the Main 1 tab, add a Change Instance action.◦ Set change into to objectBossAttack.

◦ Set perform events to yes.◦ Click OK.

• On the Control tab, add an Else action.

• On the Main 1 tab, add a Change Instance action.◦ Set change into to objectBossJump.

◦ Set perform events to yes.◦ Click OK.

© 2009 TechKnowHow, Inc. 3/4

Page 56: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 164. Lastly, we'll make the boss turn around when it run into a wall or U-turn marker, just like

the chasers.

• Click Add Event and select Collision → objectUTurn

• On the Move tab, add a Reverse Horizontal action.◦ Click OK.

Save your work, but don't test your game just yet. We're one step closer to seeing our boss in action. Next, we'll add the jumping behavior.

© 2009 TechKnowHow, Inc. 4/4

Page 57: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 17

Making the Boss Jump

We will now program the Boss to move as it did in the previous lesson as well as jump in the air. This will make the boss attempt to smash the main character.

1. Just like objectBoss, we'll start by adding a Create event. The boss will start moving towards the main character. In addition, we'll add gravity to the boss and make it jump in the air.

• Open objectBossJump.• Click Add Event and select Create.

• On the Control tab, add a Test Variable action.◦ Set variable to objectMain.x.◦ Set value to x.◦ Set operation to smaller than.◦ Click OK.

• On the Move tab, add a Move Fixed action.◦ Set Direction to Left.◦ Set Speed to 5.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/4

Page 58: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 17• On the Control tab, add an Else

action.• On the Move tab, add a

Move Fixed action.◦ Set Direction to Right.◦ Set Speed to 5.◦ Click OK.

• On the Move tab, add a Set Gravity action.◦ Set direction to 270.◦ Set gravity to 1.5.◦ Click OK.

• On the Move tab, add a Speed Vertical action.◦ Set vert. speed to -30.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/4

Page 59: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 172. When the boss collides with a wall, it will drop down to the ground. Then, we'll stop all it's

movement, turn off gravity, and change it back into the main boss object.

• Click Add Event and select Collision → objectPlatform.

• On the Move tab, add a Set Gravity action.◦ Set direction to 0.◦ Set gravity to 0.◦ Click OK.

• On the Move tab, add a Move Fixed action.◦ Set Direction to No Direction

by clicking the center box.◦ Set Speed to 0.◦ Click OK.

© 2009 TechKnowHow, Inc. 3/4

Page 60: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 17• On the Move tab, add a

Move to Contact action.◦ Set direction to 270◦ Set maximum to -1◦ Set against to solid objects.◦ Click OK.

• On the Main 1 tab, add a Change Instance action.◦ Set change into to objectBoss◦ Set perform events to yes.◦ Click OK.

Save your game but don't test just yet. Next, we'll make the boss throw objects at the main character.

© 2009 TechKnowHow, Inc. 4/4

Page 61: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 18

Making the Boss Throw Objects

The last behavior to add to our boss will make it throw several objects in the direction of the main character. The boss will delay a bit before it throws anything to give the player a hint of what it is about to do.

1. First, we need a sprite to represent the object the boss will throw.

• Click Create a Sprite.◦ Set the Name to spriteBossThrow.

◦ Click Load Sprite and select an object for the boss to throw. Your instructor will show you where to find the small objects library.

◦ Click OK.

2. Next, we'll add an object so we can add logic to it. We'll set the depth to 5 to make sure that this object appears from the behind the boss.

• Click Create an Object.◦ Set the Name to objectBossThrow.

◦ Set the Sprite to spriteBossThrow.

◦ Set the Depth to 5.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/5

Page 62: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 183. Now, we'll set up the boss's throwing behavior. We'll start with a create event where the boss

will decide which direction to throw. This will give the main character a chance to jump over the boss and avoid the objects.

• Open objectBossAttack.• Click Add Event and select Create.

• On the Move tab, add a Speed Horizontal action.◦ Set hor. speed to 0.◦ Select Relative.◦ Click OK.

• On the Control tab, add a Test Variable action.◦ Set variable to objectMain.x.◦ Set value to x.◦ Set operation to smaller than.◦ Click OK.

• On the Control tab, add a Set Variable action.◦ Set variable to bossDirection.◦ Set value to 180.

180 degrees points to the left.◦ Click OK.

© 2009 TechKnowHow, Inc. 2/5

Page 63: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 18• On the Control tab, add an Else

action.• On the Control tab, add a

Set Variable action.◦ Set variable to bossDirection.◦ Set value to 0.

0 degrees points to the right.◦ Click OK.

• On the Main 2 tab, add a Set Alarm action.◦ Set number of steps to 45.◦ Set alarm no. to Alarm 0.◦ Click OK.

4. When the alarm goes off, the boss will throw three objects towards the main character. These objects will all be thrown at slightly different angles to make them more difficult to avoid.

• Click Add Event and select Alarm → Alarm Alarm 0

• On the Main 1 tab, add a Create Moving action.◦ Set object to objectBossThrow.◦ Set x to 32.◦ Set y to 32.◦ Set speed to 7.◦ Set direction to bossDirection.◦ Select Relative.◦ Click OK.

© 2009 TechKnowHow, Inc. 3/5

Page 64: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 18• Right click on the Create Moving

action we just made and select Copy.

• Right click anywhere in the Actions list and select Paste.

• Again, right click anywhere in the Actions list and select Paste.

• Double click second Create Moving action to edit it.

◦ Set direction to bossDirection + 5 .

◦ Click OK.

© 2009 TechKnowHow, Inc. 4/5

Page 65: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 18• Double click the third

Create Moving action to edit it.

◦ Set direction to bossDirection - 5 .

◦ Click OK.

• On the Main 1 tab, add a Change Instance action.◦ Set change into to objectBoss◦ Set perform events to yes.◦ Click OK.

Open roomLevel2 and place your boss in the room. Make sure that your main character starts in the top left corner and the boss starts in the lower right.

Save your work and test your game. Make sure the boss runs at the main character, jumps around and throws objects towards the main character. Keep in mind that you can't hit the boss and the boss can't hit the main character. Next, we'll add health to our boss.

© 2009 TechKnowHow, Inc. 5/5

Page 66: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 19

Adding Health to the Boss

Now, we'll add health to our boss. The main character can deplete this health by hitting the boss with it's throw. When the boss's health reaches 0, the player wins and we'll show a victory screen.

1. First, we need to give the boss health by creating a variable.

• Open objectBoss.• Click Add Event and select

Other → Room Start.

• On the Control tab, add a Set Variable action.◦ Set variable to

global.bossHealth.◦ Set value to 100.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/3

Page 67: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 192. Next, we'll check every step to see if the boss has run out of health. If it has, the player wins.

• Click Add Event and select Step → Step.

• On the Control tab, add a Test Variable action.◦ Set variable to

global.bossHealth.◦ Set value to 1.◦ Set operation to smaller than.◦ Click OK.

• On the Main 1 tab, add a Next Room action.◦ Set transition to anything you

like.◦ Click OK.

• Click OK to close the Object Properties window.

© 2009 TechKnowHow, Inc. 2/3

Page 68: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 193. Next, we'll make the object that the main character throws take health from the boss.

• Open objectMainThrow.• Click Add Event and select

Collision → objectBoss.

• On the Main 1 tab, add a Destroy Instance action.◦ Click OK.

• On the Control tab, add a Set Variable action.◦ Set variable to

global.bossHealth.◦ Set value to -2. The larger this

number is, the easier is will be to defeat the boss.

◦ Select Relative.◦ Click OK.

4. Lastly, we'll add a room to go to when the player wins the game. We'll finish setting it up later, but we'll add it for now just to test the boss.

• Click Create a Room.• Click on the settings tab.

◦ Set the Name to roomEnd.

Save and test your game. Make sure that you can defeat the boss and that you are taken to the next room (even though it is currently blank). Next, we'll make the main character take damage when it is hit by the boss or it's thrown objects.

© 2009 TechKnowHow, Inc. 3/3

Page 69: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 20

Make the Boss Hit the Main Character

To finish the boss, we need to add a collision between the boss and the main character. If the main character runs into the boss, it will lose some health. We'll also do the same if it is hit by the boss's thrown objects.

1. First, we'll add a collision between the main character and the boss. It is very similar to the collision with the chaser, so we can duplicate that to get started. We'll decrease the amount of damage the boss does to the main character because the boss is harder to avoid and likely to hit the main character multiple times before it can get out of the way.

• Open objectMain.• Right click the

Collision with objectChaser1Event action we already made.

• Click Duplicate Event and select Collision → objectBoss.

• Double click on the Set Health action to edit it. It should read “Set the health relative...”◦ Set new health to -5.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/2

Page 70: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 202. Next, we'll add a collision between the main character and the boss's thrown object. We'll

increase the amount of damage it does to the main character to make the game more challenging.

• Still in objectMain, right click on the Collision with objectBoss Event we already made.

• Click Duplicate Event and select Collision → objectBossThrow.

• Double click on the Set Health action to edit it. It should read “Set the health relative...”◦ Set new health to -15.◦ Click OK.

• On the Main 1 tab, add a Destroy Instance action.◦ Under Applies to, select Other.◦ Click OK.

Save and test your game. Make sure that you can get hit by the boss and the boss's thrown objects. If you like, you can change the damage amounts to make your game easier or more challenging. The last step is to add a victory screen.

© 2009 TechKnowHow, Inc. 2/2

Page 71: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 21

Showing a Victory Screen

To finish our game, we'll add a victory screen that will display when the player defeats the boss. This screen will show a victory message, display the high score table and ask the player to play again.

1. First, we will create an object that will display the high score table after a brief pause. We'll start by setting an alarm.

• Click Create an Object.◦ Set the Name to objectEnd.

• Click Add Event and select Create.

• On the Main 2 tab, add a Set Alarm action.◦ Set number of steps to 90.◦ Set alarm no. to Alarm 0.◦ Click OK.

© 2009 TechKnowHow, Inc. 1/4

Page 72: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 212. When the alarm goes off, we'll show the high score table and then ask the player to play

again.

• Click Add Event and select Alarm → Alarm 0.

• On the Score tab, add a Show Highscore action.◦ Click OK.

• On the Control tab, add a Test Question action.◦ Set question to Do you w ant to

play again?◦ Click OK.

• On the Main 2 tab, add a Restart Game action.

• On the Control tab, add an Else action.

• On the Main 2 tab, add an End Game action.

• Click OK to close the Object Properties window.

© 2009 TechKnowHow, Inc. 2/4

Page 73: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 213. Next, we'll make the victory background to display on the screen. We'll load a background

and then edit it with text just like we did with the title screen.

• Click Create a Background.

◦ Set the Name to backgroundWin.◦ Click Load Background and

select any background you like.◦ Click Edit Background.

◦ On the top menu bar, select Text → Font...

◦ Choose any Font that you like.◦ Set the Size to anything between

24 to 72.◦ Click OK.

◦ Select a color from the palette on the right side of the screen.

◦ Click the Draw Text tool.

◦ Click anywhere on the image and type a message like You win! or Good job!

◦ Position your text anywhere you like.

◦ Continue to edit the image as you like.

◦ Click the Green Check when you're happy with your image.

• Click OK.

© 2009 TechKnowHow, Inc. 3/4

Page 74: 2D Platform - campbell.teachur.comcampbell.teachur.com/GameMaker/2DPlatformLessons_GSpark.pdf · In Game Maker, directions are in degrees. 270 is down. Set gravity to 1.5. Click OK.

2D Platform L 214. Lastly, we'll set up the room to display our background and place objectEnd in the room.

• Open roomEnd.◦ Click on the backgrounds tab.◦ Click on <no background> and

select backgroundTitle.◦ Click on the objects tab.◦ Place objectEnd anywhere in

the room.

Save and test your game. Make sure that you see the victory screen after you defeat the boss. Make sure you the high score table shows and you are given the option to play again. Congratulations, you've just finished your own platform game.

© 2009 TechKnowHow, Inc. 4/4