Head office, Rana Pratap Bagh, Delhi011 2721 1512+91 97116 99511

Science project idea

Scratch two-player pong with paddles and a bouncing ball

The ball bounces off the walls and the paddles by changing its direction. It teaches how direction angles work and how two players share one program.

Make it yourself: 8 stepsGet a ready-made kit: Robotics and Coding

A drawing for computing and coding projects, not a photograph of this model.

What it shows

The ball bounces off the walls and the paddles by changing its direction. It teaches how direction angles work and how two players share one program.

The science

In Scratch a sprite’s direction is an angle measured clockwise from straight up. Moving steps in that direction gives the path. When a ball hits a vertical surface like a paddle, its sideways motion reverses while the up and down motion stays, which means the new direction is 0 minus the old direction. This matches the law of reflection used in light.

Materials

Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.

  • A computer, laptop or phone with a browser (free)
  • Scratch 3 in the browser at scratch.mit.edu (free, no sign-in needed to code)
  • Three sprites: a Ball and two paddles drawn as thin rectangles
  • A notebook and a pencil

Safety

Read before you start

This project uses safe, everyday materials. Still, read the rules below with a parent before you start.

Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.

All the safety rules

Step by step

8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.

  1. Draw two paddles with the Rectangle tool, tall and thin, name them Paddle1 and Paddle2, and place one at x: -220 and one at x: 220 using go to x: y: blocks.

  2. Paddle 1: when w key pressed change y by 15, and when s key pressed change y by -15.

  3. Paddle 2: when up arrow key pressed change y by 15, and when down arrow key pressed change y by -15.

  4. Make variables p1 and p2 for the scores.

  5. On the Ball (shrink it to about 30 percent with the Size box): when green flag clicked, set p1 to 0, set p2 to 0, go to x: 0 y: 0, point in direction 75.

  6. Add forever with move 6 steps and if on edge, bounce.

  7. Inside the forever add if touching Paddle1? or touching Paddle2? then point in direction (0 - (direction)) and move 10 steps.

  8. Add if x position < -225 then change p2 by 1 and go to x: 0 y: 0; add the mirror rule for x position > 225 changing p1 (these limits are checked before the ball can bounce off the side edge). Play with a friend.

What you should see

Expected result

The ball bounces between the top and bottom edges and off both paddles, and the score of the player who gets the ball past the other paddle goes up.

Viva questions

A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.

01Which angle does direction 0 mean?

Straight up.

02Why is the new direction 0 minus the old one?

A vertical bounce reverses the sideways motion, which mirrors the angle around the up direction.

03Why move 10 steps after the bounce?

To get out of the paddle so the touch is not detected again immediately.

04Where else do we see reflection like this?

Light bouncing off a mirror obeys the same equal-angle rule.

Free ebook: Viva Questions for Science Projects

Take it further

Make it your own

Increase the ball speed by 0.5 after each paddle hit using a speed variable instead of the fixed move 6.

Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.

Free ebooks for this project

Find out more about computing and coding

Free, well-known places to explore the subject further. Ask a grown-up before you sign up for anything or type your name anywhere.

WhatsApp us