Hints For The Game of Pong
Examine the starter file where a rectangular paddle sprite and a circular ball sprite have been created for you.
-
Write the code for the paddle first. The paddle should be allowed to move only up and down near the right edge of the screen. When the user presses the up/down arrow keys on the keyboard, the paddle should move up or down a certain amount but it should never wander off the edges of the screen. You may find the following blocks useful.
-
The code for the ball is a bit trickier due to the paddle bounce.
Initialize the ball to appear in the middle of the screen and give it a random direction. Then check if the ball is at the edge of the screen or is touching the paddle. In each case the ball needs to bounce. Snap! already provides you with a block for bouncing off the edges of the screen.
You can write the code for the ball bouncing off the paddle by realizing that the ball bounces from the paddle with the negative of the direction at which it hits the paddle. Remember that in Snap! positive angles are measured clockwise from the 0°, up direction, and negative angles are measured counterclockwise from the 0°, up direction.
Now write the code for the ball. You may find the following blocks useful.