Make a bouncing ball game and score points to win.
Objective: Students will create algorithms to make a ball bounce off a paddle and the sides. Students will code conditionals and variables to score points or end the game.
Expected Outcome:
Students will be able to:
Objectives/Outcome
Pong Game
Prerequisites:
Students should have foundational understanding of:
Vocabulary
Conditionals
Algorithm
Event
Project Sample
conditional
conditional
conditional
variables
$
24
code.org : Course 4, Lesson 6
Step-by-Step
Go to Clever
Open Code HS
Select the “Pong Game” Project
Tutorials
Video Tutorial
Coding Cards
Pong Game
Decompose
Add sprite (ball) and a background
Add a paddle and code it to follow your mouse.
Make the ball sprite bounce off the paddle.
Make a loop so the the ball moves and bounces off the edges at an angle.
Stop the game if the ball hits a red line
Note: Not all blocks that might be used are shown here. There are multiple ways to code this project.
Add a score
What are some of the code blocks I need?
Step-by-Step
1. Add a background.
2. Add a ball sprite.
Step-by-Step
3. Add this code to the ball sprite
Click the green flag to test the code
Click the green flag to test the code - the ball should bounce off the walls
Try a different number to make the ball move slower or faster
Step-by-Step
4. Add a paddle sprite.
5. Drag the paddle near the bottom of the stage.
Step-by-Step
6. Add this code to the paddle sprite so it moves from side to side
Insert the “mouse x” sensing block into the oval of the “set x” block
Click the green flag to test the code - move the mouse and the paddle should move left and right following the mouse
Step-by-Step
7. Add this code to make the ball sprite bounce off the paddle
Click the green flag to test the code
Choose Paddle from the drop down menu
Insert the “pick random” operator into the turn block
Step-by-Step
8. Add a line sprite.
9. Drag the paddle to the bottom of the stage.
Step-by-Step
10. Add this code to the line sprite to end the game.
Click the green flag to test the code
Choose Ball from the drop down menu
Step-by-Step
11. Click Variables and select “Make a Variable”
12. Name the variable “score” and click ok
Step-by-Step
13. Add a score variable to the ball sprite
Click the green flag to test the code
Add the variable block and choose “score” from the drop down menu.
Step-by-Step
13. Add the set score block to reset the score when the game starts.
Click the green flag to test the code
Choose score from the drop down menu
Revise
Can you make the ball move faster or slower?
Can you make this a 2 player game?
Pong Game
Can you add a way to win the game?
Debug
Does everything work the way you want it to?
Is there anything you want to change?
Add background music.
Make your own custom sprite.
Revise
Extension - Pong Tutorial
Debug
Does everything work the way you want it to?
Is there anything you want to change?
CODE BLOCKS
Show
Hide
Point towards
Move
Wait
Go to random
If/then
Sensing operator
Start sound
SKILLS
VOCABULARY
Conditionals
Random
Algorithm
Event
Vocabulary
Code Blocks
Skills
Standards
STANDARDS
CS 3AP-3b Create programs that include sequences, events, loops, and conditionals
CS 3AP-4a Break down (deconstruct) algorithms and list the steps needed to solve a problem into a sequence of tasks and sub-tasks.
CS 3AP-5e Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended
Resources
Pong Game
Sample Project:
Variations: https://scratch.mit.edu/projects/512525016
Video Tutorials: https://www.youtube.com/watch?v=eAJ3AS76ZLo&ab_channel=MITFullSTEAMAhead
Slidesgo
THANKS
Sources:
scratch.mit.edu
thenounproject.com
freepik.com
code.org
Pam Hyer
score
5