04-03 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Scene - Update Every Frame
  2. /**
  3. * leftPaddle
  4. * if the up arrow is pressed, move the leftPaddle up
  5. * if the down arrow is pressed, move the leftPaddle down
  6. **/
  7. if ( isKeyPressed(Keys.upArrow) ) {
  8. moveY(leftPaddle, -300);
  9. }
  10. if ( isKeyPressed(Keys.downArrow) ) {
  11. moveY(leftPaddle, 300);
  12. }
  13. /**
  14. * rightPaddle
  15. * if the rightPaddle is below the mouse, move the rightPaddle up
  16. * if the rightPaddle is above the mouse, move the rightPaddle down
  17. **/
  18. if ( rightPaddle.y() > getMouseY() ) {
  19. moveY(rightPaddle, -300);
  20. }
  21. if ( rightPaddle.y() < getMouseY() ) {
  22. moveY(rightPaddle, 300);
  23. }
  24. /**
  25. * walls
  26. * if the ball touches right wall, give player 1 a point and reset the ball
  27. * if the ball touches left wall, give player 2 a point and reset the ball
  28. **/
  29. if (ball.isTouchingRightWall() ) {
  30. leftPaddle.score += 1;
  31. leftScoreLabel.text(leftPaddle.score);
  32. ball.x(400);
  33. ball.y(300);
  34. }
  35. if ( ball.isTouchingLeftWall() ) {
  36. rightPaddle.score += 1;
  37. rightScoreLabel.text(rightPaddle.score);
  38. ball.x(400);
  39. ball.y(300);
  40. }