import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Rock here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rock extends Mover
{
private static final int NUM_FRAGMENTS = 50;
private int rotate = Greenfoot.getRandomNumber(9)+1;
private Counter counter;
public Rock(Counter pointCounter)
{
counter = pointCounter;
}
/**
* Act - do whatever the Rock wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(), getY()+1);// the actor's y coordinate placement is added by one each time the act button is pressed.
setRotation(getRotation () +rotate);// The rotation of Rock is increasing by randomly generated number(1-10) each time act is pressed.
move();//the rotation affects the x coordinate of Rock.
if (Greenfoot.mouseClicked(this)){
explode();
counter.setValue(counter.getValue() + 1);
}
}
public void explode()
{
placeDebris (getX(), getY(),NUM_FRAGMENTS);
getWorld(). removeObject(this);
}
private void placeDebris(int x, int y, int numFragments)
{
for (int i=0; i < numFragments; i++) {
getWorld().addObject (new Debris(), x, y );
}
}
}