javoids
Class BasicSprite

java.lang.Object
  extended by javoids.BasicSprite
All Implemented Interfaces:
java.io.Serializable, Sizes
Direct Known Subclasses:
Sprite

public abstract class BasicSprite
extends java.lang.Object
implements java.io.Serializable, Sizes

Common anscestor for all game sprites

Author:
mallette
See Also:
Serialized Form

Nested Class Summary
static class BasicSprite.Collision
          Type of collision interaction
static class BasicSprite.Gravity
          Type of gravity interaction
 
Field Summary
private  boolean automaticMove
          is the sprite supposed to move automatically?
private  boolean displayAreas
          should the areas be displayed (drawn) for this sprite
private  boolean exploded
          was the sprite exploded (destroyed)
private  BasicSprite.Gravity gravity
          the gravity type of the sprite
private  Health health
          the sprite's health information
private  boolean homing
          is the sprite a homing sprite?
private static boolean isAreaChecking
          should the actual object's area be used for collision detection rather than a bounding circle?
private static boolean isPacmanGame
          is this a special pacman game?
private  Move move
          the movement information
private  BasicSprite parent
          what is the parent sprite to this sprite?
private  boolean player
          is this sprite a player?
private  int points
          the number of points this sprite is worth when shot
private  double rotationAngle
          theamount to rotate when turning
private static long serialVersionUID
          This is the version used for serializing/deserializing (storing/retrieving) this object
protected  int size
          the sprite size
 
Constructor Summary
BasicSprite(BasicSprite _parent, Health _health, Move _move, int _size)
           
 
Method Summary
 void accelerate(double acceleration)
           
 void age()
          make the sprite age
 int collide(BasicSprite sprite, BasicSprite.Collision collisionType)
           
 BasicSprite.Collision collisionDetected(BasicSprite sprite)
           
abstract  void draw(java.awt.Graphics2D g2d, java.awt.Graphics2D foregroundImage)
           
 void expire()
          make the sprite expire (maximum duration reached)
<E extends BasicSprite>
java.util.Collection<E>
explode()
          Override this method to have a larger object break up into more pieces.
 int getAgingRate()
           
static boolean getAreaChecking()
          Is the game using area checking?
abstract  java.util.Vector<java.awt.geom.Area> getAreas()
           
 java.awt.Color getColor()
           
abstract  java.util.Vector<java.awt.Color> getColors()
           
 int getDamage()
           
 int getDeaths()
           
 double getDirection()
           
 int getDuration()
           
 BasicSprite.Gravity getGravity()
           
 Health getHealth()
           
 double getMass()
           
 int getMaxDamage()
           
 int getMaxDeaths()
           
 int getMaxDuration()
           
 double getMaxVelocity()
           
 Move getMove()
           
abstract  double getMultiplier()
           
static boolean getPacmanGame()
          Is the game running in pacman mode?
 BasicSprite getParent()
           
 int getPoints()
           
 double getRelativeVelocity(BasicSprite basicSprite)
           
 double getRotation()
           
 java.awt.Rectangle getScreen()
           
 int getSize()
           
 double getX()
           
 double getY()
           
 boolean isAlive()
          is the sprite health
 boolean isAutomaticMove()
          is the sprite moving by itself?
 boolean isDisplayAreas()
          is the sprite supposed to display it's areas?
 boolean isExploded()
           
 boolean isGravitySource()
          is the sprite a gravity source
 boolean isGravityWell()
          is the sprite a gravity well
 boolean isHoming()
          is the sprite a homing sprite
 boolean isPlayer()
          is the sprite a player?
 boolean isRestorable()
           
 void kill()
          make the sprite die
 int modifyDamage(int damage)
          modify the sprite's damage level
 int modifyDeaths(int deaths)
          modify the sprite's lives
 int modifyDuration(int duration)
          modify the sprite's duration
 int modifyPoints(int _points)
          modify the sprite's point total
 void move()
          move the sprite (apply changes based on the velocity, ageing rate, and any rotation)
 void setAgingRate(int agingRate)
          set the sprite's aging rate
