Advertisement
Guest User

Rock

a guest
Jan 24th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
  2.  
  3. /**
  4. * Write a description of class Rock here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class Rock extends Mover
  10. {
  11. private static final int NUM_FRAGMENTS = 50;
  12. private int rotate = Greenfoot.getRandomNumber(9)+1;
  13. private Counter counter;
  14. public Rock(Counter pointCounter)
  15. {
  16. counter = pointCounter;
  17. }
  18. /**
  19. * Act - do whatever the Rock wants to do. This method is called whenever
  20. * the 'Act' or 'Run' button gets pressed in the environment.
  21. */
  22. public void act()
  23. {
  24. setLocation(getX(), getY()+1);// the actor's y coordinate placement is added by one each time the act button is pressed.
  25. setRotation(getRotation () +rotate);// The rotation of Rock is increasing by randomly generated number(1-10) each time act is pressed.
  26. move();//the rotation affects the x coordinate of Rock.
  27. if (Greenfoot.mouseClicked(this)){
  28. explode();
  29. counter.setValue(counter.getValue() + 1);
  30. }
  31. }
  32. public void explode()
  33. {
  34. placeDebris (getX(), getY(),NUM_FRAGMENTS);
  35. getWorld(). removeObject(this);
  36.  
  37. }
  38. private void placeDebris(int x, int y, int numFragments)
  39. {
  40. for (int i=0; i < numFragments; i++) {
  41. getWorld().addObject (new Debris(), x, y );
  42.  
  43. }
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement