Setup the Game

Goal: Initialize the game environment, player, and title screen.

  1. Add a 'when run' block.
  2. Set the background to the dark forest image.
  3. Show the title screen with the title "The roaming ghost" and the subtitle "Press space to start".
Tip: Make sure to select the correct background image.
Check: Did you see the title screen when you run the code?

Define the startGame function

Goal: Create the functions to start the game.

  1. Create a 'createGameMap' function. Set background and create collectible.
  2. Create a 'createHero' function.
  3. Then create a "start game" function.
  4. Inside, set the background using 'createGameMap', create the hero.
  5. Hide the title screen, hide 'collectedCarrots'
  6. Set the variables, set the 'timer' to 60, set 'collectedCarrots' to 0.
  7. Create the enemy, spawn a ghost, and make it wander using a behaviour block.
Tip: You can find the 'function' blocks in the Functions category.
Check: Does your function have all the sprite setup blocks inside?

When "Space" pressed event

Goal: Create the hero and start the game when the space key is pressed.

  1. Add a 'when space pressed' block to call the 'startGame' function.
Tip: Remember to use the 'when space pressed' event to trigger your start function.
Check: Does the game start when you press the space key?

Win game function

Goal: Create the win game function.

  1. Play start game sound
  2. Set rainbow background
  3. Show win game message
  4. Remove all sprites
  5. Show collected carrots score
  6. Hide the timer variable
Tip: Play around with different background images for your win screen!
Check: Does the win screen appear when you win?
src='screenshots/step-4-winGame-function.png' alt=''>

Timer logic

Goal: Implement the timer logic.

  1. Use an 'at 1 seconds' loop to decrease the 'timer' by 1 and reset the timer so the loop keeps running.
  2. Inside the loop, add an 'if' block to check if the 'timer' equals 0.
  3. If the timer reaches 0, call the 'winGame' function.
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?

Logic to make collectible unstuck

Goal: Implement the logic to make collectible sprites unstuck.

  1. When the collectible coin sprite touches the rock, it should jump somewhere else 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?

Logic for collecting coins

Goal: Implement the logic for collecting coins.

  1. When the hero touches a coin, 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.

  1. Create a 'endGame' function
  2. Play the 'gameOver' sound
  3. Set closing background
  4. Show game over message
  5. Remove all sprites
  6. Show collected carrots score
  7. Hide the timer variable
  8. 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!
🏆

🚀 Challenge Ideas!

Ready for more? Try these challenges to level up your game!
  1. Add multiple lives
  2. Make the walls move
  3. Make enemies faster
🚀