static boolean setAreaChecking(boolean _isAreaChecking)
          Set area checking value (should the game check a sprite's actual area rather than a bounding circle)
 void setAutomaticMove(boolean _automaticMove)
          set the sprite's value to say if it should move automatically
 void setDamage(int damage)
          set the sprite's damage level
 void setDeaths(int lives)
          set the sprite's lives
 void setDirection(double direction)
          set the sprite's direction
 void setDisplayAreas(boolean _displayAreas)
          set the sprite's value to say if it should display the sprite's areas when drawing an image (for debugging)
 void setDuration(int duration)
          set the sprite's duration
 void setGravity(BasicSprite.Gravity _gravity)
          set the sprite's gravity
 void setHealth(Health _health)
          set the sprite's health information
 void setHoming(boolean _homing)
          set the sprite's value to determine if it is a homing sprite or not
 void setMaxDamage(int maxDamage)
          set the sprite's maximum damage level
 void setMaxDuration(int maxDuration)
          set the sprite's maximum duration
 void setMaxLives(int maxLives)
          set the sprite's maximum lives
 void setMaxVelocity(double maxVelocity)
          set the sprite's maximum velocity
 void setMove(Move _move)
          set the sprite's movement information
static boolean setPacmanGame(boolean _isPacmanGame)
          Set pacman game value
 void setParent(BasicSprite _parent)
          set the sprite's parent
 void setPlayer(boolean _player)
          set the sprite's value to say if it is a player or not
 void setPoints(int _points)
          set the sprite's point value
 void setRotation(double _rotationAngle)
          set the sprite's rotation amount
 void setScreen(java.awt.Rectangle screen)
          set the sprite's screen size
abstract  void setSize(int _size)
          set the sprite's size
 void setX(double x)
          set the sprite's x coordinate
 void setY(double y)
          set the sprite's y coordinate
 java.lang.String toString()
          Provide a String representation of this object.
 void turn(double turn_direction, double n)
          turn the sprite to a new direction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javoids.Sizes
getDefaultSize, getMaximumSize, getMinimumSize
 

Field Detail

serialVersionUID

private static final long serialVersionUID
This is the version used for serializing/deserializing (storing/retrieving) this object

See Also:
Constant Field Values

isAreaChecking

private static boolean isAreaChecking
should the actual object's area be used for collision detection rather than a bounding circle?


isPacmanGame

private static boolean isPacmanGame
is this a special pacman game?


exploded

private transient boolean exploded
was the sprite exploded (destroyed)


health

private Health health
the sprite's health information


automaticMove

private boolean automaticMove
is the sprite supposed to move automatically?


displayAreas

private boolean displayAreas
should the areas be displayed (drawn) for this sprite


gravity

private BasicSprite.Gravity gravity
the gravity type of the sprite


homing

private boolean homing
is the sprite a homing sprite?


move

private Move move
the movement information


parent

private BasicSprite parent
what is the parent sprite to this sprite?


player

private boolean player
is this sprite a player?


points

private int points
the number of points this sprite is worth when shot


rotationAngle

private double rotationAngle
theamount to rotate when turning


size

protected int size
the sprite size

Constructor Detail

BasicSprite

public BasicSprite(BasicSprite _parent,
                   Health _health,
                   Move _move,
                   int _size)
Parameters:
_parent - null if this is a top level sprite. pointer to this sprite's parent sprite otherwise (it's a bullet that belong to the parent)
_health - initial value of the sprite's health and life expectency
_move - initial location, direction etc.
_size - initial size of sprite
Method Detail

accelerate

public void accelerate(double acceleration)
Parameters:
acceleration - how much to increase the velocity by

kill

public void kill()
make the sprite die


expire

public void expire()
make the sprite expire (maximum duration reached)


age

public void age()
make the sprite age


isExploded

public boolean isExploded()
Returns:
was the sprite blown up (exploded) or not?

isRestorable

public boolean isRestorable()
Returns:
whether or not the object can be restored (i.e. it has lives left)

collide

public int collide(BasicSprite sprite,
                   BasicSprite.Collision collisionType)
Parameters:
sprite - The sprite that is colliding into this sprite.
collisionType - The type of interaction required for this collision (shield on shield etc).
Returns:
the number of points obtained from the collision

collisionDetected

public BasicSprite.Collision collisionDetected(BasicSprite sprite)
Parameters:
sprite - did this sprite collide with another sprite?
Returns:
the type of collision (none, shield to shield, shield to sprite, sprite to sprite)

draw

public abstract void draw(java.awt.Graphics2D g2d,
                          java.awt.Graphics2D foregroundImage)
Parameters:
g2d - the graphics context
foregroundImage - the buffer where drawing is performed

