Copy template

Goal: Create a copy of the project template
  1. Click this link to make a remix: PROJECT LINK

Initialize Game

Goal: Set up the starting background and show the title screen when the program runs.

Welcome to Jumping Bear! In this first step, configure what the player sees when clicking Run.

  1. Connect the "set background to" block under the "when run" block.
  2. Select the mountain forest landscape background from the dropdown.
  3. Add the "show title screen" block under the "set background to" block.
  4. Type "Jumping bear" into the "title" input.
  5. Type "Press "A" to start" into the "subtitle" input.
Tip: Make sure the title and subtitle match the capitalization and punctuation shown in the screenshot.
Check: Click Run. You should see the mountain forest background with the title "Jumping bear" and subtitle "Press "A" to start".
Initialize Game

Create Bear Function

Goal: Define a function to spawn and initialize the player bear sprite with behaviors.

Create a reusable function called createBear to spawn the player character with its initial position, size, and movement behaviors.

  1. Open the Functions category and create a new function named "createBear".
  2. Add a "make new [sprite] sprite at (x, y)" block inside the function.
  3. Select the bear sprite and set the coordinates to (123, 72).
  4. Add a "set [sprite] size to" block, select the bear sprite, and set the value to 30.
  5. Add a "sprite [sprite] begins" block, select the bear sprite, and choose the "gravityTurnedOn" behavior.
  6. Add another "sprite [sprite] begins" block, select the bear sprite, and choose the "moving with arrow keys" behavior.
Tip: Putting sprite setup inside a function makes it easy to respawn the bear whenever a new level starts.
Check: Verify that the createBear function spawns the bear at (123, 72) with size 30 and attaches both the gravityTurnedOn and moving with arrow keys behaviors.
Create Bear Function

Start Game on "A" Key Press

Goal: Reset the stage, initialize game variables, and spawn the bear and map when pressing A.

When the player presses the "a" key, hide the title screen, reset game variables, and start the first level.

  1. Drag out a "when [key] pressed" event block and select "a" from the dropdown.
  2. Connect the "hide title screen" block under the "when [a] pressed" block.
  3. Add the "remove [all sprites]" block under the "hide title screen" block.
  4. Add the "set background to" block and choose the meadow landscape with a tree.
  5. Add a "set [variable] to" block, select "gravity", and set it to 5.
  6. Add a "set [variable] to" block, select "jumped", and set it to 0.
  7. Add a "set [variable] to" block, select "level", and set it to 0.
  8. Add a "set [variable] to" block, select "subLevel", and set it to 0.
  9. Add the "createBear" function block under the variable blocks.
  10. Add the "createMap1" function block under the "createBear" block.
Tip: Initializing all variables to their starting values ensures the game resets properly every time it starts.
Check: Press the "a" key after running the program to verify the title screen hides, the meadow background appears, and the bear and map load.
Start Game on "A" Key Press

Create the Gravity Behavior

Goal: Define a custom gravityTurnedOn behavior that pulls the sprite downward and detects ground collisions.

To simulate gravity and solid platforms, create a behavior that moves the sprite downward unless it is touching dirt or magic floor platforms.

  1. Open the Behaviors category and create a new behavior named "gravityTurnedOn with: this sprite".
  2. Add a "move [sprite] [distance] pixels [direction]" block inside the behavior.
  3. Set the sprite to "this sprite", distance to the "gravity" variable, and direction to "South".
  4. Add an "if" logic block under the move block and click the plus icon to add an "else if" branch.
  5. In the first condition slot, check if "[this sprite] is touching [dirt]" = true.
  6. Inside the first branch do slot, add a "set [variable] to" block, choose "jumped", and set it to 0.
  7. Add a "move [sprite] [distance] pixels [direction]" block inside the first branch, setting sprite to "this sprite", distance to "gravity", and direction to "North".
  8. In the "else if" condition slot, check if "[this sprite] is touching [magic floor]" = true.
  9. Inside the second branch do slot, add a "set [variable] to" block, choose "jumped", and set it to 0.
  10. Add a "move [sprite] [distance] pixels [direction]" block inside the second branch, setting sprite to "this sprite", distance to "gravity", and direction to "North".
