- 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.
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 platforms, create a behavior that constantly moves the sprite downward unless it is touching dirt or magic floor platforms.
- Open the Behaviors folder and create a new behavior named "gravityTurnedOn".
- Add a "move [sprite]" block inside the behavior.
- Set the sprite to "this sprite", distance to the "gravity" variable, and direction to "South". so that the sprite moves downward.
- Add an "if" Logic block with an "else if" branch under the move block.
- In the first condition slot, check if "[this sprite] is touching [dirt]" = true.
- Inside the first branch, 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.
- Set the 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, 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.
- Set the 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 if block, add a "set [variable] to" block, choose "jumped", and set it to 1.
- Add a "move [sprite] [distance] pixels [direction]" block inside the if block.
- 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".
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 2
- Create a double jump ability by allowing the bear to jump when jumped is less than 2.
- Add sound effects when the player jumps