javoids
Class Ship

java.lang.Object
  extended by javoids.BasicSprite
      extended by javoids.Sprite
          extended by javoids.ShieldedSprite
              extended by javoids.Ship
All Implemented Interfaces:
java.io.Serializable, Sizes

public final class Ship
extends ShieldedSprite

A space ship sprite class.

Author:
mallette
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javoids.BasicSprite
BasicSprite.Collision, BasicSprite.Gravity
 
Field Summary
protected static int AFTERBURNER_MULTIPLIER
          The amount to increase the maximum speed by when using afterburners
private static int count
          the number of these sprites already created
private  Item.Type currentItem
          the current item (GUN1 is always available)
protected static int DEFAULT_LIVES
          the defualt number of lives
protected static int DEFAULT_SIZE
          the sprite's default size
protected static int DEFAULT_VELOCITY
          the default velocity
protected static int FREE_SHIP_POINTS
          the number of points that need to be obtained before a free life is rewarded
private  int freeLives
          the number of free lives rewarded
private  int gravityDuration
          the duration for the current gravity effect
private  java.util.HashMap<Item.Type,Item> items
          a mapping of item names to items that this sprite possesses
protected static int MAX_NUMBER
          The maximum number of these sprites allowed in the game
protected static int MAX_SIZE
          the sprite's maximum size
protected static int MAXIMUM_DAMAGE_CAPACITY
          the maximum damage level
protected static int MIN_SIZE
          the sprite's minimum size
private static long serialVersionUID
          This is the version used for serializing/deserializing (storing/retrieving) this object
private  boolean soundAfterburner
          is the afterburner sound to be played?
 
Fields inherited from class javoids.BasicSprite
size
 
Constructor Summary
Ship(BasicSprite parent, Health health, Move move, int _size)
          Constructor
 
Method Summary
 void addItems(java.util.HashMap<Item.Type,Item> _items)
           
 void apply(BasicSprite sprite)
          Apply the effects of the power up to the ship
private  void checkFreeLife()
          Check to see if a free life should be awarded (takes away a death).
 void cycleWeapon(Item.Direction direction)
          Go throught the weapons until one with ammunition is found
 Item.Type getCurrentItem()
           
 int getDefaultSize()
           
 ImageMap.Name getImageNumber()
           
 java.util.HashMap<Item.Type,Item> getItems()
           
 int getMaximumSize()
           
 int getMinimumSize()
           
 int modifyDamage(int _damage)
          modify the sprite's damage level
 int modifyPoints(int points)
          modify the sprite's point total
 void move()
          Move the sprite and check for an end to gravity effects.
 void performAction(KeyMap.Action action, SpriteVector<Ship> ships, SpriteVector<Bullet> bullets, SpriteVector<Mine> mines, SpriteVector<Javoid> javoids, SpriteVector<Explosion> explosions)
          Perform a sepcified action
 void resetItems()
          reset all items to their default values
 void restore(double x, double y, double maxVelocity, double direction)
           
static void restoreCount()
          restore an item's number of uses to 0
 void setCurrentItem(Item.Type item)
           
 void setGravityDuration(int _gravityDuration)
           
 void setPoints(int points)
          set the sprite's point value
 void setSize(int _size)
          set the sprite's size
 void setSoundAfterburner(boolean _soundAfterburner)
           
 void setWeaponBest()
          set the current item to the best weapon the ship owns
 SpriteVector<Bullet> spawnBullets()
           
 void thrust(double amount)
          Push the ship forward by the amount specified
 java.lang.String toString()
          Provide a String representation of this object.
 void useAfterBurner()
          Use the ship's afterburners if possible
 SpriteVector<Bullet> useAutomaticGun()
           
 void useBomb(SpriteVector<Javoid> sprites, SpriteVector<Explosion> explosions)
           
 SpriteVector<Bullet> useGun()
           
 void useJumps()
          use a hyperspace jump to change position and direction instantly and randomly.
<E extends BasicSprite>
void
useMegaBomb(SpriteVector<E> sprites, SpriteVector<Explosion> explosions)
           
 void useShields()
          activate the ship's shields
 
