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

Create Map 1

Goal: Define a function to build the platforms, animated floor, and goal item for Level 1.

Create the first level environment with platforms for the bear to jump on, an animated magic floor, and an apple as the goal.

  1. Open the Functions category and create a new function named "createMap1".
  2. Add a "make [lava] sprites using grid" block to create the bottom hazard layer.
  3. Add a "make new [magic floor] sprite at (220, 146)" block.
  4. Add a "make [dirt] sprites using grid" block to create stepping platforms.
  5. Add a "make new [magic floor] sprite at (133, 248)" block.
  6. Add the "animateMagicFloor" function block under the magic floor block.
  7. Add a "make new [apple] sprite at (24, 317)" block.
  8. Add a "set [apple] size to" block and set the value to 50.
Tip: Make sure you call animateMagicFloor after adding the magic floor sprites so they start moving.
Check: Verify that createMap1 builds the hazard floor, platforms, magic floors, and the apple at (24, 317) with size 50.
Create Map 1

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 [this sprite] [gravity] pixels [South]" block inside the behavior.
  3. Add an "if [condition] do" block under the move block and click the plus icon to add an "else if" branch.
  4. In the first condition slot, check if "[this sprite] is touching [dirt] = true".
  5. Inside the first branch, add a "set [jumped] to 0" block.
  6. Add a "move [this sprite] [gravity] pixels [North]" block inside the first branch.
  7. In the else if condition slot, check if "[this sprite] is touching [magic floor] = true".
  8. Inside the second branch, add a "set [jumped] to 0" block.
  9. Add a "move [this sprite] [gravity] pixels [North]" block inside the second branch.
Tip: Moving North by the gravity amount when touching a platform cancels out the downward pull, allowing the bear to stand firmly on surfaces.
Check: Verify that the behavior moves the sprite South by gravity pixels, and pushes it North while resetting jumped to 0 when touching dirt or magic floor platforms.
Create the Gravity Behavior

Jumping Mechanic on Space Pressed

Goal: Make the bear jump upward when the space bar is pressed, but only if it is currently grounded.

Add controls to let the player jump by checking the jumped variable so the bear cannot jump repeatedly mid-air.

  1. Drag out a "when [key] pressed" event block and select "space" from the dropdown.
  2. Add an "if [condition] do" block inside the event.
  3. In the condition slot, check if "jumped = 0".
  4. Inside the do branch, add a "set [jumped] to 1" block.
  5. Add a "move [sprite] [distance] pixels [North]" block, selecting the bear sprite.
  6. Set the distance slot to "gravity x 8" using a math multiplication block.
Tip: Setting jumped to 1 prevents the bear from jumping again until gravity resets jumped to 0 upon landing on a platform.
Check: Press the space bar while playing. The bear should leap upward by 40 pixels (5 x 8) and fall back down with gravity.
Jumping Mechanic on Space Pressed

Animate Magic Floor Function

Goal: Define a function to animate and resize moving platform magic floors.

Magic floors add dynamic platforming challenges by moving 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, select the magic floor sprite, and choose "swimming left and right".
  3. Add a "set [sprite] size to" block, select the magic floor sprite, and set the value to 50.
  4. Add a "set [sprite] speed to" block, select the magic floor sprite, and set the value to 5.
Tip: Using the "swimming left and right" behavior causes the magic floor to continuously patrol horizontally across the screen.
Check: Verify that the animateMagicFloor function gives magic floors the "swimming left and right" behavior with size 50 and speed 5.
Animate Magic Floor Function

Game Over Function

Goal: Define a function to handle defeat, display the game over screen, and play a sound cue.

Create a reusable loseGame function to notify the player when they touch a hazard or fail an objective.

  1. Open the Functions category and create a new function named "loseGame".
  2. Add a "set background to" block and choose the space night sky 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: Clearing all sprites ensures old platforms and hazards are cleaned up before restarting.
Check: Verify that the loseGame function switches the background to space, shows the title screen "You lose!", removes all sprites, and plays the negative game cue sound.
Game Over 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. While Map 1 had step-by-step instructions and Map 3 is already provided for you, creating Map 2 is entirely up to your own creativity! Build an exciting obstacle layout for Level 2, then advance the level variable and load the next map when the bear reaches the apple.

  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. Create a new function named "createMap2" and design your own Level 2 map layout using your creativity with platforms, hazards, and collectibles (Map 1 had guided steps, and Map 3 is already done for you!). Then 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. Use your imagination when building createMap2—try combining moving magic floors, jumping platforms, and hazards to make Level 2 uniquely yours!
Check: Move the bear into an apple. Listen for the achievement sound and verify that the next level loads.
Level Progression with Apples 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