Adding Spites and Some Action
Step 1: Setting Up the Game
A. Add a Sprite (Cat)
Open Scratch and click Create to start a new project.
The Cat sprite is already there. If not, click Choose a Sprite → Select the Cat.
Position the Cat near the bottom-left of the screen.
B. Add an Obstacle Sprite
Click Choose a Sprite → Select a Rock
Place the rock near the bottom-right of the screen.
C. Add a Backdrop
Click Choose a Backdrop → Select "Blue Sky" or another simple background.
A backdrop with a picture of a rock was chosen. You do not have to use this one. Pick one that you will like to use!
Step 2: Making the Cat Jump
A. Code for the Cat Sprite
Click the Cat Sprite.
Go to Events → Drag "when up arrow key pressed".
Go to Motion → Drag "change y by 50" (this moves the cat up).
Go to Events → Drag "when down arrow key pressed".
Go to Motion → Drag "change y by -50" (this moves the cat down).
Test your code by clicking the flag. Then touch your arrow up and arrow down keys. What happens?
Step 3: Making the Obstacle Move
A. Code the Rock Sprite
Click the Rock Sprite.
Go to Events → Drag "when green flag clicked".
Inside the forever loop: (continuous movement)
Go to Motion → Drag "go to x: 240 y: -100" (This moves the rock to the right each time it starts.)
Go to Control → Drag “wait 1 second.” Change the number to 1, if necessary.
Go to Motion → Drag "glide 3 seconds to x: -240 y: -100" (This moves the rock to the left.)
Test your code. What happens?
Step 4: Game Over if the Cat Hits the Obstacle
A. Adding Collision Detection
Click the Cat Sprite.
Go to Events → Drag "when green flag clicked".
Go to Control → Drag "forever".
Inside the forever loop:
Go to Control → Drag "if touching Rock?".
Inside the if block, add "say 'Game Over!' for 2 seconds".
Add "stop all" (so the game stops).
Test the code. Remember to use your up and down arrows to move the cat.
What happens? What needs to be fixed?
Yes, there is one problem. What is it? How can you fix it?
Follow the directions to fix the problem.
1) The cat does not jump high enough to jump over the rock. Which blocks determine how high the cat jumps up and falls down? What numbers should you change to make the cat jump higher and then fall back to the ground? Try different amounts until you have ones that works.
Well Done!
You have one more challenge. It takes 3 seconds for the rock to move across the stage. Let’s make it move faster.
What block controls how fast the rock moves? Change the speed from 3 seconds to 2 seconds.
Play the game. Is the game harder to play?
Be sure give your game a name and save it. You will be using this game again in Lesson 4. You can use whatever name you would like that helps to describe the game.
In Lesson 4 you will add more complexity to the game, including more rocks and a score keeper.
In Lesson 5 you will add a second level to the game and a timer to make the game more challenging.
Well done! You’ve made your first game!
Wrap Up
With this lesson you learned:
1) how to make a sprite jump,
2) how to create continuous movement
3) how to stop movement.