Remix the Template

Goal: Create your own copy of the starter project.
  1. Click this link to create a remix of the template: Remix Template

Initialize the Game

Goal: Set the starting background, title screen, and game state.
  1. Find the "set background to" block in the World category and set a background of your choice from the library.
  2. Choose the night forest image from the background dropdown.
  3. Add the "show title screen" block from the World category under the background block.
  4. Set the title field to "Treasure hunter" and the subtitle field to "Press space to start".
  5. Add a "set to" variable block from the Variables category below the title screen block.
  6. Choose the "game started" variable from the dropdown and set its value to false.
Initialize the Game

Create the Map Function

Goal: Define the createMap function to set the playing grid background and create the compass sprite.
  1. Inside the "createMap" function block, add a "set background to" block from the World category and choose any background you like.
  2. Select the grid background from the dropdown.
  3. Add a "make new sprite at" block from the Sprites category and choose the compass sprite.
  4. Set the location pin coordinates for the compass sprite to (32, 26).
  5. Add a "set size to" block from the Sprites category, select the compass sprite, and set the size to 50.
Create the Map Function

Create the Treasure Function

Goal: Define the createTreasure function to spawn the coin sprite at a random location.
  1. Inside the "createTreasure" function block, add a "make new sprite at" block from the Sprites category.
  2. Select the coin sprite from the dropdown.
  3. Attach a "random location" block from the Locations category to the location input.
  4. Add a "set size to" block from the Sprites category, select the coin sprite, and set the size to 1.
Create the Treasure Function

Create the Hero Function

Goal: Define the createHero function to spawn the player character and enable arrow key controls.
  1. Inside the "createHero" function block, add a "make new sprite at" block from the Sprites category.
  2. Select the purple bunny sprite from the dropdown.
  3. Set the location pin coordinates for the bunny sprite to (332, 48).
  4. Add a "set size to" block from the Sprites category, select the bunny sprite, and set the size to 50.
  5. Add a "sprite begins" block from the Behaviors category and select the bunny sprite.
  6. Attach the "moving with arrow keys" behavior block from the Behaviors category to the "sprite begins" block.
Create the Hero Function

Create the Monster Function

Goal: Define the createEnemy function to spawn the monster and give it wandering behavior.
  1. Inside the "createEnemy" function block, add a "make new sprite at" block from the Sprites category.
  2. Select the orange monster sprite from the dropdown.
  3. Set the location pin coordinates for the monster sprite to (64, 315).
  4. Add a "sprite begins" block from the Behaviors category and select the monster sprite.
  5. Attach the "wandering" behavior block from the Behaviors category to the "sprite begins" block.
Create the Monster Function

Start the Game with Space Key

Goal: Run the setup functions when the space key is pressed.
  1. Add a "when space pressed" event block from the Events category.
  2. Place an "if" block from the Logic category inside the event block.
  3. Connect an equality comparison block to the "if" condition and check if "game started" equals false.
  4. Inside the "do" section, add function call blocks in the following order:
    1. resetGame
    2. createMap
    3. createTreasure
    4. createHero
    5. createEnemy
Start the Game with Space Key

Keep the Treasure Unstuck

Goal: Relocate the coin if it spawns on top of the compass.
  1. Add a "when touches" event block from the Events category.
  2. Select the coin sprite in the first dropdown and the compass sprite in the second dropdown.
  3. Inside the event block, add a "jump to" block from the Sprites category, select the coin sprite, and set it to jump to a "random location".
Keep the Treasure Unstuck

Collect the Treasure

Goal: Update score, play a sound, and relocate the coin when the player collects it.
  1. Add a "when touches" event block from the Events category.
  2. Select the coin sprite in the first dropdown and the purple bunny sprite in the second dropdown.
  3. Add a "play sound" block from the World category and select any sound you like from the sound library.
  4. Add a "jump to" block from the Sprites category and set the coin sprite to jump to a "random location".
  5. Add a "change by" variable block from the Variables category to increase the "score" variable by 1.
  6. Add a "say" block from the Sprites category for the purple bunny sprite.
  7. Use a text join block to combine "Collected: " with the "score" variable, and set the duration to 4 seconds.
Collect the Treasure

Check Coordinates with Compass

Goal: Display the treasure coordinates when the player touches the compass.
  1. Add a "when touches" event block from the Events category.
  2. Select the compass sprite in the first dropdown and the purple bunny sprite in the second dropdown.
  3. Add a "say" block from the Sprites category for the compass sprite and set the duration to 4 seconds.
  4. Use text join blocks to combine "The treasure is at ", "X: ", the coin's "x position" block, "Y: ", and the coin's "y position" block.
  5. Add a "play sound" block from the World category and select any sound you like from the sound library.
Check Coordinates with Compass

Game Over Logic

Goal: Trigger game over when the monster touches the hero.
  1. Add a "when touches" event block from the Events category.
  2. Select the orange monster sprite in the first dropdown and the purple bunny sprite in the second dropdown.
  3. Inside the event block, add the "gameOver" function call block from the Functions category.
Game Over Logic

🎉 Congratulations!

Congratulations! You have built the complete Treasure Hunter game with custom functions, events, and coordinates!
🏆

Next challenge!

Next challenge ideas:
  1. Add a countdown timer to see how many treasures you can find before time runs out.
  2. Spawn multiple monsters or increase the monster speed over time.
  3. Change the background or add celebration effects when reaching a high score.
🚀
×
Zoomed view