Introduction to the Jumping Game
- In this lesson, we will create a fun jumping game using Scratch.
- In this game, the player sprite will jump over obstacles.
- If the player touches the obstacle, the game will get over.
- This lesson helps students understand movement, loops, sensing, conditions, variables, and scoring in Scratch.
What Students Will Learn
- How to position sprites at a specific location using x and y coordinates
- How to make a sprite jump using keyboard events
- How to move obstacles smoothly using glide blocks
- How to repeat actions using forever loops
- How to detect when two sprites touch each other
- How to stop the game using conditions
- How to create and use variables to add a score
- How to reset the score when the game restarts
Adding Sprites
In this project, we will use two main sprites:
- Dinosaur sprite as the player
- Ball sprite as the obstacle
How to add sprites:
- Click on the Choose a Sprite icon at the bottom right corner
- Select a dinosaur sprite from the library
- Click again on Choose a Sprite and select a ball sprite
Positioning Sprites on the Stage
- Position the dinosaur at the bottom left corner (the ground)
- Position the ball at the bottom right corner (the starting point for the obstacle)
- Note the x and y numbers displayed below the stage for each sprite
Explanation: Every sprite in Scratch has an x (left-right) and y (up-down) position. Using these coordinates ensures the sprite starts at the same spot every time the game starts.
Coding the Dinosaur Sprite (Player)
Starting Position
- Select the dinosaur sprite
- Go to Events and pick when green flag clicked
- Go to Motion and drag go to x: ___ y: ___
Explanation: This makes the dinosaur start from the ground at the same position every time the game runs.
Making the Dinosaur Jump
- Events → when space key pressed
- Motion → change y by 10 to move up
- To come down, use change y by -10
Explanation: The y position controls vertical movement.
Creating a Smooth Jump
- Control → repeat 10, inside it place change y by 10 (dinosaur goes up smoothly)
- Add another repeat 10 block and place change y by -10 (dinosaur comes down smoothly)
Explanation: Using repeat blocks makes the jump look smooth rather than instant.
Coding the Obstacle (Ball)
Starting Position
- Select the ball sprite
- Add when green flag clicked
- Motion → go to x: ___ y: ___
Explanation: The ball will always start from the bottom right corner.
Making the Ball Move
- Motion → glide 1 second to x: ___ y: ___
- Set the x and y numbers to the bottom left corner
- Add a forever block around the glide block
Explanation: Glide moves the ball smoothly. The forever block repeats the movement continuously.
You can change the number in glide (like 2 for slower or 0.5 for faster movement).
Detecting Collision (Game Over)
- On the ball sprite, add when green flag clicked
- Control → if then
- Sensing → touching dinosaur? → place inside the if block
- Control → stop all → place inside the if block
- Add a forever block around the if then block
Explanation: If the dinosaur touches the ball, the game stops immediately.
Adding a Score
Creating the Score Variable
- Variables → Make a Variable
- Name it score
Increasing the Score
- Go to the ball sprite code
- Under the glide block, add change score by 1
Explanation: Every time the ball completes one movement from right to left, the score increases.
Resetting the Score
- Add when green flag clicked
- Variables → set score to 0
Explanation: This ensures the score resets every time the game starts.
Summary of What Students Learned
- How to position sprites using x and y coordinates
- How to make a sprite jump using keyboard events
- How to move obstacles smoothly using glide
- How to use repeat loops for smooth movement
- How to detect collisions between sprites
- How to stop the game when a condition is met
- How to create, increase, and reset a score variable
Task for Students
- Create your own jumping game
- Choose any sprite as your player
- Add at least one obstacle
- Try adding two obstacles, changing the speed, or adding sound effects
- Make the game more challenging and fun