All posts by Atomic Toddler

Level 05 Lesson 03 [Better Conditions]

In the past several lessons we have used simple if statements to check the values of variables to help us decide whether or not to execute some code. While these simple conditions work well, sometimes you need slightly more complicated conditions in your code. In this lesson we will take a look at some of the extra options you have when asking “if”.

Part A – Reading and Questions Time!
This is one of the rare topics in this course where reading some notes and answering some concepts questions will help you quite a bit. The notes,concept questions, and solutions are bundled into one file for you.

Read the Notes: L05-03-Reading01.pdf
Contains
1) Basic Operators
2) Using AND and OR
3) Using if, else if, else

Watch the video: 05-03-A
(reviews the reading notes)

Try the Concept Questions: L05-03-ConceptQuestions01.pdf
Check your answers are at the end of the question file!


Part B – Coding Challenges

These five coding challenges come with videos explaining what to do. Watch the video and then use the pre-made starting game project to complete the challenge. Good luck!

Challenge 01 – Fire Toggle and Ammo
Start with this project: L05-03-StartHereA.gmk
Video Preview this challenge:  05-03-X1Preview

When the player presses the T key, this should toggle the value of the variable selected from 1 to 2 to 1 to 2 and so on. Once this is working, change the draw method so that it shows ROCK when selected is equal to 1 and ARROW when selected is equal to 2. Once this is working, the player should fire the appropriate item, a rock or an arrow. Once this is working, make sure that the player can only fire the selected item if they have enough of those items (the variables rock and arrows are already made).

Solution Video: 05-03-X1Solution
Donefile: L05-03-X1-Done.gmk

 

Challenge 02 – Keys and Locks
Start with this project: L05-03-StartHereB.gmk
Video Preview this challenge: 05-03-X2Preview

The player can open the chest if they have collected either of the keys. To open the chest, use the code with obj_chest { sprite_index = spr_chestOpen } . This will change the sprite of the chest to an open chest graphic.

The player can destroy the red lock only if they have collected the gold and silver key. Having just one key won’t don’t it!

The player can destroy the door if the player has either of the keys and has collected all 5 coins that are in the room.

Solution Video: 05-03-X2Solution
Donefile: L05-03-X2-Done.gmk


Challenge 03 – Target Points

Start with this project: L05-03-StartHereC.gmk
Video Preview this challenge: 05-03-X3Preview

The player has a points variable. When the player has between 0-9 points, show “Noob” on the screen. When they have between 10-19 points show “Not Bad”. When between 20-29 show “Good”, and 30 and higher show “Awesome!”.

Once this is working, make it so that a pear, cherry, or strawberry is produced from the target when the target is hit from an arrow. Set the odds to 10% chance of pear being produced, 30% chance of cherry being produced, and 60% chance of strawberry being produced. When you test your program, make sure that these approximate odds are working!

Solution Video: 05-03-X3Solution
Done-File: L05-03-X3-Done.gmk


Challenge 04 – Color Squares

Start with this project:  L05-03-StartHereD.gmk
There is a demo video of this challenge: 05-03-X4Preview

When you detect that the player is in different areas of the screen, write the following test on the screen using the draw object provided. Draw each line at a slightly different height so that when two are showing up they don’t overlap.

In the blue areas on the left: “Blue Side”
In the large top right square: “Top Right”
In the gray area: “Gray Part”
In the tiny center square: “Center!”
In any of the four large corners: “Corner!”

Solution Video: 05-03-X4Solution
Donefile: L05-03-X4-Done.gmk


Challenge 05 – Cycling

Start with this project: L05-03-StartHereE.gmk
Video Preview this challenge: 05-03-X5Preview

The player has a variable called item. Pretend the player has 5 different items to cycle through. When they press the right arrow, add 1 to item. But if the value of item goes past 5 you should put it back to 1. When the press the left arrow key cycle down by subtracting 1 from item. If the item variable goes below 1 then bring it to 5. As you continuously press an arrow key, you should be cycling through the item values.

