Class Creature

java.lang.Object
  extended by greenfoot.Actor
      extended by Creature

public class Creature
extends greenfoot.Actor

A creature in a simulation. The creature has a known home. It can move and head towards or away from home. Movement of the creature is arranged by storing a deltaX/deltaY pair: the offsets in the x/y direction that the creature will move in the next step. The value for these is capped by the SPEED constant: the delta values will always be in the range [-SPEED..SPEED].

Version:
1.0
Author:
mik

Constructor Summary
Creature()
           
 
Method Summary
 AntHill getHomeHill()
          Get the home hill of this creature.
 void headTowards(greenfoot.Actor target)
          Adjust the walking direction to head towards the given actor.
 void randomWalk()
          Walk around randomly.
 void setHomeHill(AntHill homeHill)
          Set the home hill of this creature.
 void walk()
          Walk forward in the current direction with the current speed.
 void walkAwayFromHome()
          Try to walk away from home.
 void walkTowardsHome()
          Try to walk home.
 
Methods inherited from class greenfoot.Actor
act, addedToWorld, getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getX, getY, intersects, setImage, setImage, setLocation, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Creature

public Creature()
Method Detail

getHomeHill

public AntHill getHomeHill()
Get the home hill of this creature.


headTowards

public void headTowards(greenfoot.Actor target)
Adjust the walking direction to head towards the given actor.


randomWalk

public void randomWalk()
Walk around randomly.


setHomeHill

public void setHomeHill(AntHill homeHill)
Set the home hill of this creature.


walk

public void walk()
Walk forward in the current direction with the current speed. (Does not change direction or speed.)


walkAwayFromHome

public void walkAwayFromHome()
Try to walk away from home. (Goes occasionally off course a little.)


walkTowardsHome

public void walkTowardsHome()
Try to walk home. Sometimes creatures get distracted or encounter small obstacles, so they occasionally head in a different direction for a moment.