This week’s project builds upon the sketch from last week. Before starting this project make sure you have completed all steps from last week and tested your game thoroughly.
Create a copy of your sketch directory from last week and rename it to
something like game-project-6
. Keep your completed project from last
week safe as a reference, and make the following changes to the code
in your new game directory.
-
Add a score counter [1 marks]
- create a global variable called
game_score
- increment
game_score
by one each time the character collects an item. - use the text function to draw the score on the screen.
- create a global variable called
-
Add a flagpole [1 marks]
- We need to add an end to your level. I have chosen a flagpole but you can chose according to the theme of your game.
- Initialise an object called
flagpole
, it should at least have the propertiesx_pos
andisReached
. - set
isReached
tofalse
andx_pos
to a world position at the very end of your level. - create a function called
renderFlagpole
and call this from the draw function - complete the function to draw your flagpole in two states. One for when
isReached
is false, and one for when it istrue
-
Flagpole checking function [1 marks]
- create a function called
checkFlagpole
- call the function from
draw
, but write a conditional so thatcheckFlagpole
is only called whenflagpole.isReached
isfalse
- in
checkFlagpole
write a conditional such that when the gameChar is in range of the flagpole itsisReached
property is set totrue
- create a function called
-
Add lives [2 marks]
- Your character should begin with three lives, and each time they fall down a canyon the game should reset and their remaining lives decrement by one.
- Create a global variable
lives
, and initialise it to3
withinsetup
. - Create a function called
checkPlayerDie
. Call this within draw. - In this function define a conditional statement that tests if your character has fallen below
the bottom of the canvas. When this is
true
, decrement thelives
counter by one - Create a new function called
startGame()
. - Move everything from
setup
exceptcreateCanvas
and the initialisation offloorPos_y
andlives
into this new function. - At the end of your now very short
setup
function callstartGame()
. - In
checkPlayerDie
create a conditional statement to test if the player has used all of their lives. If there are lives remaining callstartGame
. - Write some code using a
for
loop to draw life tokens onto the screen so that you can keep track of how many lives you have remaining.
-
"Game over" and "Level complete" text [2 marks]
- In the draw loop, after your drawing code and before your game logic code, write two conditional statements
- The first displays "Game over. Press space to continue."
when
lives
is less than 1. - The other displays "Level complete. Press space to continue." when
flagpole.isReached
is true - For each conditional you should return at the end of the statement. This prevents any further game logic from happening when play is over.
- Tidy your code [3 marks]
- make sure your code is elegant
- remove all commented blocks of code
- check all indentations
- make your variable names consistent
- remove any redundant code
- refactor unwieldy drawing code
- break up long commands onto multiple lines