Category Archives: Level 04

Level 04 Lessons

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