se.liu.student.kimgr905.tilegame.sprites
Class Sprite

java.lang.Object
  extended by se.liu.student.kimgr905.tilegame.sprites.Sprite
Direct Known Subclasses:
PowerUp, Ship, Shot

public class Sprite
extends java.lang.Object

A sprite is a object with a Animation, and information about x and y-position as well as velocity and current state.


Field Summary
(package private)  Animation anim
           
private  float dx
           
private  float dy
           
private  int state
           
static int STATE_DEAD
          The Sprite is dead.
static int STATE_EXPLODING
          The Sprite is exploding.
static int STATE_NORMAL
          The Sprite is normal.
static int STATE_SHOOTING
          The Sprite is shooting.
private  float x
           
private  float y
           
 
Constructor Summary
Sprite(Animation anim)
          Creates a new Sprite object with the specified Animation.
 
Method Summary
 java.lang.Object clone()
          Clone is used to make a deepcopy of this Sprite.
 int getHeight()
          Gets this Sprite's height, based on the size of the current image.
 java.awt.Image getImage()
          Gets this Sprite's current image.
 int getState()
          Gets the state of this Creature.
 float getVelocityX()
          Gets the horizontal velocity of this Sprite in pixels per millisecond.
 float getVelocityY()
          Gets the vertical velocity of this Sprite in pixels per millisecond.
 int getWidth()
          Gets this Sprite's width, based on the size of the current image.
 float getX()
          Gets this Sprite's current x position.
 float getY()
          Gets this Sprite's current y position.
 boolean isAlive()
          The ship is alive if it's state is STATE_NORMAL or STATE_SHOOTING.
 void setState(int state)
          Sets the state of this SPRITE to STATE_NORMAL, STATE_SHOOTING, STATE_EXPLODING or STATE_DEAD.
 void setVelocityX(float dx)
          Sets the horizontal velocity of this Sprite in pixels per millisecond.
 void setVelocityY(float dy)
          Sets the vertical velocity of this Sprite in pixels per millisecond.
 void setX(float x)
          Sets this Sprite's current x position.
 void setY(float y)
          Sets this Sprite's current y position.
 void update(long elapsedTime)
          Updates this Sprite's Animation and its position based on the velocity.
 
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
The Sprite is normal.

See Also:
Constant Field Values

STATE_DEAD

public static final int STATE_DEAD
The Sprite is dead.

See Also:
Constant Field Values

STATE_EXPLODING

public static final int STATE_EXPLODING
The Sprite is exploding.

See Also:
Constant Field Values

STATE_SHOOTING

public static final int STATE_SHOOTING
The Sprite is shooting.

See Also:
Constant Field Values

anim

Animation anim

x

private float x

y

private float y

dx

private float dx

dy

private float dy

state

private int state
Constructor Detail

Sprite

public Sprite(Animation anim)
Creates a new Sprite object with the specified Animation.

Parameters:
anim - Animation
Method Detail

update

public void update(long elapsedTime)
Updates this Sprite's Animation and its position based on the velocity.

Parameters:
elapsedTime - the time elapsed since the last update in ms

getX

public final float getX()
Gets this Sprite's current x position.

Returns:
x position

getY

public final float getY()
Gets this Sprite's current y position.

Returns:
y position

setX

public final void setX(float x)
Sets this Sprite's current x position.

Parameters:
x - x position

setY

public final void setY(float y)
Sets this Sprite's current y position.

Parameters:
y - y position

getWidth

public final int getWidth()
Gets this Sprite's width, based on the size of the current image.

Returns:
the sprite's width

getHeight

public final int getHeight()
Gets this Sprite's height, based on the size of the current image.

Returns:
the sprite's height

getVelocityX

public final float getVelocityX()
Gets the horizontal velocity of this Sprite in pixels per millisecond.

Returns:
x velocity

getVelocityY

public final float getVelocityY()
Gets the vertical velocity of this Sprite in pixels per millisecond.

Returns:
y velocity

setVelocityX

public final void setVelocityX(float dx)
Sets the horizontal velocity of this Sprite in pixels per millisecond.

Parameters:
dx - see above

setVelocityY

public final void setVelocityY(float dy)
Sets the vertical velocity of this Sprite in pixels per millisecond.

Parameters:
dy - see above

getImage

public final java.awt.Image getImage()
Gets this Sprite's current image.

Returns:
the sprite's image

clone

public java.lang.Object clone()
Clone is used to make a deepcopy of this Sprite.

Overrides:
clone in class java.lang.Object
Returns:
a deepcopy of this sprite

getState

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

Returns:
current state

setState

public void setState(int state)
Sets the state of this SPRITE to STATE_NORMAL, STATE_SHOOTING, STATE_EXPLODING or STATE_DEAD.

Parameters:
state - current state

isAlive

public final boolean isAlive()
The ship is alive if it's state is STATE_NORMAL or STATE_SHOOTING. If it's STATE_EXPLODING or STATE_DEAD the method will return false.

Returns:
is the ship dead or alive