The Roaming Ghost
Fix a spooky game where you collect items while avoiding a ghost.
Remix the project
Goal:
Make a copy of the project for today's lesson
Click the
LINK
to remix the project.
Fix the "when run" block
Goal:
Fix the "When run" block so that it will initialize the game environment, player, and title screen.
The "When run" block is broken, look at the image and see what needs to be fixed.
Tip:
Make sure to select the correct background image.
Check:
Did you see the title screen when you run the code?
Fix the createGameMap function
Goal:
Fix the 'createGameMap' function so that it will set the background and create collectible items.
Look at the image and see what needs to be fixed.
Check:
Does your function have all the sprite setup blocks, background setup, and collectible item creation inside?
Fix the createHero function
Goal:
Fix the 'createGameMap' function so that it will set the background and create collectible items.
Make sure to set the hero to the correct size.
Fix the moving with keys behaviour.
Add the "edges block from moving" to the top of the behaviour.
Add the "if block" to prevent the hero from walking through the walls; Add it to all the directions, up, down, left, and right.
Check:
Does your hero move correctly with the arrow keys and does not walk through the walls?
Fix the startGame function
Goal:
Fix the 'startGame' function so that it will set the background and create the hero.
The createStartGame seems to be missing some blocks.
Look for the 'createGameMap' and 'createHero' functions and add them inside the 'startGame' function.
Look at the image and fix the broken parts of the 'startGame' function.
Tip:
You can find the 'function' blocks in the Functions category.
Check:
Does your startGame function have all the sprite setup blocks inside?
Fix the when "Space" pressed event
Goal:
Add a 'when space pressed' block to call the 'startGame' function.
The when space pressed event is missing.
Add a 'when space pressed' block to call the 'startGame' function.
Check:
Does the game start when you press the space key?
Fix the win game function
Goal:
Create the win game function.
Look at the image and fix the broken parts of the 'winGame' function.
Tip:
Play around with different background images for your win screen!
Check:
Does the win screen appear when you win?
Fix the Timer logic
Goal:
Fix the timer logic.
The timer logic is broken. Fix it so the timer counts down by 1 every second.
Tip:
Ensure your timer resets inside the loop so it continues to count down.
Check:
Does the timer count down correctly by 1 every second?
Add logic to make collectible unstuck
Goal:
Implement the logic to make collectible sprites unstuck.
Right now, when the collectible coin sprite spawns on the rock, the player is unable to collect it.
The coin should jump somewhere else when it spawns on the rock, so it is not stuck!
Tip:
Using 'random location' helps ensure the collectible doesn't get stuck in the same place.
Check:
Do the coins move to a new location when they spawn on a rock?
Fix logic for collecting coins
Goal:
Fix the logic for collecting coins.
When the hero touches a coin, it should play a sound, increase 'collectedCarrots' by 1, and make the coin jump to a random location.
Tip:
Don't forget to increase the variable by 1 every time the hero touches a coin.
Check:
Does the coin count increase when you touch a coin?
End Game Logic
Goal:
Implement the logic to end the game when the hero touches the ghost.
Create a 'endGame' function
Play the 'gameOver' sound
Set closing background
Show game over message
Remove all sprites
Show collected carrots score
Hide the timer variable
Add a 'when' block to trigger 'endGame' if the hero touches the ghost.
Tip:
Make sure your 'endGame' function removes all sprites so the game looks clean.
Check:
Does the game end and show the "Game Over" message when you touch the ghost?
🎉 Congratulations!
Congratulations! You've completed 'The Roaming Ghost' game. Time to test your skills and see how many carrots you can collect!
Celebrate!
🏆
🚀 Challenge Ideas!
Ready for more? Try these challenges to level up your game!
Add multiple lives
Make the walls move
Make enemies faster
🚀