9.11. The Pong Game (Optional)

Time Estimate: 45 minutes

9.11.1. Preview

(Teacher Tube version)
Pong was one of the first computer games. It consists of a paddle controlled by the user and a ball. In its simplest form the ball bounces off the four walls and the user tries to keep the ball from hitting the bottom wall. When the ball hits the bottom wall, the game is over. Variations of the game include keeping score, multiple lives, increasing the ball’s speed, sound effects, and so on.

Objectives: In this lesson you will learn to :

  • make incremental additions to an existing program;
  • understand that if/else is a selection control structures in algorithms;
  • define and use a procedure with a parameter;
  • define an if/else statement to evaluate more than one condition.

9.11.2. Tutorial or Basic Pong App

For this lesson you have a choice, you can follow some video tutorials that guide you through building the Pong game from scratch. Or you can start with a basic version of the game and add some enhancements. No matter which option you choose, by the end of this lesson you will have built a pretty cool mobile Pong game that keeps score and plays sound effects.

Option 1: Build Pong from Scratch

To follow the video tutorials, open App Inventor in a separate tab and then click on the top of the thumbnails to open each tutorial as full-screen videos. When finished with the basic app, add the enhancements listed after Option 2.

1. Moving the ball
2. Random movement
3. Bounce off edges
4. Moving the paddle
5. Keeping score

Option 2: Enhance a Basic Pong App

If you take this route, we will start with a basic Pong app, in which a ball will move around the canvas, bouncing off the edges and the paddle. You will add several enhancements to the game, such as keeping score and sound effects.

To begin, open the notes for this lesson in a separate tab. Then open App Inventor with the Pong Basic template. The notes provide an overview of the code for the Basic Pong app.


Implement the following enhancements using the suggestions below.

  1. Keeping Score: Add a procedure with a parameter and other statements to the code to perform score keeping tasks. (Note: already completed in Option 1.)
  2. Ending the Game: Modify the when Ball1.EdgeReached block to end the game when the ball reaches the bottom edge.
  3. Add Sound Effects: Using the sound files included with the template, add effects for the ball hitting the bottom wall, an edge, and the paddle.
  4. Advanced: Allow the user turn the sound on/off.

9.11.3. Self-Check

9.11.4. Reflection: For Your Portfolio

In your portfolio, create a new page named Pong under the Reflections category and answer the following questions:

  1. Describe and provide pseudocode for the procedure you defined to keep score (Enhancement #1).
  2. Describe and provide pseudocode for the algorithm you defined to handle the sound on/off checkbox.
Be sure to provide screenshots along with your explanations for each of the enhancements that you made.