com.brackeen.javagamebook.tilegame.sprites
Class Creature

java.lang.Object
  extended by Sprite
      extended by com.brackeen.javagamebook.tilegame.sprites.Creature
Direct Known Subclasses:
Fly, Grub, Player

public abstract class Creature
extends Sprite

A Creature is a Sprite that is affected by gravity and can die. It has four Animations: moving left, moving right, dying on the left, and dying on the right.


Field Summary
static int STATE_DEAD
           
static int STATE_DYING
           
static int STATE_NORMAL
           
 
Constructor Summary
Creature(Animation left, Animation right, Animation deadLeft, Animation deadRight)
          Creates a new Creature with the specified Animations.
 
Method Summary
 java.lang.Object clone()
           
 void collideHorizontal()
          Called before update() if the creature collided with a tile horizontally.
 void collideVertical()
          Called before update() if the creature collided with a tile vertically.
 float getMaxSpeed()
          Gets the maximum speed of this Creature.
 int getState()
          Gets the state of this Creature.
 boolean isAlive()
          Checks if this creature is alive.
 boolean isFlying()
          Checks if this creature is flying.
 void setState(int state)
          Sets the state of this Creature to STATE_NORMAL, STATE_DYING, or STATE_DEAD.
 void update(long elapsedTime)
          Updates the animaton for this creature.
 void wakeUp()
          Wakes up the creature when the Creature first appears on screen.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_NORMAL

public static final int STATE_NORMAL
See Also:
Constant Field Values

STATE_DYING

public static final int STATE_DYING
See Also:
Constant Field Values

STATE_DEAD

public static final int STATE_DEAD
See Also:
Constant Field Values
Constructor Detail

Creature

public Creature(Animation left,
                Animation right,
                Animation deadLeft,
                Animation deadRight)
Creates a new Creature with the specified Animations.

Method Detail

clone

public java.lang.Object clone()

getMaxSpeed

public float getMaxSpeed()
Gets the maximum speed of this Creature.


wakeUp

public void wakeUp()
Wakes up the creature when the Creature first appears on screen. Normally, the creature starts moving left.


getState

public int getState()
Gets the state of this Creature. The state is either STATE_NORMAL, STATE_DYING, or STATE_DEAD.


setState

public void setState(int state)
Sets the state of this Creature to STATE_NORMAL, STATE_DYING, or STATE_DEAD.


isAlive

public boolean isAlive()
Checks if this creature is alive.


isFlying

public boolean isFlying()
Checks if this creature is flying.


collideHorizontal

public void collideHorizontal()
Called before update() if the creature collided with a tile horizontally.


collideVertical

public void collideVertical()
Called before update() if the creature collided with a tile vertically.


update

public void update(long elapsedTime)
Updates the animaton for this creature.