Methods inherited from class javoids.ShieldedSprite
accelerate, collide, collisionDetected, draw, getMass, getShield, setDirection, setMove, setRotation, setShield, turn
 
Methods inherited from class javoids.Sprite
getAreas, getColors, getMultiplier, getOriginalImage, getShape, setAreas, setColors, setColors, setImage, setShape
 
Methods inherited from class javoids.BasicSprite
age, collisionDetected, expire, explode, getAgingRate, getAreaChecking, getColor, getDamage, getDeaths, getDirection, getDuration, getGravity, getHealth, getMaxDamage, getMaxDeaths, getMaxDuration, getMaxVelocity, getMove, getPacmanGame, getParent, getPoints, getRelativeVelocity, getRotation, getScreen, getSize, getX, getY, isAlive, isAutomaticMove, isDisplayAreas, isExploded, isGravitySource, isGravityWell, isHoming, isPlayer, isRestorable, kill, modifyDeaths, modifyDuration, setAgingRate, setAreaChecking, setAutomaticMove, setDamage, setDeaths, setDisplayAreas, setDuration, setGravity, setHealth, setHoming, setMaxDamage, setMaxDuration, setMaxLives, setMaxVelocity, setPacmanGame, setParent, setPlayer, setScreen, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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

AFTERBURNER_MULTIPLIER

protected static final int AFTERBURNER_MULTIPLIER
The amount to increase the maximum speed by when using afterburners

See Also:
Constant Field Values

MAX_NUMBER

protected static final int MAX_NUMBER
The maximum number of these sprites allowed in the game

See Also:
Constant Field Values

MAXIMUM_DAMAGE_CAPACITY

protected static final int MAXIMUM_DAMAGE_CAPACITY
the maximum damage level

See Also:
Constant Field Values

MAX_SIZE

protected static final int MAX_SIZE
the sprite's maximum size

See Also:
Constant Field Values

MIN_SIZE

protected static final int MIN_SIZE
the sprite's minimum size

See Also:
Constant Field Values

DEFAULT_SIZE

protected static final int DEFAULT_SIZE
the sprite's default size

See Also:
Constant Field Values

DEFAULT_VELOCITY

protected static final int DEFAULT_VELOCITY
the default velocity

See Also:
Constant Field Values

DEFAULT_LIVES

protected static final int DEFAULT_LIVES
the defualt number of lives

See Also:
Constant Field Values

FREE_SHIP_POINTS

protected static final int FREE_SHIP_POINTS
the number of points that need to be obtained before a free life is rewarded

See Also:
Constant Field Values

count

private static int count
the number of these sprites already created


freeLives

private int freeLives
the number of free lives rewarded


items

private java.util.HashMap<Item.Type,Item> items
a mapping of item names to items that this sprite possesses


currentItem

private Item.Type currentItem
the current item (GUN1 is always available)


gravityDuration

private int gravityDuration
the duration for the current gravity effect


soundAfterburner

private boolean soundAfterburner
is the afterburner sound to be played?

Constructor Detail

Ship

public Ship(BasicSprite parent,
            Health health,
            Move move,
            int _size)
Constructor

Parameters:
parent - the parent of this sprite
health - the health information
move - the movment information
_size - the size this should be
Method Detail

getMaximumSize

public int getMaximumSize()
Returns:
the maximum size

getMinimumSize

public int getMinimumSize()
Returns:
the minimum size

getDefaultSize

public int getDefaultSize()
Returns:
the default size

setSize

public void setSize(int _size)
Description copied from class: BasicSprite
set the sprite's size

Overrides:
setSize in class Sprite
Parameters:
_size - the size to set the sprite's size to

getItems

public java.util.HashMap<Item.Type,Item> getItems()
Returns:
a mapping of item names to items

getCurrentItem

public Item.Type getCurrentItem()
Returns:
the currently selected item

setSoundAfterburner

public void setSoundAfterburner(boolean _soundAfterburner)
Parameters:
_soundAfterburner - the sound for the ship's afterburner engine

