I'm trying to stop one Greep at a tomato while the others take the tomato back to them but I can't get a Greep to stop at the tomato. Please help!
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
/**
* An Alien is an alien creature that likes to collect tomatoes.
*
* @author (your name here)
* @version 0.1
*/
public class Alien extends Creature
{
// Remember: you cannot extend the Alien's memory. So:
// no additional fields (other than final fields) allowed in this class!
/**
* Default constructor for testing purposes.
*/
public Alien()
{
this(null);
}
/**
* Create an Alien with its home space ship.
*/
public Alien(Ship ship)
{
super(ship);
}
/**
* Do what a Alien's gotta do.
*/
public void act()
{
super.act(); // do not delete! leave as first statement in act().
returnToShip();
reachedWater();
bounceOffWalls();
stopAtTomato();
if(carryingTomato())
{
if(atShip())
{
dropTomato();
reachedWater();
stopAtTomato();
}
else
{
move();
reachedWater();
turnHome();
bounceOffWalls();
stopAtTomato();
}
}
else
{
move();
checkFood();
reachedWater();
bounceOffWalls();
stopAtTomato();
}
}
/**
* Is there any food here where we are? If so, try to load some!
*/
public void checkFood()
{
// check whether there's a tomato pile here
TomatoPile tomatoPile = (TomatoPile) getOneIntersectingObject(TomatoPile.class);
if(tomatoPile != null)
{
loadTomato();
setImage("alien-with-food.png");
turnHome();
setFlag(1, true);
stopAtTomato();
}
}
/**
* This method specifies the name of the author (for display on the result board).
*/
public static String getAuthorName()
{
return "Keegan Grandel"; // write your name here!
}
/**
* This method specifies the image we want displayed at any time. (No need
* to change this for the competition.)
*/
public String getCurrentImage()
{
if(carryingTomato())
{
return "alien-with-food.png";
}
else
{
return "alien.png";
}
}
public void bounceOffWalls()
{
int yCoord = getY();
if(yCoord <= 0 || yCoord >= 599)
{
turn(45);
}
int xCoord = getX();
if(xCoord <= 0 || xCoord >= 799)
{
turn(20);
}
}
public void returnToShip()
{
Actor ship = getOneIntersectingObject(Ship.class);
if(ship != null)
{
setImage("alien.png");
}
}
public void reachedWater()
{
if(atWater())
{
if(carryingTomato() == true)
{
turnHome();
}
if(carryingTomato() == false)
{
turn(45);
move();
}
}
}
public void stopAtTomato()
{
Alien alien = (Alien) getOneIntersectingObject(Alien.class);
if(!getFlag(1))
{
move();
}
else
{
if(getFlag(1))
{
stop();
}
}
}
public void stop()
{
move(0);
}
}
