| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- // Scene - Update Every Frame
- /**
- * leftPaddle
- * if the up arrow is pressed, move the leftPaddle up
- * if the down arrow is pressed, move the leftPaddle down
- **/
- if ( isKeyPressed(Keys.upArrow) ) {
- moveY(leftPaddle, -300);
- }
- if ( isKeyPressed(Keys.downArrow) ) {
- moveY(leftPaddle, 300);
- }
- /**
- * rightPaddle
- * if the rightPaddle is below the mouse, move the rightPaddle up
- * if the rightPaddle is above the mouse, move the rightPaddle down
- **/
- if ( rightPaddle.y() > getMouseY() ) {
- moveY(rightPaddle, -300);
- }
- if ( rightPaddle.y() < getMouseY() ) {
- moveY(rightPaddle, 300);
- }
- /**
- * walls
- * if the ball touches right wall, give player 1 a point and reset the ball
- * if the ball touches left wall, give player 2 a point and reset the ball
- **/
- if (ball.isTouchingRightWall() ) {
- leftPaddle.score += 1;
- leftScoreLabel.text(leftPaddle.score);
- ball.x(400);
- ball.y(300);
- }
- if ( ball.isTouchingLeftWall() ) {
- rightPaddle.score += 1;
- rightScoreLabel.text(rightPaddle.score);
- ball.x(400);
- ball.y(300);
- }
|