Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Rock

By: a guest on Jan 24th, 2014  |  syntax: None  |  size: 1.54 KB  |  views: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }