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