Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. import greenfoot.*;
  2. /**
  3. *
  4. *
  5. */
  6. public class Ball extends Actor
  7. {
  8. /**
  9. * Responds to motion control from the arrow keys and removes
  10. * any buttons from the world when it intersects them.
  11. */
  12. public void act() {
  13. handleKeyPress();
  14. lookForButton();
  15. }
  16. /**
  17. * Handles input from the arrow keys.
  18. */
  19. public void handleKeyPress() {
  20. checkLeftArrow() ;
  21. checkRightArrow() ;
  22. checkUPArrow() ;
  23. checkDownArrow() ;
  24. }
  25. }
  26. /**
  27. * Checks to see if the left arrow key is being pressed.
  28. * If it is, then the ball sets its rotation angle to zero degrees
  29. * and moves backward 5 units. If it is not being pressed,
  30. * this method does nothing.
  31. */
  32. public void checkLeftArrow() {
  33. public void act() {
  34. if (Greenfoot.isKeyDown("left")
  35. {
  36. setRotation(0);
  37. turn(-5);
  38. }
  39. }
  40. }
  41. /**
  42. * Checks to see if the right arrow key is being pressed.
  43. * If it is, then the ball sets its rotation angle to zero degrees
  44. * and moves forward 5 units. If it is not being pressed,
  45. * this method does nothing.
  46. */
  47. public void checkRightArrow() {
  48. public void act() {
  49. if (Greenfoot.isKeyDown("right")
  50. {
  51. setRotation(0);
  52. turn(5);
  53. }
  54. }
  55. }
  56.  
  57. /**
  58. * Checks to see if the up arrow key is being pressed.
  59. * If it is, then the ball sets its rotation angle to 270 degrees
  60. * and moves forward 5 units. If it is not being pressed,
  61. * this method does nothing.
  62. */
  63. public void checkUpArrow() {
  64. public void act() {
  65. if (Greenfoot.isKeyDown("up")
  66. {
  67. setRotation(270);
  68. turn(5);
  69. }
  70. }
  71. }
  72.  
  73. /**
  74. * Checks to see if the down arrow key is being pressed.
  75. * If it is, then the ball sets its rotation angle to 90 degrees
  76. * and moves forward 5 units. If it is not being pressed,
  77. * this method does nothing.
  78. */
  79. public void checkDownArrow() {
  80. public void act() {
  81. if (Greenfoot.isKeyDown("down")
  82. {
  83. setRotation(90);
  84. turn(5);
  85. }
  86. }
  87. }
  88.  
  89. public class Button extends Actor
  90. {
  91.  
  92. /**
  93. * Checks to see if the ball is "touching" an object of the Button class.
  94. * If it is, then the ball removes from the World a Button that it touches.
  95. * If the ball isn't touching an object of the Button class, then this
  96. * method does nothing.
  97. */
  98. public void lookForButton() {
  99. Actor B =getOneIntersectingObject(Ball.class)
  100. if (isTouching(Ball.Class))
  101. {
  102. removeTouching(Ball.class)
  103. }
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement