Class Spaceship

java.lang.Object
  extended by Actor
      extended by QuantumObject
          extended by Spaceship
Direct Known Subclasses:
AIControlledSpaceship, ManuallyControlledSpaceship

public class Spaceship
extends QuantumObject

Stuff that flies through the sky. Base class for both AI-controlled ships and manually controlled ones.


Field Summary
protected  boolean angled_guns
          Determines if guns should shoot in a straight way (angled_guns = false) or rather in a widespread way (angled_guns = true).
protected  int blink
          Variable containing the state of the blink animation that happens when the spaceship is damaged.
protected  java.lang.String blink_file
          Filename of the sprite to be used while blinking, i.
static double GUN_ANGLE
          Determines the angular distance between guns when angled_guns is true.
static int GUN_DISTANCE
          X distance between guns on one spaceship.
protected  Gun[] guns
           
protected  int hitpoints
           
protected  int level
           
protected  int max_blink
          How many turns the blinking animations should last.
protected  int max_hitpoints
           
protected  int n_guns
           
static int N_GUNS
           
protected  int side
           
 
Fields inherited from class QuantumObject
destroysOnNextTurn, disappear, mantissa, speed
 
Constructor Summary
Spaceship(int the_level)
           
 
Method Summary
 void act()
          A day in the life of a quantum object: 1.
 void addGun(int position, Gun new_gun)
          Add a gun in the given position.
 void addHitpoints(int n_hitpoints)
           
 double angle(double x, double max_angle)
          Return an angle that lies between -max_angle and max_angle for x between 0 and 1
 void beforeDestruction()
          This method is called right before the spaceship is destroyed by (and only by) lack of hitpoints.
 void doBlink()
          Do the blinking animation.
protected  void fire()
          Try to fire (all) the guns.
 java.lang.String getBlinkFile()
           
 int getHitpoints()
           
 int getLevel()
           
 int getMaxBlink()
           
 int getMaxHitpoints()
           
 int getNumberOfGuns()
           
 int getSide()
           
 boolean hit(Missile m)
          If the missile was shot by an enemy, subtract hitpoints.
 void removeGun(int position)
          Remove the gun in the given position.
 void removeHitpoints(int n_hitpoints)
           
 void reorderGuns()
          Set the guns' dx values so that the missiles are launched from appear in an neat, aligned fashion.
 void setAngledGuns(boolean angled)
          Sets the ship to shoot straight or widespread (aka angled).
 void setBlinkFile(java.lang.String the_blink_file)
           
 void setHitpoints(int hit)
           
 void setLevel(int new_level)
           
 void setMaxBlink(int max)
           
 void setMaxHitpoints(int max)
           
 void setSide(int new_side)
           
protected  void setupImages()
          Sort-of abstract method available for overriddance [sic].
 
Methods inherited from class QuantumObject
getDestroysOnNextTurn, getSpeed, move, setDestroysOnNextTurn, setSpeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

side

protected int side

level

protected int level

hitpoints

protected int hitpoints

max_hitpoints

protected int max_hitpoints

blink

protected int blink
Variable containing the state of the blink animation that happens when the spaceship is damaged. 1: start blink animation 2..MAX_BLINK: continue blinking MAX_BLINK+1: restore default sprite

See Also:
doBlink()

max_blink

protected int max_blink
How many turns the blinking animations should last.


blink_file

protected java.lang.String blink_file
Filename of the sprite to be used while blinking, i. e. of the spaceship's "blink" state.


GUN_DISTANCE

public static final int GUN_DISTANCE
X distance between guns on one spaceship.

See Also:
Constant Field Values

GUN_ANGLE

public static final double GUN_ANGLE
Determines the angular distance between guns when angled_guns is true. The angle between the first and the last gun equals 2 * n_guns * GUN_ANGLE. The value is expressed in radians.

See Also:
angled_guns, n_guns, Constant Field Values

N_GUNS

public static final int N_GUNS
See Also:
Constant Field Values

guns

protected Gun[] guns

n_guns

protected int n_guns

angled_guns

protected boolean angled_guns
Determines if guns should shoot in a straight way (angled_guns = false) or rather in a widespread way (angled_guns = true).

Constructor Detail

Spaceship

public Spaceship(int the_level)
Method Detail

act

public void act()
Description copied from class: QuantumObject
A day in the life of a quantum object: 1. Maybe commit suicide (i. e. destroys itself when destroysOnNextTurn is true) 2. Do quantum object interactions with intersecting objects 3. -- Err... are you missing point 3?

Overrides:
act in class QuantumObject

addGun

public void addGun(int position,
                   Gun new_gun)
Add a gun in the given position. Doesn't check if position exceeds array bounds. This is a feature. (Seriously: The check wasn't implemented because that way programming mistakes in MoreGuns etc. became obvious more quickly.)

See Also:
MoreGuns

removeGun

public void removeGun(int position)
Remove the gun in the given position. Doesn't check if position exceeds array bounds.

See Also:
addGun(int position, Gun new_gun)

getNumberOfGuns

public int getNumberOfGuns()

reorderGuns

public void reorderGuns()
Set the guns' dx values so that the missiles are launched from appear in an neat, aligned fashion. That is, make them launch from positions that are GUN_DISTANCE pixels apart from each other, and aligned to the center of the spaceship.


angle

public double angle(double x,
                    double max_angle)
Return an angle that lies between -max_angle and max_angle for x between 0 and 1

Parameters:
x - number between 0.0 and 1.0

setAngledGuns

public void setAngledGuns(boolean angled)
Sets the ship to shoot straight or widespread (aka angled). Recalculate the guns' speed vectors based on that value.


setSide

public void setSide(int new_side)

getSide

public int getSide()

setLevel

public void setLevel(int new_level)

getLevel

public int getLevel()

fire

protected void fire()
Try to fire (all) the guns. That is, call each gun's missile() method and check if something came out yet. If yes, place it into the world.


addHitpoints

public void addHitpoints(int n_hitpoints)

removeHitpoints

public void removeHitpoints(int n_hitpoints)

getHitpoints

public int getHitpoints()

setHitpoints

public void setHitpoints(int hit)

getMaxHitpoints

public int getMaxHitpoints()

setMaxHitpoints

public void setMaxHitpoints(int max)

beforeDestruction

public void beforeDestruction()
This method is called right before the spaceship is destroyed by (and only by) lack of hitpoints. Empty here, to be overridden in subclasses that e. g. want to leave power-ups behind.


hit

public boolean hit(Missile m)
If the missile was shot by an enemy, subtract hitpoints.

Overrides:
hit in class QuantumObject
Parameters:
m - The object we are interacting with
Returns:
boolean. True if this quantum object should survive, false otherwise.

setupImages

protected void setupImages()
Sort-of abstract method available for overriddance [sic]. Subclasses can implement this to set their sprite (back) to its default value. It's called whenever a reset to the default sprite is needed, e. g. after the blinking animation.

See Also:
doBlink()

setBlinkFile

public void setBlinkFile(java.lang.String the_blink_file)

getBlinkFile

public java.lang.String getBlinkFile()

doBlink

public void doBlink()
Do the blinking animation. This is called whenever the ship has hitpoints subtracted. It evaluates and changes the "blink" variable, and changes sprites if necessary.


setMaxBlink

public void setMaxBlink(int max)

getMaxBlink

public int getMaxBlink()