setCurrentItem

public void setCurrentItem(Item.Type item)
Parameters:
item - the the currently selected item

setWeaponBest

public void setWeaponBest()
set the current item to the best weapon the ship owns


setGravityDuration

public void setGravityDuration(int _gravityDuration)
Parameters:
_gravityDuration - the length of time the gravity effect on the ship will last

setPoints

public void setPoints(int points)
Description copied from class: BasicSprite
set the sprite's point value

Overrides:
setPoints in class BasicSprite
Parameters:
points - the number of points to set this sprite's point total to

modifyPoints

public int modifyPoints(int points)
Description copied from class: BasicSprite
modify the sprite's point total

Overrides:
modifyPoints in class BasicSprite
Parameters:
points - the number of points to award
Returns:
the new point total

checkFreeLife

private void checkFreeLife()
Check to see if a free life should be awarded (takes away a death).


cycleWeapon

public void cycleWeapon(Item.Direction direction)
Go throught the weapons until one with ammunition is found

Parameters:
direction - the direction to cycle through the list of weapons

restore

public void restore(double x,
                    double y,
                    double maxVelocity,
                    double direction)
Parameters:
x - the x coordinate
y - the y coordinate
maxVelocity - the maximum velocity
direction - the direction the ship is facing

restoreCount

public static void restoreCount()
restore an item's number of uses to 0


thrust

public void thrust(double amount)
Push the ship forward by the amount specified

Parameters:
amount - the amount of thrust to use

move

public void move()
Move the sprite and check for an end to gravity effects.

Overrides:
move in class ShieldedSprite

modifyDamage

public int modifyDamage(int _damage)
Description copied from class: BasicSprite
modify the sprite's damage level

Overrides:
modifyDamage in class BasicSprite
Parameters:
_damage - the damage the sprite sustained
Returns:
the new damage level

performAction

public void performAction(KeyMap.Action action,
                          SpriteVector<Ship> ships,
                          SpriteVector<Bullet> bullets,
                          SpriteVector<Mine> mines,
                          SpriteVector<Javoid> javoids,
                          SpriteVector<Explosion> explosions)
Perform a sepcified action

Parameters:
action - the action to perform in the game
ships - the list of all ships in the game
bullets - the list of all bullets in the game
mines - the list of all mines in the game
javoids - the list of all javoids in the game
explosions - the list of all explosions in the game

useBomb

public void useBomb(SpriteVector<Javoid> sprites,
                    SpriteVector<Explosion> explosions)
Parameters:
sprites - the list of sprites to apply the effects of the bomb on.
explosions - the list of all explosions in the game

useMegaBomb

public <E extends BasicSprite> void useMegaBomb(SpriteVector<E> sprites,
                                                SpriteVector<Explosion> explosions)
Type Parameters:
E - the type of sprite being exploded
Parameters:
sprites - the list of sprites to apply the effects of the bomb on.
explosions - the list of all explosions in the game

useJumps

public void useJumps()
use a hyperspace jump to change position and direction instantly and randomly.


useShields

public void useShields()
activate the ship's shields


useAfterBurner

public void useAfterBurner()
Use the ship's afterburners if possible


useGun

public SpriteVector<Bullet> useGun()
Returns:
fire the ship's gun

useAutomaticGun

public SpriteVector<Bullet> useAutomaticGun()
Returns:
use the ship's gun automatically if not player controlled

spawnBullets

public SpriteVector<Bullet> spawnBullets()
Returns:
create the bullets from one use of the gun

apply

public void apply(BasicSprite sprite)
Apply the effects of the power up to the ship

Parameters:
sprite - the power up to use

addItems

public void addItems(java.util.HashMap<Item.Type,Item> _items)
Parameters:
_items - the list of items to add the the ship's list

getImageNumber

public ImageMap.Name getImageNumber()
Specified by:
getImageNumber in class Sprite
Returns:
the image name for the image currently being used

resetItems

public void resetItems()
reset all items to their default values


toString

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

Overrides:
toString in class ShieldedSprite
Returns:
String A representation of the object for debugging.