When this is working, add some code inside the draw event so that you show the actual names of the items.

Solution Video: 05-03-X5Solution
Done-File: L05-03-X5-Done.gmk


That was a long one.  Go grab a snack.
See you in Level 06 where we’ll take a look at a few concepts involved in sprites and animations.

Level 06 Intro

‘Sprites are in the eye of the beholder’ – unknown

An important aspect of any game is the graphics.  Everyone that has played a video game knows that an object sprite can change as the object performs different actions.  Think about a player that is walking, running, jumping, attacking, defending, and so on; the sprite for the player changes – if it didn’t, the game would look quite boring.

In this level, we are going to teach you a little more about how to control your game sprites using your own variables and some variables that are already built into GameMaker.  We will also look at how to import sprites and sprite sheets that other people have created so that you don’t have to spend hundreds of hours drawing all your own graphics for your homebrew games.

Level 06 Lesson 01 [Sprites and Images]

Graphics are important part of any video game. In this lesson we’re going to learn how to do some basic sprite tasks that will give you more control over how a sprite behaves on screen. You will definitely use what you learn today in your own games.

Part A – Common Sprite and Image Options
Watch the video: 06-01-A
Watch the video: 06-01-A2
Done File: L06-01-AB-Done.gmk


Challenge 1 – Using Sprite Index

Add on to this project:   06-01-AB-Done.gmk.
Add the up and down direction to the player with the appropriate animated sprites.

Add a chest object into the room. When the player touches the chest object, it should change to an open chest sprite. If the player touches the chest again, it should change to a closed chest again. Now here’s the problem: if the player stands on top of the chest, the chest will rapidly open and close and you won’t even be able to see the changing sprites take place. Solution: Use an alarm on the chest so that it can only be opened/closed every 3 seconds. This is a nice challenge that reviews alarms! Check the solution file or video if this one stumps you.

Challenge 1 Solution
Watch the Video: 06-01-X1Solution
Donefile: L06-01-X1-Done.gmk


Challenge 2 – Growing Health
Modify the health object so that it grows bigger quickly until it is twice its normal size. Then it returns to it’s original size and the pattern repeats forever.

Now try to modify this even more! Make it so that this effect doesn’t start happening until the user clicks the health pack. So before the user clicks the health pack, it just sits there with one size. Then after clicked it starts to do size change effect on the sprite over and over. Hint: an extra variable and and an if statement will help.

Challenge 2 Solution
Solution Video: 06-01-X2Solution
Solution File: L06-01-X2-Done.gmk

 

Level 06 Lesson 02 [Sprite Sheets Editor]

So you think you can draw? In this lesson we will open up the sprite editor built into GameMaker and make our own animated sprites. If you are like me, however, you would rather just download some free graphics from the Internet.  We will also learn how to use the sprite editor to create animated sprites from sprite sheets that you can find online.

Part A – Very Basics of the Sprite Editor
Watch the video: 06-02-A
Donefile: L06-02-A-Done.gmk

Challenge 1 – Draw Something!
Take a few minutes and draw your own sprite. You don’t have to make it a masterpiece. Maybe a ghost from Pacman, a space invader, or a really good stick figure trying to run. Test it out in your game. No video solution to this one.


Part B – Using Sprite Sheets
Watch the video: 06-02-B
Donefile: L06-02-B-Done.gmk


Challenge 2 – Street Fighter

Start with the pre-made game project
L06-02-X2-StartHere.gmk
Watch the Preview Video:  L06-02-X2Preview

In the Level 06 Resource folder there is a nice sprite sheet for Ken, one of the main characters for the famous game Street Fighter. Use this sprite sheet to create the sprites for the following:

spr_fire, spr_standing, spr_punch, spr_kick, spr_crouch

Each animated sprite uses one row of the sprite sheet. The individual sprite squares are all 80 pixels X 80 pixels (easy sheet to work with).

