1 of 23

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:

  • add sprites and background
  • code a sprite to move and bounce
  • code sprites to hide and show in random locations on the screen
  • use a conditional to control response to a sensing block

Objectives/Outcome

Pong Game

Prerequisites:

Students should have foundational understanding of:

  • adding sprites
  • basic movement blocks

Vocabulary

Conditionals

Algorithm

Event

2 of 23

Project Sample

3 of 23

conditional

conditional

  • commands that only run under certain conditions
  • an action that occurs based on whether a condition is true or false

4 of 23

conditional

variables

  • A place to store a piece of data that can change.
  • A container for storing a value that can be used and updated. Variables can store numbers, text (strings) or other values.

$

24

code.org : Course 4, Lesson 6

5 of 23

Step-by-Step

Go to Clever

Open Code HS

Select the “Pong Game” Project

6 of 23

Tutorials

Video Tutorial

Coding Cards

7 of 23

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?

8 of 23

Step-by-Step

1. Add a background.

2. Add a ball sprite.

9 of 23

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

10 of 23

Step-by-Step

4. Add a paddle sprite.

5. Drag the paddle near the bottom of the stage.

11 of 23

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

12 of 23

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

13 of 23

Step-by-Step

8. Add a line sprite.

9. Drag the paddle to the bottom of the stage.

14 of 23

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

15 of 23

Step-by-Step

11. Click Variables and select “Make a Variable”

12. Name the variable “score” and click ok

16 of 23

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.

17 of 23

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

18 of 23

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.

19 of 23

Revise

Extension - Pong Tutorial

Debug

Does everything work the way you want it to?

Is there anything you want to change?

20 of 23

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

  • Create an algorithm
  • Make sprite follow mouse pointer
  • Make a sprite appear and disappear in random locations
  • Use conditionals with sensing blocks to control events

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

21 of 23

Resources

Pong Game

22 of 23

Slidesgo

THANKS

Sources:

scratch.mit.edu

thenounproject.com

freepik.com

code.org

Pam Hyer

CREDITS: This presentation template was created by Slidesgo, including icons by Flaticon, infographics & images by Freepik

23 of 23

score

5