All posts by Atomic Toddler

Level 03 Intro

‘Create, change, and check.  The three C’s of variables.’

This level is all about giving your games the power to create, change, and check game variables.  Variables like score, user name, hit points, items collected, best time, enemies defeated, which item they have selected, current stage number, energy levels – you get the point!

After creating a variable you will most likely change it’s value and then check it’s value.  For example, after creating a variable to keep track of the player’s score you might increase the players score and then check to see if the player has reached a million points.  If they have reached a million points, you do something awesome.

Enough talking, lets get started!

Level 03 Lesson 01 [Intro to Variables]

Lets start learning how you can use variables in your programs.

Resources You Will Use
It’s Level 03 now, so remember to look for sprites, sounds, and other resources in the Lv03 resource folder.

Part A – Creating and Changing Instance Variables
To save time, a pre-made game project has been made that will help us learn about variables. Go the resources projects folder and open the game project called L03-01-StartHere.gmk .

Watch the video:  03-01-A
Done File: L03-01-A-Done.gmk


Challenge 1– Add the Following
Here are few programming tasks to add.

a) Give the player a new variable called money. When the player collides with a coin, add one to the player’s money and destroy the coin. Use a show message to confirm it is working!

b) Since the player can gain points, lets make a way for the player to lose points. Add the code so that when an arrow hits a wall (misses a ghost) the player loses 2 points. Use a show message to confirm it is working.

Challenge 1 Solution
Solution video: 03-01-X1Solution
Solution file: L03-01-X1-Done.gmk


Part B – Drawing Variables
Continue with the file you are working on.
Watch the video: 03-01-B
Done File: L03-01-B-Done.gmk

Challenge 2– Add the Following
This challenge will have a few more tasks to code so that you can get confident with the basic use of instance variables.

a) When a player picks up gold, add 10 to their money. Remember to destroy the gold. Play sound pickup.

b) Give the player a variable called life. It should start at 100. Use the draw object to draw this variable to the screen.
When the player touches the poison object they should lose 1 life but don’t destroy the poison! Watch how fast life goes down when they player touches the poison.

c) Eating apples will give the player 25 more life.

d) Touching the blue potion will bring you to 100 life instantly.

e) Code this in the WALL object. When the wall collides with the player, lower the player life by one.

Challenge 2 Solution
Solution video: 03-01-X2Solution
Solution file: L03-01-X2-Done.gmk

 

Level 03 Lesson 02 [Variables and Conditions]

Variables are great for remembering values. But the real power of variables is being able to ask questions about their values, and depending on these values, perform different blocks of code. This lesson will introduce you to the power of simple conditional statements.

Part A – Watch!
We’ll continue working on the variable game project from the last lesson. Open the completed Challenge 02 from last lesson,
L03-01-X2-Done.gmk .

Watch the video:  03-02-A
Done File: L03-02-A-Done.gmk
(give player life amount, give wall life amount)

Watch the video:  03-02-B
Done File: L03-02-B-Done.gmk
(player needs money to fire)

Watch the video: 03-02-C
Done File: L03-02-C-Done.gmk
(limit life to 100)


Watch the video: 03-02-D
Done File: L03-02-D-Done.gmk
(potion increases life but has limited number of times it can be used)


Challenge 1– Add the Following
Here is a chance to try your hand at some variable related tasks.  But before you start, change the player’s create event code so that the player starts with money=1000.  This will make the game easier to test since the player won’t run out of life so quickly.

a) Give ghosts life so that they need to be hit 2 times before they are destroyed.
b) If the player picks up 6 coins then show a message box saying that you got all the coins.
c) a ghost will keep track of how many times they have bounced off of a wall.  If they bounce off a wall 5 times then they change direction to move left.  Weird, but just do it.
d) if the player destroys 3 ghosts then display a message saying “Next Level” and end the game.

Challenge 1 Solution
Solution Video: 03-02-X1Solution
Solution File: L03-02-X1-Done.gmk

Level 03 Lesson 03 [Random Values]

Every programming language has commands that allow us to generate random numbers.  Random numbers can be used along with conditional statements to give games more variety.  This lesson will give you an introduction to how you can start using random values with conditions.

Part A – Setting Variables to Random Values
To save time, a pre-made game project has been made that will help us learn about random values and variables. Go the resources folder and open the game project called L03-03-A-StartHere.gmk

