Hi,
I am trying to detect when the fireball hits the plant 5 times but am unsuccessful in doing so. Does anyone know how to do this? My code is shown below. Thanks for the help.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Fireball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Fireball extends Actor
{
private static final int SPEED=7;
private int a = 0;
/**
* Act - do whatever the Fireball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(SPEED);
if(getX()>getWorld().getWidth()-3) {
getWorld().removeObject(this);
return;
}
Actor plant = getOneIntersectingObject(Plant.class);
if(plant!=null) {
getWorld().addObject(new Explosion(),getX(),getY());
a++;
getWorld().removeObject(this);
return;
}
if(a==5) {
getWorld().addObject(new Hugeexplosion(),getX(),getY());
getWorld().removeObject(plant);
getWorld().removeObject(this);
return;
}
}