KEY SKILLS: Animation | Responding to keyboard input | Objects reacting to their environment
VIDEO OF PROGRAM IN ACTION
A, Z are user 1’s controls. M, K for user 2. R starts a new game.
Key Process:
Created the virtual environment by creating shapes for the paddles and ball. Gave each shape an initial location
When key ‘A’ is pressed, decreased the left paddle’s location by a set paddle velocity. Similarly, changed the respective paddle position for ‘Z’ ‘M’ and ‘K’
Set paddle boundries so the shape never goes off the screen.
Constantly added a ball velocity value to the ball’s x & y location
If the ball hits the screen’s top/bottom or a paddle, flip the ball's direction by adding a negative sign to the ball velocity
If the ball hits the screen’s edge on the right/left side, stop accepting user input and print Game Over
When ‘R’ is pressed, reset the location of all shapes to their initial location. Force quit program when ‘Q’ is pressed