getAgingRate

public int getAgingRate()
Returns:
the rate that the sprite ages

explode

public <E extends BasicSprite> java.util.Collection<E> explode()
Override this method to have a larger object break up into more pieces. You must call super.explode() right after you check to see if it was exploded or not or you may have numerous explosions happening due to thread interactions.

Type Parameters:
E - the type of sprite being exploded
Returns:
null (this should be overridden)

getHealth

public Health getHealth()
Returns:
the health status of this sprite

getAreaChecking

public static boolean getAreaChecking()
Is the game using area checking?

Returns:
true/false

getAreas

public abstract java.util.Vector<java.awt.geom.Area> getAreas()
Returns:
The areas that make up the sprite's shape.

getColor

public java.awt.Color getColor()
Returns:
the color of the sprite should use to draw something (changes based on damage and duration remaining)

getColors

public abstract java.util.Vector<java.awt.Color> getColors()
Returns:
The colors that match each shape that make up the sprite's shape.

getDirection

public double getDirection()
Returns:
the direction (0 (and 360) are up on screen, 90 is right on screen, 180 is down on screen, 270 is left on screen)

getGravity

public BasicSprite.Gravity getGravity()
Returns:
what type of gravity this sprite has ( sink, source, none)

getDamage

public int getDamage()
Returns:
the sprite's damage level (0 is dead currently)

getDuration

public int getDuration()
Returns:
return the spite's liftime remaining

getDeaths

public int getDeaths()
Returns:
return the number of lives the sprite has left

getMass

public double getMass()
Returns:
return the mass of the sprite (used for calculating damage)

getMaxDamage

public int getMaxDamage()
Returns:
the maximum damage the sprite can take before being destroyed

getMaxDuration

public int getMaxDuration()
Returns:
the maximum amount of ticks the sprite can live

getMaxDeaths

public int getMaxDeaths()
Returns:
the maximum number of lives this sprite can ever have

getMaxVelocity

public double getMaxVelocity()
Returns:
the maximum velocity the sprite can attain

getMove

public Move getMove()
Returns:
the position and velocity information for the sprite

getMultiplier

public abstract double getMultiplier()
Returns:
the scaling factor to use for drawing the sprite

getPacmanGame

public static boolean getPacmanGame()
Is the game running in pacman mode?

Returns:
true/false

getParent

public BasicSprite getParent()
Returns:
the owning sprite of this sprite

getPoints

public int getPoints()
Returns:
the number of points the sprite is worth

getRelativeVelocity

public double getRelativeVelocity(BasicSprite basicSprite)
Parameters:
basicSprite - the other sprite that the velocity is being measured relative to
Returns:
the relative velocity between the two sprites

getRotation

public double getRotation()
Returns:
the angle to rotate when turning

getScreen

public java.awt.Rectangle getScreen()
Returns:
the screen size

getSize

public int getSize()
Returns:
the size of this sprite

getX

public double getX()
Returns:
the horizontal position of the sprite on the screen (x-axis)

getY

public double getY()
Returns:
the vertical position of the sprite on the screen (y-axis)

isAlive

public boolean isAlive()
is the sprite health

Returns:
is the sprite health?

isAutomaticMove

public boolean isAutomaticMove()
is the sprite moving by itself?

Returns:
is the sprite moving by itself?

isDisplayAreas

public boolean isDisplayAreas()
is the sprite supposed to display it's areas?

Returns:
should the game display the areas that make up drawn sprites?

isGravitySource

public boolean isGravitySource()
is the sprite a gravity source

Returns:
is the sprite a gravity source (repells objects)?

isGravityWell

public boolean isGravityWell()
is the sprite a gravity well

Returns:
is the sprite a gravity well (attracts objects)?

isHoming

public boolean isHoming()
is the sprite a homing sprite

Returns:
does the sprite seek out a target?

isPlayer

public boolean isPlayer()
is the sprite a player?

Returns:
is the sprite a player?

modifyDamage

public int modifyDamage(int damage)
modify the sprite's damage level

Parameters:
damage - the amount to modify the damage level by
Returns:
the new damage level

modifyDuration

public int modifyDuration(int duration)
modify the sprite's duration

Parameters:
duration - the amount to modify the duration by
Returns:
the new duration

modifyDeaths

public int modifyDeaths(int deaths)
modify the sprite's lives

