Hi,
I keep getting an unreachable statement error in my 'getWorld().addObject(new Enemyfireball(),getX(),getY());' lines of code. Does anyone know how to fix this problem? Is it because you are not allowed to add the same object from the same class? The purpose for the code underneath is to keep adding a fireball whenever it hits the ground or right edge of the world.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemyfireball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemyfireball extends Actor
{ private int vSpeed;
private int hSpeed;
/**
* Act - do whatever the Enemyfireball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
plant();
moveAround();
vSpeed = Greenfoot.getRandomNumber(8);
hSpeed = 6;
}
public void moveAround()
{ setLocation(getX()+hSpeed,getY()+vSpeed);
}
public void plant()
{
if(getX()>getWorld().getWidth()-3) {
getWorld().removeObject(this);
return;
getWorld().addObject(new Enemyfireball(),getX(),getY());
}
Actor ground = getOneIntersectingObject(Ground.class);
if(ground!=null) {
getWorld().removeObject(this);
return;
getWorld().addObject(new Enemyfireball(),getX(),getY());
}
}
}
