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.