Tip: Moving the sprite North when touching a platform offsets the downward gravity pull so the sprite stays on solid ground and resets the jumped variable.
Check: Verify your behavior checks collisions for both the dirt platform and the magic floor platform, resetting jumped to 0 each time.
Create the Gravity Behavior

Make the Bear Jump

Goal: Program the bear to jump upward when space is pressed if it is not already in the air.

Give the bear jumping abilities by checking the jumped variable whenever the player presses the space key.

  1. Drag out a "when [key] pressed" event block and select "space" from the dropdown.
  2. Connect an "if [condition] do" block under the "when [space] pressed" block.
  3. Set the if condition to check if "jumped" = 0.
  4. Inside the do branch, add a "set [variable] to" block, choose "jumped", and set it to 1.
  5. Add a "move [sprite] [distance] pixels [direction]" block inside the do branch.
  6. Select the bear sprite in the sprite slot.
  7. In the distance slot, insert a multiplication block and calculate "gravity" * 8.
  8. Set the direction dropdown to "North".
Tip: Setting jumped to 1 prevents the player from jumping repeatedly while already in the air.
Check: Press the space key while running the game. The bear should leap upward by gravity multiplied by 8 pixels.
Make the Bear Jump

Animate Magic Floor Function

Goal: Define a function to give magic floor platforms a swimming movement behavior, size, and speed.

Create the animateMagicFloor function to make floating platforms move back and forth across the screen.

  1. Open the Functions category and create a new function named "animateMagicFloor".
  2. Add a "sprite [sprite] begins" block inside the function.
  3. Select the magic floor sprite and choose the "swimming left and right" behavior.
  4. Add a "set [sprite] [property] to" block, select the magic floor sprite, choose "size", and set it to 50.
  5. Add a "set [sprite] [property] to" block, select the magic floor sprite, choose "speed", and set it to 5.
Tip: The swimming left and right behavior automatically bounces the platform between the left and right screen boundaries.
Check: Check that the animateMagicFloor function sets the magic floor sprite behavior to swimming left and right, size to 50, and speed to 5.
Animate Magic Floor Function

Lose Game Function

Goal: Define a function to display the game over screen, play a cue sound, and remove all sprites.

Create the loseGame function to cleanly handle when the player fails a level or touches a hazard.

  1. Open the Functions category and create a new function named "loseGame".
  2. Add a "set background to" block and choose the dark space background with stars and planets.
  3. Add the "show title screen" block under the background block.
  4. Type "You lose!" into the "title" input.
  5. Type "Press "A" to restart" into the "subtitle" input.
  6. Add the "remove [all sprites]" block under the title screen block.
  7. Add a "play sound" block and select "Alerts: playful_quirky_negative_game_cue_2".
Tip: Removing all sprites stops all ongoing behaviors and clears obstacles from the screen.
Check: Verify that the loseGame function sets the space background, shows "You lose!", removes all sprites, and plays the defeat sound.
Lose Game Function

Win Game Function

Goal: Define a function to display the victory screen and clear all sprites.

Create the winGame function to celebrate when the player completes all levels of the game.

  1. Open the Functions category and create a new function named "winGame".
  2. Add a "set background to" block and choose the rainbow hill landscape background.
  3. Add the "show title screen" block under the background block.
  4. Type "You win!" into the "title" input.
  5. Type "Press "A" to restart" into the "subtitle" input.
  6. Add the "remove [all sprites]" block under the title screen block.
Tip: The player can restart the game from this screen anytime by pressing the "A" key.
Check: Verify that the winGame function sets the rainbow background, displays "You win!", and removes all sprites.
Win Game Function

Level Progression with Apples

Goal: Play a celebration sound and advance through levels 1, 2, or win the game when touching an apple.

