Advertisement
Guest User

A.I. Pong Unexpected token: void

a guest
Dec 20th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /** this method moves the computer */
  2. public void move (Ball)
  3. {
  4. // calculate the middle of the paddle
  5. real_y_pos = y_pos + (size_y / 2);
  6.  
  7. /* If the ball is moving in opposite direction to the paddle and is no danger for computer's goal move paddle back to the middle y - position*/
  8. if (ball.getXSpeed() > 0)
  9. {
  10. // if the paddle's position is over the middle y - position
  11. if (real_y_pos < 148)
  12. {
  13. y_pos += y_speed;
  14. }
  15. // Paddle is under the middle y - position
  16. else if (real_y_pos > 152)
  17. {
  18. y_pos -= y_speed;
  19. }
  20. }
  21. // ball is moving towards paddle
  22. else if (ball.getXSpeed() < 0)
  23. {
  24. // As long as ball's y - position and paddle's y - position are different
  25. if ( real_y_pos != ball.getYPos())
  26. {
  27. // If ball's position smaller than paddle's, move up
  28. if (ball.getYPos() < real_y_pos)
  29. {
  30. y_pos -= y_speed;
  31. }
  32. // If ball's position greater than padle's, move down
  33. else if (ball.getYPos() > real_y_pos)
  34. {
  35. y_pos += y_speed;
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement