http://www.greenfoot.org/scenarios/10331
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy extends Actor
{
/**
* Act - do whatever the Enemy 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);
Actor avatar;
avatar = getOneIntersectingObject( Avatar.class );
{
AvoiderWorld world = (AvoiderWorld) getWorld();
world.endGame();
world.removeObject(avatar);
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy extends Actor
{
/**
* Act - do whatever the Enemy 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);
Actor avatar;
avatar = getOneIntersectingObject( Avatar.class );
if(avatar != null){
AvoiderWorld world = (AvoiderWorld) getWorld();
world.endGame();
world.removeObject(avatar);
}
}
}
if(getY() > getWorld().getHeight()-5) {
getWorld().removeObject(this);
}