- Click this link to make a remix: PROJECT LINK
Copy template
Initialize Game
Welcome to Jumping Bear! In this first step, configure what the player sees when clicking Run.
- Connect the "set background to" block under the "when run" block.
- Select the mountain forest landscape background from the dropdown.
- Add the "show title screen" block under the "set background to" block.
- Type "Jumping bear" into the "title" input.
- Type "Press "A" to start" into the "subtitle" input.
Create Bear Function
Create a reusable function called createBear to spawn the player character with its initial position, size, and movement behaviors.
- Open the Functions category and create a new function named "createBear".
- Add a "make new [sprite] sprite at (x, y)" block inside the function.
- Select the bear sprite and set the coordinates to (123, 72).
- Add a "set [sprite] size to" block, select the bear sprite, and set the value to 30.
- Add a "sprite [sprite] begins" block, select the bear sprite, and choose the "gravityTurnedOn" behavior.
- Add another "sprite [sprite] begins" block, select the bear sprite, and choose the "moving with arrow keys" behavior.
Start Game on "A" Key Press
When the player presses the "a" key, hide the title screen, reset game variables, and start the first level.
- Drag out a "when [key] pressed" event block and select "a" from the dropdown.
- Connect the "hide title screen" block under the "when [a] pressed" block.
- Add the "remove [all sprites]" block under the "hide title screen" block.
- Add the "set background to" block and choose the meadow landscape with a tree.
- Add a "set [variable] to" block, select "gravity", and set it to 5.
- Add a "set [variable] to" block, select "jumped", and set it to 0.
- Add a "set [variable] to" block, select "level", and set it to 0.
- Add a "set [variable] to" block, select "subLevel", and set it to 0.
- Add the "createBear" function block under the variable blocks.
- Add the "createMap1" function block under the "createBear" block.
Create the Gravity Behavior
To simulate gravity and solid platforms, create a behavior that moves the sprite downward unless it is touching dirt or magic floor platforms.
- Open the Behaviors category and create a new behavior named "gravityTurnedOn with: this sprite".
- Add a "move [sprite] [distance] pixels [direction]" block inside the behavior.
- Set the sprite to "this sprite", distance to the "gravity" variable, and direction to "South".
- Add an "if" logic block under the move block and click the plus icon to add an "else if" branch.
- In the first condition slot, check if "[this sprite] is touching [dirt]" = true.
- Inside the first branch do slot, add a "set [variable] to" block, choose "jumped", and set it to 0.
- Add a "move [sprite] [distance] pixels [direction]" block inside the first branch, setting sprite to "this sprite", distance to "gravity", and direction to "North".
- In the "else if" condition slot, check if "[this sprite] is touching [magic floor]" = true.
- Inside the second branch do slot, add a "set [variable] to" block, choose "jumped", and set it to 0.
- Add a "move [sprite] [distance] pixels [direction]" block inside the second branch, setting sprite to "this sprite", distance to "gravity", and direction to "North".
Make the Bear Jump
Give the bear jumping abilities by checking the jumped variable whenever the player presses the space key.
- Drag out a "when [key] pressed" event block and select "space" from the dropdown.
- Connect an "if [condition] do" block under the "when [space] pressed" block.
- Set the if condition to check if "jumped" = 0.
- Inside the do branch, add a "set [variable] to" block, choose "jumped", and set it to 1.
- Add a "move [sprite] [distance] pixels [direction]" block inside the do branch.
- Select the bear sprite in the sprite slot.
- In the distance slot, insert a multiplication block and calculate "gravity" * 8.
- Set the direction dropdown to "North".
Animate Magic Floor Function
Create the animateMagicFloor function to make floating platforms move back and forth across the screen.
- Open the Functions category and create a new function named "animateMagicFloor".
- Add a "sprite [sprite] begins" block inside the function.
- Select the magic floor sprite and choose the "swimming left and right" behavior.
- Add a "set [sprite] [property] to" block, select the magic floor sprite, choose "size", and set it to 50.
- Add a "set [sprite] [property] to" block, select the magic floor sprite, choose "speed", and set it to 5.
Lose Game Function
Create the loseGame function to cleanly handle when the player fails a level or touches a hazard.
- Open the Functions category and create a new function named "loseGame".
- Add a "set background to" block and choose the dark space background with stars and planets.
- Add the "show title screen" block under the background block.
- Type "You lose!" into the "title" input.
- Type "Press "A" to restart" into the "subtitle" input.
- Add the "remove [all sprites]" block under the title screen block.
- Add a "play sound" block and select "Alerts: playful_quirky_negative_game_cue_2".
Win Game Function
Create the winGame function to celebrate when the player completes all levels of the game.
- Open the Functions category and create a new function named "winGame".
- Add a "set background to" block and choose the rainbow hill landscape background.
- Add the "show title screen" block under the background block.
- Type "You win!" into the "title" input.
- Type "Press "A" to restart" into the "subtitle" input.
- Add the "remove [all sprites]" block under the title screen block.
Level Progression with Apples
The apple acts as the goal for each level. Advance the level variable and load the next map when the bear reaches it.
- Drag out a "when [sprite] touches [sprite]" event block, choosing the bear and apple sprites.
- Connect the "play sound" block under the event and select "Achievements: vibrate_success_1_up".
- Add an "if [condition] do" block under the sound block and use the plus icon to add two "else if" branches.
- In the first condition slot, check if "level" = 0.
- Inside the first branch, set "level" to 1.
- Add the "remove [all sprites]" block inside the first branch.
- Add the "createBear" function block inside the first branch.
- Add the "createMap2" function block inside the first branch.
- In the second condition slot, check if "level" = 1.
- Inside the second branch, set "level" to 2.
- Add the "remove [all sprites]" block inside the second branch.
- Add the "createBear" function block inside the second branch.
- Add the "createMap3" function block inside the second branch.
- In the third condition slot, check if "level" = 2.
- Inside the third branch, add the "winGame" function block.
Collecting Coins and Sub-levels
Each coin collected within a level updates the layout by placing new dirt platforms and magic floors.
- Drag out a "when [sprite] touches [sprite]" event block, selecting the bear and coin sprites.
- Connect the "play sound" block under the event and select "Collect: collect_item_bling_1".
- Add a "remove [object]" block and select the coin sprite.
- Add an "if [condition] do" block with two "else if" branches.
- In the first condition slot, check if "subLevel" = 0.
- Inside the first branch, add a "make [dirt] sprites using grid" block.
- Add a "make new [magic floor] sprite at (163, 131)" block.
- Add the "animateMagicFloor" function block.
- Add a "make new [coin] sprite at (382, 173)" block.
- Add a "set [coin] size to" block and set the size to 50.
- Add a "set [subLevel] to" block and set the value to 1.
- In the second condition slot, check if "subLevel" = 1.
- Inside the second branch, add a "make [dirt] sprites using grid" block.
- Add a "make new [magic floor] sprite at (266, 187)" block.
- Add the "animateMagicFloor" function block.
- Add a "make new [coin] sprite at (26, 224)" block.
- Add a "set [coin] size to" block and set the size to 50.
- Add a "set [subLevel] to" block and set the value to 2.
- In the third condition slot, check if "subLevel" = 2.
- Inside the third branch, add a "make [dirt] sprites using grid" block.
Hazard Detection
Add danger to the game by triggering a game over if the bear falls onto or touches a hazard.
- Drag out a "when [sprite] touches [sprite]" event block.
- Select the bear sprite in the first slot and the hazard block sprite in the second slot.
- Connect the "loseGame" function block inside the event.
🎉 Congratulations!
Next challenge!
- Update the map for level 3
- Create a double jump ability by allowing the bear to jump when jumped is less than 2.
- Add sound effects when the player jumps