After you have the 5 animated sprites, use the standing sprite and the kicking sprite and your own code to imitate the behaviour shown in the preview video.

Challenge 2 Solution
Solution Video: 06-02-X2Solution
Solution File: L06-02-X2-Done.gmk

Level 06 Lesson 03 [Advanced Sprite Control]

Now that you know how to switch sprites around you have to learn how to plan and control the various sprite animations that you might assign to an object. In this lesson we will develop Ken, our supreme Street Fighter so his behaviour is more like the real Ken in the arcade. It will be an excellent review of conditions and variables mixed with sprite control.

Part A –Image Index
When animated sprites are playing, a variable called image_index is keeping track of which frame the animation is on. If the current image index is 4, and you switch to another sprite, you will switch sprites and still be on frame 4. This can have weird effects because if you switch to another sprite it will continue animating from frame 4 (and not the first frame, frame 0). Usually you will want to set the image index back to 0 when you switch sprites.

Watch the video: 06-03-A

 

Part B – Controlling Actions / Sprites
We are going to build on our street fighter so that we can control the way he fires, punches, kicks, crouches, and stands. It will require a combination of variables, well thought out conditions, and good sprite control.

Watch the video: 06-03-B
Done-File: L06-03-B-Done.gmk


Challenge 01 – Punch and Crouch
Start with the pre-made game project:
L06-03-X1-StartHere.gmk

So far you have Ken standing, kicking, and firing. Time for you to add the punch and crouch. Notice that crouching is a little different then the other actions. The player doesn’t press a key once to crouch, they hold down a key to crouch (so use keyboard event, not key press).

Challenge Solution
Watch the video: 06-03-X1Solution
Done-File: L06-03-X1-Done.gmk


Challenge 02 – All on Your Own

It might have been easy to add in punching and crouching when the kicking and firing are already in the file. Delete all your code and try to get all 5 moves working from a fresh file without following the videos! Re-watch the lesson video if you have trouble getting this working.


Challenge 03 – Getting Hit

Start with the pre-made project
L06-03-X3-StartHere.gmk
Watch the Preview Video: 06-03-X3Preview

Now that we have Ken making his moves properly, lets wrap up this project file with Ken getting hit by fire objects that are fired at him.
Notice the object called globs that creates a global hit point variable for Ken.
The globs object is also drawing the hit points to the screen.
There is also a tower object that is firing fire at Ken.

Now try and add the following behaviour:
If Ken is crouched, he won’t take damage. If Ken is firing he will take double damage (10 points). Any other position is normal damage (5 points).
Add an explosion object when Ken gets hit. The explosion sprite sheet is in the Level 06 resource folder. The explosion object should destroy itself when it’s animation is over.

Challenge Solution
Solution Video:  06-03-X3Solution
Done-File: L06-03-X3-Done.gmk

Level 06 Lesson 04 [Drawing Sprites in Draw Events]

So far we have drawn the value of variables to the screen using objects that we add to the room (the draw object). We have also changed an object’s sprite using the sprite_index variable. In this lesson we will explore another way of drawing variables and sprites to the screen.

Part A – More About the Draw Event
We have left the draw event blank for most of our game objects. Blank draw events, by default, will draw the object’s sprite for you automatically. Sometimes, however, it is good to code an objects draw event to draw variables and sprites out.   Check out these examples.

Watch the video: 06-04-A
Watch the video: 06-04-B
Done-File: 06-04-A-Done.gmk


Challenge 01 – Draw Potion Life

Open the project 06-04-A-Done.gmk.
Try changing the way that the health potion is drawn out.
Use the draw event of the potion to draw out the sprite for the potion and also the amount of the potion that is left.

Challenge Solution
Solution Video:  06-04-X1-Solution
Solution File: 06-04-X1-Done.gmk

 

