Session 3 of 5 · 60 minutes
Sports
Build sports games: make things move, notice when they touch, and keep score.
Goals
By the end of this session you can:
- Move a sprite with motion blocks and the keyboard
- Use if touching to react when two sprites meet
- Keep a score with a variable
- Remix a sports starter project and change how the game plays
Words to know
- condition
- A question the game asks, like "am I touching the ball?". The answer is yes or no.
- variable
- A named box that holds a value, such as score. It can change while the game runs.
- coordinates
- The x and y numbers that say where a sprite is on the stage.
The lesson
Step 1: Net Sports
Today’s main project is Sports - Net Sports. Open a starter, press the green flag, play it, and look at how it works with See inside.
- Net Sports: pick the starter you like:
Step 2: Move things
Open the Motion category.
| Block | What it does |
|---|---|
| move 10 steps | Moves the sprite forward. |
| change x by 10 | Moves the sprite right (use a negative number to go left). |
| change y by 10 | Moves the sprite up. |
| go to x: y: | Jumps to a spot on the stage. |
| if on edge, bounce | Turns the sprite around when it hits the edge. |
Add when right arrow key pressed from Events on top, and you can move a sprite with the keyboard.
Step 3: Ask a question with if
A sports game must notice when things meet. Use if touching Ball then from Control and Sensing, and put the blocks you want to run inside it. Put the if inside a forever so the game keeps checking.
Step 4: Keep score
- Open Variables and click Make a Variable. Name it
score. - Under when green flag clicked, add set score to 0.
- Inside your if touching, add change score by 1.
Step 5: Projects to remix
If your class finishes the main project early, choose one of these.
- Sports - Batter Up: Starter project
- Sports - Extreme Sports: Starter project
Exercise
Catch the ball and score
- Add a ball sprite and a catcher sprite (a basket, a net or a glove).
- Make the catcher move: when right arrow key pressed, change x by 10, and the same for the left arrow with change x by -10.
- In Variables, click Make a Variable and name it
score. Put set score to 0 under when green flag clicked. - On the ball: forever, if touching Catcher then, change score by 1, then go to the top of the stage.
- Play it and see if the score goes up.
Need a hint?
Choose the catcher's name in the drop-down of the touching block.
Small project
My sports game
Remix a sports starter project and change it so it plays your way.
- Open Net Sports (choose one of its starters) and click Remix.
- Play it once. Find the score, the moving parts and how it ends.
- Change the look: new sprites, costumes or a new backdrop.
- Change one rule, such as how fast things move or how many points a catch is worth.
- Test it and ask a classmate to play.
Stretch it: Make the game get harder as the score grows.
Quiz
Check your understanding
Pick one answer for each question. Your score appears right in the page; nothing is sent anywhere.
Feedback on this lesson
Teachers and students: tell us what worked and what didn't. We read this to improve the curriculum.
Received
Thank you for the feedback.
The Education team reviews lesson feedback to improve the curriculum.
Preview mode: this form is not connected to a destination yet, so nothing was sent. Set its web address in src/data/config.json.