Class Evolution.Animal

java.lang.Object
  extended by Evolution.Drawable
      extended by Evolution.Animal
Enclosing class:
Evolution

private class Evolution.Animal
extends Evolution.Drawable

Class for an animal

Author:
Townsend
See Also:
Evolution.Drawable

Field Summary
 Evolution.Action[] actions
           
 boolean actionsCanEvolve
           
 long born
           
 java.lang.String bundle
           
 long childrenSpawned
           
 int colour
           
 int colourAlignment
           
 boolean colourAlignmentCanEvolve
           
 boolean colourCanEvolve
           
 Evolution.Action currentAction
           
 double direction
          Direction in radians
 java.lang.Double directionAltered
           
 int generation
           
 long kills
           
 int life
           
 double rand
           
 boolean randomizeChildren
           
 double rateOfEvolution
           
 boolean rateOfEvolutionCanEvolve
           
 int sight
           
 boolean sightCanEvolve
           
 double sightFactor
           
 boolean spawnCanEvolve
           
 int spawnChildren
           
 int spawnLife
           
 long spawns
           
 java.lang.String species
           
 double speed
           
 boolean speedCanEvolve
           
 double speedFactor
           
 boolean spriteCanEvolve
           
 boolean stopped
           
 
Fields inherited from class Evolution.Drawable
id, positionX, positionY, sprite
 
Constructor Summary
Evolution.Animal()
          Constructor, sets default locations, sprite, actions, statistics
 
Method Summary
 void calculateKill()
           
 void calculateReaction()
           
private  int[] defaultSprite()
           
 void die()
           
 void drawSprite(int x, int y, int[] image)
          Draw the sprite at the specified position.
 void eat(Evolution.Plant p)
           
 int getDirection()
           
 java.lang.Double getDirectionAltered()
           
 int getPositionX()
           
 int getPositionY()
           
 int getSight()
           
 double getSpeed()
           
 int[] getSprite()
          Getter for the sprite (can be overridden)
 boolean isFriendlyTo(Evolution.Animal a)
           
 void live()
           
 void move()
          Moves a sprite to it's next position, based on direction and speed.
private  double rand()
           
 Evolution.Hazard scanForAHazard()
           
 Evolution.Plant scanForAPlant()
           
 boolean scanForHazards(double dX, double dY)
           
 void scanForPlants()
           
 void setDirection(int direction)
           
 void setDirectionAltered(java.lang.Double directionNew)
           
 void setPositionX(double positionX)
           
 void setPositionX(int positionX)
           
 void setPositionY(double positionY)
           
 void setPositionY(int positionY)
           
 void spawn()
           
 java.lang.String toString()
           
 void whoCanISee(java.util.ArrayList<Evolution.Animal> enemies, java.util.ArrayList<Evolution.Animal> friends)
           
 int whoCanSeeMe(java.util.ArrayList<Evolution.Animal> enemies, java.util.ArrayList<Evolution.Animal> friends, int range)
           
 void wipeSprite()
          Overload of wipeSprite, using the default pixel arrays.
 
Methods inherited from class Evolution.Drawable
drawSprite, drawSprite, setSprite, wipeSprite, wrapPosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

species

public java.lang.String species

bundle

public java.lang.String bundle

direction

public double direction
Direction in radians


directionAltered

public java.lang.Double directionAltered

life

public int life

rateOfEvolution

public double rateOfEvolution

rateOfEvolutionCanEvolve

public boolean rateOfEvolutionCanEvolve

colour

public int colour

colourCanEvolve

public boolean colourCanEvolve

speed

public double speed

speedCanEvolve

public boolean speedCanEvolve

stopped

public boolean stopped

speedFactor

public double speedFactor

spawnLife

public int spawnLife

spawnChildren

public int spawnChildren

spawnCanEvolve

public boolean spawnCanEvolve

sight

public int sight

sightCanEvolve

public boolean sightCanEvolve

sightFactor

public double sightFactor

colourAlignment

public int colourAlignment

colourAlignmentCanEvolve

public boolean colourAlignmentCanEvolve

spriteCanEvolve

public boolean spriteCanEvolve

currentAction

public Evolution.Action currentAction

actions

public Evolution.Action[] actions

actionsCanEvolve

public boolean actionsCanEvolve

generation

public int generation

rand

public double rand

randomizeChildren

public boolean randomizeChildren

kills

public long kills

spawns

public long spawns

childrenSpawned

public long childrenSpawned

born

public long born
Constructor Detail

Evolution.Animal

public Evolution.Animal()
Constructor, sets default locations, sprite, actions, statistics

Method Detail

defaultSprite

private int[] defaultSprite()

move

public void move()
Moves a sprite to it's next position, based on direction and speed. ... Note that I trim the sprite pixels from the max position, so it doesn't try to draw the sprite partially off the screen. I had to add the mod dividend to the divisor to allow for wrapping negative values, because Java assigns the sign of the divisor to the remainder. ie: -2 % 7 = -2, which isn't what we want, we want -2 % 7 = 5. To do that, I do (-2 + 7) % 7 = 5, which will also work for positives: (6 + 7) % 7 = 6, (11 + 7) % 7 = 4, etc...


live

public void live()

die

public void die()
Overrides:
die in class Evolution.Drawable

scanForAPlant

public Evolution.Plant scanForAPlant()

scanForPlants

public void scanForPlants()

scanForAHazard

public Evolution.Hazard scanForAHazard()

scanForHazards

public boolean scanForHazards(double dX,
                              double dY)

whoCanSeeMe

public int whoCanSeeMe(java.util.ArrayList<Evolution.Animal> enemies,
                       java.util.ArrayList<Evolution.Animal> friends,
                       int range)

whoCanISee

public void whoCanISee(java.util.ArrayList<Evolution.Animal> enemies,
                       java.util.ArrayList<Evolution.Animal> friends)

calculateKill

public void calculateKill()

calculateReaction

public void calculateReaction()

isFriendlyTo

public boolean isFriendlyTo(Evolution.Animal a)

eat

public void eat(Evolution.Plant p)

spawn

public void spawn()

drawSprite

public void drawSprite(int x,
                       int y,
                       int[] image)
Description copied from class: Evolution.Drawable
Draw the sprite at the specified position. Only draws non-background pixels, which allows for sprites to overlap (and saves a bit of work.)

Overrides:
drawSprite in class Evolution.Drawable
Parameters:
x - X Coordinate
y - Y Coordinate

wipeSprite

public void wipeSprite()
Description copied from class: Evolution.Drawable
Overload of wipeSprite, using the default pixel arrays.

Overrides:
wipeSprite in class Evolution.Drawable

getSprite

public int[] getSprite()
Description copied from class: Evolution.Drawable
Getter for the sprite (can be overridden)

Overrides:
getSprite in class Evolution.Drawable
Returns:
int array of the pixels for this sprite

getDirection

public int getDirection()

setDirection

public void setDirection(int direction)

getSight

public int getSight()

getPositionX

public int getPositionX()
Overrides:
getPositionX in class Evolution.Drawable

setPositionX

public void setPositionX(int positionX)
Overrides:
setPositionX in class Evolution.Drawable

getPositionY

public int getPositionY()
Overrides:
getPositionY in class Evolution.Drawable

setPositionY

public void setPositionY(int positionY)
Overrides:
setPositionY in class Evolution.Drawable

setPositionX

public void setPositionX(double positionX)

setPositionY

public void setPositionY(double positionY)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

rand

private double rand()

getSpeed

public double getSpeed()

getDirectionAltered

public java.lang.Double getDirectionAltered()

setDirectionAltered

public void setDirectionAltered(java.lang.Double directionNew)