Make Pong- and play with a friend

To help us learn the basics of game design, we’re going all the way back to one of first arcade games – Pong!  Pong is a bit like tennis, with two paddles hitting a ball back and forth, gaining a point for a hit and losing if the ball is missed. It might be from 1972, but it can still be fun nearly 50 years later!

Try our one player version here – https://scratch.mit.edu/projects/546781306/

Remember to keep testing and tweaking your game as you go along – each game will be slightly different and as the developer you will have a sense of what works for your version!


Create Sprites

Pong involves two paddles and a ball to play. As you can see the original graphics are a little basic!

  • How can you make your version appealing?
  • Take time to design the look of your version
    • How do we bring Pong into 2021 using visuals?
    • Can you tell a story or convey a theme using two paddles and a ball?
    • Create sprites for your paddles, ball and background.

Set up the “collision” code on your ball

  • Add the code blocks above to the “ball” sprite.
  • These blocks mean the ball will know when it touches the paddles and needs to change direction – this code goes inside the “forever” block so that it keeps repeating throughout the game and the ball keeps moving.
  • It’s important to have some limitations – we’ll add code so the ball doesn’t go off the screen and so it starts in the middle in a later step.  We’ll also add the sound later.

Add a score system (to the code you have already added to the ball)

Let’s create two variables, Score and Opponent Score

  • Variables are holders for information about our game (such as the score)- the information they hold can change throughout the game.
  • Create variables by choosing “make a variable” from the variable menu – the name you give them is what will be seen on screen.  Make sure to check the box next to them to make them visible, and drag them wherever you like in the scratch stage.
  • You can right click on them to change the way they display, the three options are Normal, Large and Slider
  • For this game, choose from normal or large as a slider isn’t suitable for scoring.
  • Add blocks to the ball code to set your variables to zero for the start of the game.  Put these right under the “When clicked” block.
  • Under the “If touching” for each paddle, add in the change score by 1 block from the variable menu.
  • Make sure the correct score changes for the correct paddle.

Add Sound

      • Open the sound panel and choose a sound you like.
      • Add the start sounds block as in the image above – for when the ball touches the paddle.
        • Try different sounds to see what fits the tone of your game
        • Is there anywhere else that may benefit from sound?

Add edge detection and movement (to the code you have already added to the ball)

  • Add the code above into the code you have already added to the ball.
  • We need to know when the ball hits the sides of the scratch stage.
  • The scratch stage is 480 pixels wide by 360 pixels tall (your computer screen is made up of dots called pixels.)
  • This means the edges of the screen are represented by the X and Y co-ordinates – X -240, 240, Y -180, 180
  • The ball can bounce off the top so we only need to worry about the X values
      • If X <-230 the player looses, if X>230 the player wins
      • Once you have tested your game, you may need to change these values based on the size of your sprite.  Sometimes your eyes are better than trusting numbers alone!
  • The code inside the “repeat” block controls the speed – try changing the “10 steps” to different numbers and see what happens.

Add player paddle movement

  • The up and down arrow keys are good controls to use for your paddle.
  • You only need to set the Y values, pong paddles can only move up and down!

Set random movement for opponent

  • Let’s add code to the opponent paddle so it will move by itself.
  • We want the paddle to move up or down towards the ball if the ball is heading towards it
    • When the ball reaches the X position of  0, the middle of the screen, the paddle will move.

Adding Multiple Lives

  • From testing you may have seen the gameplay can be quite short, so let’s add multiple lives to keep the game going.
  • Duplicate your ball sprite 4 times, making them nice and small and line them up in pairs along either the bottom or top, two on the player side two on the opponent side (See above for an idea of how this should look)
  • You don’t want the movement code on these balls the  need to stay still- so delete the original code from them.
  • Go to the variables panel and create another two, Player 1 Lives and Player 2 Lives.
  • For the one ball on the player 1 side, add the code exactly as below. For one ball on player 2’s side, add the same code but remember to switch the variable to Player 2 Lives.
  • For the second balls on each side, you need the same code, but set it to “show” if the player has two lives – this way they can see how many lives they have left
  • Test your game and make sure the score is working!


Adding Multiplayer

  • Games are best played with a friend, lets add in two player controls
  • We need to remove the code from the Opponent Paddle
  • Then copy the code from the player paddle onto the opponent paddle, but change the key press to W and S
    • This allows plenty space at the keyboard for two player

Grab a friend and test the games together.

Congratulations – You’re well on your way to being a fully fledged games developer!


Pong Cabinet Image:  Rob Boudon, CC BY 2.0 via Wikimedia Commons

Pong Screenshot Image: Bumm13Vector: Beao, Public domain, via Wikimedia Commons