Watch the video: 03-03-A
Done File: L03-03-A-Done.gmk


Challenge 1 – Random in Step Event
Continue using the project you have open and try and complete the following.

a)  In the step event of the banana, pick a random number between 0 and 30.  If the number is a 1, change the direction of the banana to a random value between 0 and 359. If successful, this will have the banana changing directions every second or so.

b) In the step event of the burger, add onto the existing code. Pick a number between 0 and 1000. If the number is 10 or less, set the x and y variables of the burger to new, random values (the values should be between 0 and 400 (the size of the room) ). You should see the burger ‘jump’ to a new position in the room every 3 seconds or so if you complete this properly.

Challenge 1 Solution
Watch the Video: 03-03-X1Solution
Solution File: L03-03-X1-Done.gmk


Part B – Random Values, Random Actions
To save time, a pre-made game project has been made. Go the resources folder and open the game project
called L03-03-B-StartHere.gmk

Watch the video: 03-03-B
Done File: L03-03-B-Done.gmk


Challenge 2 – Random Generation

Use the done file from the last video, L03-03-B-Done.gmk.  Lets add three new things to add to the game.

a) When you press the “M” key, make the player randomly decide whether to start moving up, down, left, or right at a speed of 4.

b) When the player touches the chest, destroy the chest and randomly decide whether to create a coin or some gold at that location.  Code it so that the chance of a coin appearing is greater than the chance of some gold appearing.

c) When the ghost is hit by an arrow, there is a 1/5th chance that the ghost is destroyed (that’s a 20% chance).

Challenge 2 Solution
Watch the Video: 03-03-X2Solution
Solution File: L03-03-X2-Done.gmk

Level 04 Intro

‘Practice does not make perfect.  Only perfect practice makes perfect.’   – Vince Lombardi

So you’ve learned a good handful of basics and you are ready to show off.  Here’s your chance.  This level is purely about practicing what you’ve learned.  You will build up two of the projects you already have started: The Two Player Game and Get The Ghosts.

You will be asked to make a series of modifications to your existing projects.  These mods are a great opportunity to practice the concepts  taught in the course.   You should work through all the modifications since each one has been selected to review a particular concept.

The mods will start easy and finish off a little more challenging.  Don’t worry if you get stuck along the way; there are video solutions for all the modifications.  Do, however, give your BEST effort to solve the challenge problem on your own before you check the solutions.

Are you worthy to proceed to Level 05?  Get started and find out!

Level 04 Lesson 01 [Modify Get the Ghosts]

It’s time to practice the concepts taught in the course so far.  To do this you will code a bunch of features and modifications into the Get The Ghosts project that you cloned in an earlier lesson.

You should work through all the modifications since each one has been selected to review a particular concept.  The mods will start easy and finish off a little more challenging.  Don’t worry if you get stuck along the way; there are video and code solutions for all the modifications.  Do, however, give your BEST effort to solve the problems on your own before you check the solutions.  That’s how you get better at coding!

There is no instructional video for this lesson, just a long list of challenges.

Huge Challenge 1 – Modify Get The Ghosts

You can start with this project:
L04-01-X1-GetTheGhostsStart.gmk

To see all the modifications in action, you can run the completed projected (but no peeking at the code!) or the application provided:
L04-01-X1-GetTheGhostsDone.gmk
L04-01-X1-GetTheGhostsDone.exe

Don’t skip modifications since some of them build upon each other!
These modifications are solved in the first solution video.

** The time at which the mod is solve in the video is provided so you can jump to particular solutions quickly.  The time given is about 10 seconds ahead of the solution so you don’t miss the start **

a) Give the player two new variables, life and points. Set the life to 100 and the points to 0. (solved at 0:00)

b) Draw these two variables somewhere in the room. Since the room has a black background, you won’t see the variables being drawn out unless you switch to a different drawing color. To do this, make the first line in the Draw Event draw_set_color(c_white) and you will be drawing in white. Follow this line with your normal draw code. (solved at 0:47)

c) Give the ghosts a variable called life and set it to 2 and change the existing code so that the ghost will have to get hit twice before it is destroyed. (solved at 4:14).

d) Give the player 5 points every time they hit the ghost with their laser. (solved at 6:25)

