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