frog.demo
Class CowSprite

java.lang.Object
  extended by frog.demo.CowSprite
All Implemented Interfaces:
Sprite

public class CowSprite
extends Object
implements Sprite

Represents a single cow on the screen. CowSprites control the individual behavior of a cow which is to walk randomly about the bottom of the screen until a UFO begins to abduct the cow. CowSprite handles the animation and status of a cow as well as its position and image.

Author:
Team Better Recognize

Field Summary
static float ABDUCT_SPEED
          Cow movement speed.
static int ABDUCTED
          Status type.
static int BEING_ABDUCTED
          Status type.
 HashSet<UFOSprite> chasers
          UFOs currently chasing this cow
static float FALL_SPEED
          Cow movement speed.
static float GROUND_Y
          Cow walking Y-position
static int LEFT
          Direction type.
static int RIGHT
          Direction type.
static float SPEED
          Cow movement speed.
static int STAND
          Direction type.
static int WALKING
          Status type.
 
Constructor Summary
CowSprite(DemoGame game)
          Creates a new CowSprite with a reference to the DemoGame that it is running within.
 
Method Summary
 void addChasingUFO(UFOSprite ufo)
          Adds an additional UFO to the list of chasing UFOs.
 void draw(Graphics g)
          Draws this sprite to the given Graphics context.
 boolean equals(Object other)
           
 int getState()
          Returns the current state of this cow.
 float getX()
          Returns the current X position of this cow.
 float getY()
          Returns the current Y position of this cow.
 int kill()
          Disables this sprite's draw method.
 void setState(int state)
          Sets the state of this cow to a new one.
 void setX(float x)
          Sets the current X position of this cow.
 void setY(float y)
          Sets the current Y position of this cow.
 void update()
          Causes this sprite update its current state.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPEED

public static final float SPEED
Cow movement speed.

See Also:
Constant Field Values

ABDUCT_SPEED

public static final float ABDUCT_SPEED
Cow movement speed.

See Also:
Constant Field Values

FALL_SPEED

public static final float FALL_SPEED
Cow movement speed.

See Also:
Constant Field Values

GROUND_Y

public static final float GROUND_Y
Cow walking Y-position

See Also:
Constant Field Values

WALKING

public static final int WALKING
Status type.

See Also:
Constant Field Values

BEING_ABDUCTED

public static final int BEING_ABDUCTED
Status type.

See Also:
Constant Field Values

ABDUCTED

public static final int ABDUCTED
Status type.

See Also:
Constant Field Values

LEFT

public static final int LEFT
Direction type.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Direction type.

See Also:
Constant Field Values

STAND

public static final int STAND
Direction type.

See Also:
Constant Field Values

chasers

public final HashSet<UFOSprite> chasers
UFOs currently chasing this cow

Constructor Detail

CowSprite

CowSprite(DemoGame game)
Creates a new CowSprite with a reference to the DemoGame that it is running within.

Parameters:
game - the DemoGame that this CowSprite appears in.
Method Detail

addChasingUFO

public void addChasingUFO(UFOSprite ufo)
Adds an additional UFO to the list of chasing UFOs. Chasing UFOs have targeted this cow for abduction. If this cow is abducted by a UFO, all UFOSprites are notified.

Parameters:
ufo - a UFO that is now chasing this cow.

draw

public void draw(Graphics g)
Description copied from interface: Sprite
Draws this sprite to the given Graphics context.

Specified by:
draw in interface Sprite
Parameters:
g - the Graphics context this sprite should draw itself to.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

getState

public int getState()
Returns the current state of this cow. Possible values include:

Returns:
the current status of this cow.

getX

public float getX()
Returns the current X position of this cow.

Returns:
the current X position of this cow.

getY

public float getY()
Returns the current Y position of this cow.

Returns:
the current Y position of this cow.

setState

public void setState(int state)
Sets the state of this cow to a new one. Valid values are:

Parameters:
state - the state to set this cow to.

setX

public void setX(float x)
Sets the current X position of this cow.

Parameters:
x - a new X position for this cow.

setY

public void setY(float y)
Sets the current Y position of this cow.

Parameters:
y - a new Y position for this cow.

kill

public int kill()
Description copied from interface: Sprite
Disables this sprite's draw method. Performs any necessary clean up and displays any effects that need to appear upon this object's death. Some sprites may be worth points when they are killed. If this is the case, kill will return those points as an integer.

Specified by:
kill in interface Sprite
Returns:
number of points this sprite is worth, if any.

update

public void update()
Description copied from interface: Sprite
Causes this sprite update its current state. This may be moving by one step or adjusting it's current display picture.

Specified by:
update in interface Sprite