e) Add this section of code to the event Ghost collides with Wall.
direction = direction + 180
It will make the ghost appear to bounce off of walls when the collide with walls once we get them moving. (Solved at 7:48)

f) Make the boss randomly produce a ghost every few seconds. The ghost that is made should be moving to the right. (Solved at 8:47)

These modifications are solved in the second solution video.

g) Make a new object called laserred and get the ghosts to fire, every second or two, red lasers at an angle of 260-280 degrees every second or two. Remember to set the image_angle of the laser so it looks correct in the game. (Solved at 0:00)

h) Since there are no walls located along the bottom of the screen, red lasers just keep on going and going. We need to destroy them when they leave the room. There is an event called Other->Outside Room that is called when an object leaves the room. Add an instance destroy method inside this event for the red laser. (Solved at 3:30)

i) When the player gets hit by the red laser, destroy the laser and reduce the player’s life by 10. (Solved at 4:54)

j) Just after you take 10 off the player’s life, check to see if the player’s life is below or equal to 0. If it is, show the message, “Game Over! Click to Restart!” and then use the line game_restart() to have the game restart itself. (Solved at 6:20)

k) Create a new object called healthpack. When the player collects a health pack it should be destroyed and the player should get +25 onto their life and make sure that the player’s life doesn’t go over 100. Add a health pack or two neaer the player to test it out. (Solved at 8:05)

l) Last modification! When a ghost is destroyed, there should be a 1 in 10 chance that it drops a health pack downward. If a health pack goes outside the room, it should destroy itself. (Solved at 11:15)

Huge Challenge 1 Solution
The solution is split into 2 videos
Solution Video #1:   04-01-X1Solution1
Solution Video #2:   04-01-X1Solution2
Solution File:  L04-01-X1-GetTheGhostsDone.gmk

And a few people asked about how the background music is started properly in the game (did you notice the problem?), so here’s a quick video about that…
Solution Video #3:  04-01-X1Solution3MusicFix

Level 04 Lesson 02 [Modify Two Player Game]

Lets go back to our Two Player Game that you were working on earlier and try a few modifications.  You should work through all the mods since each one has been selected to review a particular concept.

The mods will start easy and finish off a little more challenging.  Don’t worry if you get stuck along the way; there are video and code solutions for all the modifications.  Do, however, give your BEST effort to solve the problems on your own before you check the solutions.  That’s how you get better at coding!

There is no instructional video for this lesson, just a long list of challenges.

Challenge 1 – Improve the Two Player Game
You can start with this file,
L04-02-X1-TwoPlayerGameStart.gmk

Before you read all the modifications below, run the project
L04-02-X1-TwoPlayerGameDone.gmk
or run the application
L04-02-X1-TwoPlayerGameDone.exe

and observe/analyze the game. What modifications and features have been added to your previous version of this game?  Try to observe and program the modifications you found.  If you think you spotted and coded all of the mods, check the list below and see how well you did!  If you missed one, read the mod and code it.

These modifications are solved in Solution Video #1:

a) Give each players a variable called hp and set it to 100. Draw each players hp on the screen. (Solved at 0:00)

b) When player 1 gets hit by player 2’s ball, decrease player 1’s life by 25. Repeat for the player 2 object. (Solved at 3:20)

c) Right now the players are jumped back to their starting position when they are hit by a ball. Change this behaviour so that the players don’t jump back unless the their hit point variable reaches 0 or below. Also remember to set the player’s hit points back to 100 after they jump back so that they can continue battling. (Solved at 4:25)

These modifications are solved in the Solution Video #2:

d) Give each player a new variable called ammo and set it to 10.  (Solved at 0:00)

e) When the player presses the key to fire, check to make sure that they have some ammo (more than zero!). If they do, let them fire and decrease the ammo by one. Draw both players ammo values to the screen. (Solved at 0:35)

f) Make a new object called ammobox . When a player collects an ammo box, their ammo will increase by 10.  Place a few in the room and test. (Solved at 4:00)

g) Go back to where you jump the players (after they run out of hp). Make the ammo variable reset back to 10 when players are jumped. (Solved at 6:20)

h) Make a new object called producer. A producer doesn’t need a sprite, it will sit in the room invisible. A producer will randomly fire out ammo boxes, in any direction, every couple of seconds. Place a single producer in the middle of the room. (Solved at 7:30)

i) Make sure that ammo boxes will stop when they hit walls. (Solved at 9:53)

