Student Subscription site screenshot Subscribe now

Subscribe to our Student Site to access all of our Games Coding Lessons for just £8 per month


Scratch game making lesson 102b

Ping pong - advanced

In this lesson you will a version of the old 2 player ping pong game. Each player will have a paddle and attempt to return the ball without it hitting their end zone.

 

NOTE: You must use Scratch 3 or higher.

 

Complete these steps ..

 

1. Open Scratch, OR use File > New to create a new game ..

 

 

2. Download, save and then open this game file ..

 

 

3. Select the Stage and add this code ..

 

 

4. Select the How to play sprite and add this code ..

 

Test your game. Press the B key to begin and show the How to play sprite, and then the press the space-bar to hide it.

 

 

5. Create these variables ("for all sprites") ..

 

Right click the player 1 score and player 2 score displays on the stage and select large readout, then position them like this ..

 

 

6. Select the Paddle 1 sprite and add this code ..

 

Now add this code ..

 

Press the B key on your keyboard to test your code.

When you are ready, press the E key to end your game and continue working on it.

 

 

7. Duplicate all the Paddle 1 code/scripts to Paddle 2 and edit the go to x value so this paddle is positioned on the right side of the stage, and the key pressed scripts so that player two can use the up and down arrow keys to control their paddle ..

 

Press the B key on your keyboard to test your code.

Use the W, S, Up arrow and Down arrow keys to text they are moving correctly too.

When you are ready, press the E key to end your game and continue working on it.

 

 

8. Use File > Save to your computer to save your game. Name it Ping pong v1.sb3 ..

 

 

9. Select the Ball sprite and add this code ..

 

Now add the code to control the speed of the ball and to make it increase every 15 seconds ..

 

Now add this movement code ..

 

It will be useful to see the Direction the ball is travelling, so turn on it's Direction property display ..

 

Now, begin your game and watch the Direction display.

You will notice that when the ball is moving right, Direction shows positive numbers and when the ball is moving left, Direction shows negative numbers.

Also, notice the range of numbers when it is moving right or left (x axis) and up or down (y axis).

We need the Ball to bounce correctly from the Paddles whatever direction it hits them from.

 

Now complete the movement code you have already created by adding the if code for when it is touching the Paddles ..

 

Press the B key on your keyboard to test your code.

When you are ready, press the E key to end your game and continue working on it.

 

Next add the code to hide the variables when the How to play sprite is showing ..

 

Finally add the code to set the score variables and change them ..

Press the B key on your keyboard to test your code.

When you are ready, press the E key to end your game and continue working on it.

 

 

10. Use File > Save to your computer to re-save your game.

 

 

11. Well done, you're finished!