Ping Pong Game (Multiplayer game)
Scratch
Abhinav (WiSE program)
In this Game……
We will make a multiplayer game (ping pong)
One player has the controls w and s to control the paddle
The other player has up arrow and down arrow to control the paddle
Concepts used – The concept of direction
Background
Sprites (Two Paddles)
Code for player 1 to move the paddle
Code for Player 2 to move the paddle
Giving the code to the Ball to start moving
Initial Direction of the Ball
This is the initial direction of the Ball
180 degrees is facing downward
This is 250 (180 + 70). So the ball can start moving anywhere between this area
This is 110 (180 - 70). So the ball can start moving anywhere between this area
Code for Ball to bounce off the paddle
Some examples
Lets say direction was 120. This means it goes in the direction of 120 and when it touches paddle it will reflect back on direction 310 = -50 (120 + 180 + 10). This will keep continuing so next direction will be 140 (180 + (-50) + 10) and so on……
Lets say direction was 210 (-150). This means it goes in the direction of -150 and when it touches the paddle it will reflect back on direction 40 (-150 + 180 – 10). This keeps on continuing and the next direction will be 230 (40 + 180 + 10) and so on......
Giving score to Player 1
Giving score to player 2
Link for the Ping Pong Game