Part B – Draw Sprite Extended
Sometimes you need your sprite to be drawn using some extra properties like image_angle, alpha transparency, and scaling. For this you have to use the draw_sprite_ext method. Check out the video

Watch the video: 06-04-C
Done_File: L06-04-C-Done.gmk


Challege 02 – Fading Lasers

Start with the pre-made game project:
L06-04-X2-StartHere.gmk
Watch the Preview Video:
06-04-X2Preview    (sound is messed up, will fix one day…)

You’ll notice that the boss and the laser fire at angles and everything works alright. Here’s what we want to add: Give the lasers an instance variable called strength and set it to 1.0 when they are created. In the step event, make the strength variable decrease by 0.02 (yes, just a little). If the strength variable gets to zero or below, destroy the laser. Test this out.

Now add the draw event to the laser object. Inside of it, use the draw_sprite_ext method to draw the sprite out at the proper angle, scaling, etc.  BUT when it comes time to fill in the alpha parameter, use the strength variable. Since the strength variable is constantly decreasing, the drawn sprite’s alpha will decrease (fade out).

Solution Video: 06-04-X2Solution
Solution File: L06-04-X2-Done.gmk

 

Level 07 Intro

Level 07 is a short level that will introduce you to scripts. Scripts are also called methods and functions in other programming languages. They will definitely make your programming life easier so get to it and start the first lesson.

Level 07 Lesson 01 [Using Scripts/Methods]

This lesson is about using scripts/methods. Methods are named chunks of code that might perform a task, send you back some values, or both. You can use methods that have been written by other programmers and you can use methods that you have written. Methods can save you coding time, make your code easier to read, and help you organize your code. GameMaker has many methods that have already been written for you to use so lets take a look at some examples.
Part A – Introduction to Methods
Watch the video: 07-01-A

Challenge 1– Find, Use, and Test
Use the project 07-01-X1Start.

Add extra key press events into the player object and try out using some of the following methods. Read about the methods in the help file to find out more about them.

a) when the player presses ‘R’ use the random method to generate a number and show it with a message.
b) when the player presses ‘M’ use the motion_add method and see what happens.
c) when the player presses ‘E’ use the position_empty method and check if x=112, y=208 is empty or not (it has a hamburger so it shouldn’t be!) . If it is empty, show a message saying empty.
d) when the player presses the ‘D’ key, use the point_direction method to find out the direction toward the upper left corner ( x=0, y=0 ). Once you know this direction, fire an arrow toward this direction.
e) when the player presses the ‘C’ key, use the point_in_circle method to see if the player is within a 100 pixel radius circle that is positioned in the center of the room. The room is 800X600 so the center of the room is at (400,300). If the player is at the center of the room, make their points go up by 1000.

Challenge 1 Solution
Solution Video: 07-01-X1
Solution File: 07-01-X1Done.gmk

Level 07 Lesson 02 [id’s as Return Values]

In the last lesson you learned that some methods will return values back to you. Sometimes those values can be the ID’s of other game objects. When you know the ID of a game object you have the power to control it or interact with it. Confusing? Just watch the video!

Part A – ID’s as Return Values
Watch the video: 07-02-A

Challenge 1 – Stop Far Ghost
Use: 07-02-X1Start

a) when the player presses F, find the ghost object that is furthest from the player using the instance_furthest method. Make this ghost stop moving.

Challenge 1 Solution
Solution Video: 07-02-X1
Solution File: 07-02-X1Done.gmk

Part B – More About Using ID Values
Watch the video: 07-02-B

Challenge 2 – Run Away Walls
Use: 07-02-X2Start

a) the Step event occurs 30 times a second by default. Add this code into the Step Event of the player. Find the id of the nearest wall. Then find out how far away this wall is using the point_distance method. If the wall is within 100 pixels of the player, make the wall move away from the player at a speed of 2 (hint: away from the player is the direction from the player to the wall object!).

Challenge 2 Solution
Solution Video: 07-02-X2
Solution File: 07-02-X2Done.gmk