I'v updated the demo scenario, the project included now should have no problem.(It should works well with Eclipse and AIDE both)
If you still have problem with "@Override" things, see above.
package LandThePlane;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.util.ArrayList;
/**
* An AntiAirGuns main goal is to kill the plane.
* It tries to do this by following the planes and if the gun is loaded shoots a bullet.
* The loadtime is defined in the shootInterval variable.
* Guns get inactive when a message is displayed, this means either the player landed or died.
*
* @author Kevin van Oosterhout
* @version 1.0
*/
public class AntiAirGun extends Actor
{
private List<Plane> planes = new ArrayList();
private int counter = 0;
private int shootInterval;
private boolean active = true;
/**
* initiate the gun.
*/
public AntiAirGun(int shootInterval) {
this.shootInterval = shootInterval;
setImage("AntiAirGun.png");
}
/**
* Use the method findPlane to follow the plane and kill it.
*/
public void act()
{
if(active == true) {
findPlane();
}
}
/**
* First we read all planes in a List called planes. We follow one, this is not random,
* but we don't really care which one we follow, in our game, we'll mostly have just one plane,
* and if we have more, we're comfortable with the gun just following the last one in the List.
* Last, we call the shoot method.
*/
private void findPlane() {
planes = getWorld().getObjects(Plane.class);
for (int i=0; i < planes.size(); i++) {
Plane plane = planes.get(i);
int px = plane.getX();
int py = plane.getY();
turnTowards(px,py);
shoot(px,py);
}
}
/**
* We need to shoot the plane in order to kill it.
* First we check wether the Gun is loaded, this is the case when the counter is
* equal to or higher than the shootInterval.
* If so, we create a new Bullet and give it the correct rotation/heading,
* and place it in the world where the position of this object is. We set the counter to 0.
*
* If not, we add up 1 to our counter.
*/
private void shoot(int x, int y) {
if (counter >= shootInterval) {
getWorld().addObject(new Bullet(getRotation()),getX(), getY());
counter = 0;
} else {
counter++;
}
}
/**
* When a message is displayed, it will set the gun to inactive, we do this here.
*/
public void setInactive() {
active = false;
}
}