Challenge 1 Solution
The solution is split into 2 videos
Solution Video #1:  04-02-X1Solution1
Solution Video #2:  04-02-X1Solution2

Done File: L04-01-X1-TwoPlayerGameDone.gmk

 

Level 05 Intro

Congratulations on making it this far in the course and surviving all those modifications in Level 04.  Now you are ready for Level 05.

In this level we will introduce you to a few new concepts that you will find very useful in any game or program that you decide to create.  We will explore timing, introduce a new type of variable, and learn how to create more powerful conditions.

Get watching and coding!

Level 05 Lesson 01 [Timing Things with Counters and Alarms]

In the previous lesson/s you used random numbers in the step event to make objects perform tasks at random times. But sometimes you want an object to perform a task at specific time intervals. This lesson will cover two popular methods for making objects ‘time’ their actions.

Part A – Using Counters
Watch the video:  05-01-A
Donefile:  L05-01-A-Done.gmk


Challenge 1– Redo the Video without watching

Grab the pre-made starting file
L05-01-StartHere.gmk

Re-add the these three tasks that were showing in the lesson video. If you have trouble, re-watch the video.

a) paddle will fire a ball every one second
b) player is limited to firing every 15 steps
c) bomb will explode 2 seconds after it is created

Challenge 1 Solution
Solution: Watch the video again! These tasks are very commonly used, and very useful to know. Practice until you can do it without using the video for help.


Part B – Using Alarms
Watch the video:  05-01-B
Donefile: L05-01-B-Done


Challenge 2 – Alarm Tasks

Continue adding to the file from the end of the video lesson
L05-01-B-Done.gmk

Add the following using alarms:

a) make a ball add 30 degrees to its direction every 15 steps. This should make it move in a circle-ish (not a real word) shape.  Use the line direction = direction + 30  to make the ball’s direction change.

b) After the old man presses the “D” key, he will self destruct in 3 seconds.

c) Make it so that the left and right arrow keys make the man move at a speed of 1 to the left and right. Now limit the use of the keys so that they can only be used after waiting 3 seconds. For example: if the user presses the right arrow key, they will start to move right BUT the arrow keys will not work again until 3 seconds has past. Run the completed project if you’re not sure you understand!

Challenge 2 Solution
Solution Video: 05-01-X2Solution
Solution File: L05-01-X2-Done.gmk


Challenge 3 – Repeat with Counters

Remember those last three tasks you did with alarms? Repeat them with counters instead. Task two (the destruction of the man) might be trickier than you think, be creative! So open up
L05-01-B-Done2.gmk
and see if you can repeat these tasks using counters (no alarms!).

Challenge 3 Solution
Solution Video: 05-01-X3Solution
Solution File: L05-01-X3-Done.gmk

 

Level 05 Lesson 02 [Global vs Instance Variables]

We’ve been making good use of variables in the past few lessons. The variables we have been using are called instance variables because each instance (object you create in the game) keeps the variable inside of itself. There are other types of variables in programming. One type is a global variable. Global variables are not owned by any individual object. They are owned by the entire game and any object is able to make them, change them, or check them. This lesson will introduce you to global variables and describe when using a global variable is better than using an instance variable.

Part A – Global Variables, Why we need them.
Watch the video: 05-02-A


Part B – Using Global Variables to replace common values
Watch the video: 05-02-B
Donefile: L05-02-B-Done.gmk


Challenge 1– Add some more Global variables
Continue with the project from the videos
L05-02-B-Done.gmk
and complete the following tasks:

a) make a global variable to keep track of what level the player is currently on. The first room is level 1. When the player touches the door and advances to the next room, increase the level variable by one.  Also draw this variable to the screen.

b) make a global variable to keep track of the number of times the player has hit a ghost with a laser. Increase this variable when ghosts get hit by lasers. Draw to screen.

c) make a global variable that will keep track of how fast the player laser will move when created.  Set the value of the global variable to 8 (this is the current speed of lasers).  When the player creates a laser you should set the speed of the laser to  this global variable (not the number 8). Now add the code so that when the player has earned 5 ghost hits, the global laser speed will change to 12.  When testing you should see the laser speed increase after the player has 5 ghost hits!

Challenge 1 Solution
Solution Video: 05-02-X1Solution
Solution File: L05-02-X1-Done.gmk