Parameters:
deaths - the amount to modify the number of lives by
Returns:
the new number of lives

modifyPoints

public int modifyPoints(int _points)
modify the sprite's point total

Parameters:
_points - the number of points to modify the sprite's point value by
Returns:
the new point total

move

public void move()
move the sprite (apply changes based on the velocity, ageing rate, and any rotation)


setAgingRate

public void setAgingRate(int agingRate)
set the sprite's aging rate

Parameters:
agingRate - the amount to age the sprite by

setHealth

public void setHealth(Health _health)
set the sprite's health information

Parameters:
_health - the new values for the sprite's health information

setAreaChecking

public static boolean setAreaChecking(boolean _isAreaChecking)
Set area checking value (should the game check a sprite's actual area rather than a bounding circle)

Parameters:
_isAreaChecking - is the game using area checking for collision detection?
Returns:
true/false

setAutomaticMove

public void setAutomaticMove(boolean _automaticMove)
set the sprite's value to say if it should move automatically

Parameters:
_automaticMove - set the sprite to move automatically, if true, or disable it if false.

setDirection

public void setDirection(double direction)
set the sprite's direction

Parameters:
direction - setthe direction (0 (and 360) are up on screen, 90 is right on screen, 180 is down on screen, 270 is left on screen)

setDisplayAreas

public void setDisplayAreas(boolean _displayAreas)
set the sprite's value to say if it should display the sprite's areas when drawing an image (for debugging)

Parameters:
_displayAreas - set if the spr

setGravity

public void setGravity(BasicSprite.Gravity _gravity)
set the sprite's gravity

Parameters:
_gravity - the type of gravity this sprite has (source, sink, none)

setHoming

public void setHoming(boolean _homing)
set the sprite's value to determine if it is a homing sprite or not

Parameters:
_homing - the homing value (is it a homing sprite or not)

setDamage

public void setDamage(int damage)
set the sprite's damage level

Parameters:
damage - the sprite's new damage level

setDuration

public void setDuration(int duration)
set the sprite's duration

Parameters:
duration - the sprite's new duration

setDeaths

public void setDeaths(int lives)
set the sprite's lives

Parameters:
lives - the sprite's new number of lives

setMaxDamage

public void setMaxDamage(int maxDamage)
set the sprite's maximum damage level

Parameters:
maxDamage - the sprite's new maximum damage level

setMaxDuration

public void setMaxDuration(int maxDuration)
set the sprite's maximum duration

Parameters:
maxDuration - the sprite's new maximum duration

setMaxLives

public void setMaxLives(int maxLives)
set the sprite's maximum lives

Parameters:
maxLives - the sprite's new maximum number of lives

setMaxVelocity

public void setMaxVelocity(double maxVelocity)
set the sprite's maximum velocity

Parameters:
maxVelocity - the sprite's new maximum velocity

setMove

public void setMove(Move _move)
set the sprite's movement information

Parameters:
_move - the sprite's new movment information

setPacmanGame

public static boolean setPacmanGame(boolean _isPacmanGame)
Set pacman game value

Parameters:
_isPacmanGame - is the game using pacman settings?
Returns:
true/false

setParent

public void setParent(BasicSprite _parent)
set the sprite's parent

Parameters:
_parent - the sprite's new parent

setPlayer

public void setPlayer(boolean _player)
set the sprite's value to say if it is a player or not

Parameters:
_player - is this sprite a player?

setPoints

public void setPoints(int _points)
set the sprite's point value

Parameters:
_points - the sprite's new point total

setRotation

public void setRotation(double _rotationAngle)
set the sprite's rotation amount

Parameters:
_rotationAngle - the sprite's new amount to rotate by when turning

setScreen

public void setScreen(java.awt.Rectangle screen)
set the sprite's screen size

Parameters:
screen - the sprite's new screen size

setSize

public abstract void setSize(int _size)
set the sprite's size

Parameters:
_size - the sprite's new size

setX

public void setX(double x)
set the sprite's x coordinate

Parameters:
x - the sprite's new x xoordinate

setY

public void setY(double y)
set the sprite's y coordinate

Parameters:
y - the sprite's new y xoordinate

toString

public java.lang.String toString()
Provide a String representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
String A representation of the object for debugging.

turn

public void turn(double turn_direction,
                 double n)
turn the sprite to a new direction

Parameters:
turn_direction - the direction to turn
n - the amount to turn by