The apple acts as the goal for each level. Advance the level variable and load the next map when the bear reaches it.

  1. Drag out a "when [sprite] touches [sprite]" event block, choosing the bear and apple sprites.
  2. Connect the "play sound" block under the event and select "Achievements: vibrate_success_1_up".
  3. Add an "if [condition] do" block under the sound block and use the plus icon to add two "else if" branches.
  4. In the first condition slot, check if "level" = 0.
  5. Inside the first branch, set "level" to 1.
  6. Add the "remove [all sprites]" block inside the first branch.
  7. Add the "createBear" function block inside the first branch.
  8. Add the "createMap2" function block inside the first branch.
  9. In the second condition slot, check if "level" = 1.
  10. Inside the second branch, set "level" to 2.
  11. Add the "remove [all sprites]" block inside the second branch.
  12. Add the "createBear" function block inside the second branch.
  13. Add the "createMap3" function block inside the second branch.
  14. In the third condition slot, check if "level" = 2.
  15. Inside the third branch, add the "winGame" function block.
Tip: Always remove all sprites before spawning new ones to clear old platforms and items.
Check: Move the bear into an apple. Listen for the achievement sound and verify that the next level loads.
Level Progression with Apples

Collecting Coins and Sub-levels

Goal: Collect coins to update platforms, animate magic floors, and spawn new coins across sub-levels.

Each coin collected within a level updates the layout by placing new dirt platforms and magic floors.

  1. Drag out a "when [sprite] touches [sprite]" event block, selecting the bear and coin sprites.
  2. Connect the "play sound" block under the event and select "Collect: collect_item_bling_1".
  3. Add a "remove [object]" block and select the coin sprite.
  4. Add an "if [condition] do" block with two "else if" branches.
  5. In the first condition slot, check if "subLevel" = 0.
  6. Inside the first branch, add a "make [dirt] sprites using grid" block.
  7. Add a "make new [magic floor] sprite at (163, 131)" block.
  8. Add the "animateMagicFloor" function block.
  9. Add a "make new [coin] sprite at (382, 173)" block.
  10. Add a "set [coin] size to" block and set the size to 50.
  11. Add a "set [subLevel] to" block and set the value to 1.
  12. In the second condition slot, check if "subLevel" = 1.
  13. Inside the second branch, add a "make [dirt] sprites using grid" block.
  14. Add a "make new [magic floor] sprite at (266, 187)" block.
  15. Add the "animateMagicFloor" function block.
  16. Add a "make new [coin] sprite at (26, 224)" block.
  17. Add a "set [coin] size to" block and set the size to 50.
  18. Add a "set [subLevel] to" block and set the value to 2.
  19. In the third condition slot, check if "subLevel" = 2.
  20. Inside the third branch, add a "make [dirt] sprites using grid" block.
Tip: Notice how each subLevel sets up the next platform puzzle and repositions the coin.
Check: Touch a coin with the bear. The bling sound should play, the coin should disappear, and new platforms should appear.
Collecting Coins and Sub-levels

Hazard Detection

Goal: End the game when the bear touches the hazard block.

Add danger to the game by triggering a game over if the bear falls onto or touches a hazard.

  1. Drag out a "when [sprite] touches [sprite]" event block.
  2. Select the bear sprite in the first slot and the hazard block sprite in the second slot.
  3. Connect the "loseGame" function block inside the event.
Tip: Make sure the hazard block sprite matches the brown hazard block used across your level maps.
Check: Have the bear touch the hazard block to verify that the loseGame function triggers.
Hazard Detection

🎉 Congratulations!

Congratulations! You built a complete jumping bear platformer with multiple levels, dynamic sub-levels, jump mechanics, custom gravity physics, and hazard detection!
🏆

Next challenge!

  1. Update the map for level 3
  2. Create a double jump ability by allowing the bear to jump when jumped is less than 2.
  3. Add sound effects when the player jumps
🚀
×
Zoomed view