Scratch Ping Pong Project
In this activity, we are going to build a two player Ping Pong like game using Scratch on the Raspberry Pi. There will be two paddles and a ball.
The paddles will be user controlled to try to hit the ball back the other direction to the other player.
To begin, open Scratch and delete the Cat sprite on the right hand side.
To create the backdrop, click the “Stage” section in the bottom right hand portion of the window.
Then, in the main window, click the Backgrounds tab.
Then, click the edit button, and choose your background of choice. I chose the brick wall background.
Next, we're going to create the paddles. In the bottom right hand window, click the "Paint New Sprite" button beside the text "New Sprite."
Choose the line tool and draw a vertical line in the middle of the grid then click OK.
Then, rename the line to Paddle1 at the top of the main window.
Next, under the scripts tab, drop each instruction below into the window. These instructions are found by clicking the buttons in the upper left portion of the window that have the color corresponding to the color of the instruction.
For instance, the “When <FLAG> clicked” button is under the “Control” button because it has an orange bar on the left hand side of it.
Fill in the values as seen and select the buttons to move the paddle up and down. I used “W” and “S” for player 1.
Next, right click on paddle1 in the lower right window and select duplicate. Name the new sprite paddle2.
This will create the paddle for player 2. Change the values in script as seen below. I used the up arrow and down arrow to move the paddle for player 2.
Next, we're going to create our variables for the score. Click the Variables button in the upper left windows.
Then, click the “Make a variable” button and name it Score1. Leave “For all Sprites” selected.
Repeat this and create another variable named Score2.
In the bottom right window, click the "Choose a new sprite from file" button to import a ball sprite. I chose a beach ball, but you can choose any ball you'd like.
Next, insert the script parts seen below. Take your time and make sure you get everything!