fi.utu.cs.asteroids
Class Ship

java.lang.Object
  |
  +--fi.utu.cs.physics.Body
        |
        +--fi.utu.cs.asteroids.Ship
All Implemented Interfaces:
Shapable

public class Ship
extends Body
implements Shapable

A ship. The ship is steered with the methods rotateLeft, rotateRight, and goStraight; the thruster is operated with the methods thrusterOn, and thrusterOff; the firing is controled with the methods fireOn, and fireOff; and the ship is terminated with the method explode.


Constructor Summary
Ship(Point2 p)
          Creates a ship at position p pointing at a random direction.
 
Method Summary
 void advance(double dt)
          Advances the time dt seconds and updates the position, velocity, and rotation of the ship accordingly.
 java.awt.Color color()
          Returns a Color object that is used for drawing the outline.
 void explode()
          Explodes the ship and removes it from the universe.
 void fireOff()
          Sets the firing off.
 void fireOn()
          Sets the firing on.
 double getAngle()
          Returns the current angle (in radians).
 void goStraight()
          Sets the steering to straight forward.
 boolean isColliding(Body other)
          Returns whether the ship collides with the body other.
 boolean isDrawn()
          Returns a boolean value indicating whether the outline of the shape is drawn or not.
 boolean isFilled()
          Returns a boolean value indicating whether the shape is filled or not.
 boolean isFiring()
          Returns whether the ship is firing during the current update interval.
 boolean isThrusting()
          Returns whether the thruster is on.
 java.awt.Paint paint()
          Returns a Paint object that is used for filling the shape.
 void rotateLeft()
          Sets the steering to the left (i.e., counterclockwise).
 void rotateRight()
          Sets the steering to the right (i.e., clockwise).
 void setAngle(double t)
          Sets the current angle to t (in radians).
 void setColor(java.awt.Color c)
          Sets the color of the ship to c.
 java.awt.Shape shape()
          Returns a Shape object that defines the appearance of the object.
 java.awt.Stroke stroke()
          Returns a Stroke object that is used for drawing the outline.
 void thrusterOff()
          Sets the thruster off.
 void thrusterOn()
          Sets the thruster on.
 java.lang.String toString()
          Returns a string that contains the values of the attributes.
 
Methods inherited from class fi.utu.cs.physics.Body
elasticCollision, getAcceleration, getMass, getOwner, getPosition, getRadius, getVelocity, isCorporeal, isOverlapping, setAcceleration, setAcceleration, setCorporeal, setEthereal, setMass, setOwner, setPosition, setPosition, setRadius, setVelocity, setVelocity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Ship

public Ship(Point2 p)
Creates a ship at position p pointing at a random direction. The mass of the ship is defined by the parameter shipMass and the size by the parameter shipRadius.
See Also:
Game
Method Detail

getAngle

public double getAngle()
Returns the current angle (in radians).

setAngle

public void setAngle(double t)
Sets the current angle to t (in radians).

setColor

public void setColor(java.awt.Color c)
Sets the color of the ship to c.

advance

public void advance(double dt)
Advances the time dt seconds and updates the position, velocity, and rotation of the ship accordingly. If the parameter decorations is true and the thruster is on, the ship emits a spark at the stern.
Overrides:
advance in class Body
See Also:
thrusterOn(), Spark

isColliding

public boolean isColliding(Body other)
Returns whether the ship collides with the body other. The parameter collisionProjectileShip defines, whether the projectiles can collide with the ships. The parameter collisionShipShip defines, whether the ships can collide with each other.
Overrides:
isColliding in class Body
See Also:
Projectile

rotateLeft

public void rotateLeft()
Sets the steering to the left (i.e., counterclockwise). The rotation speed is defined by the parameter shipSteeringRotationPerSecond.

rotateRight

public void rotateRight()
Sets the steering to the right (i.e., clockwise). The rotation speed is defined by the parameter shipSteeringRotationPerSecond.

goStraight

public void goStraight()
Sets the steering to straight forward.

thrusterOn

public void thrusterOn()
Sets the thruster on. The force of the thruster is defined by the parameter shipThrusterForce.

thrusterOff

public void thrusterOff()
Sets the thruster off.

isThrusting

public boolean isThrusting()
Returns whether the thruster is on.

fireOn

public void fireOn()
Sets the firing on. The firing rate is defined by the parameter shipShotsPerSecond.
See Also:
Projectile

fireOff

public void fireOff()
Sets the firing off.

isFiring

public boolean isFiring()
Returns whether the ship is firing during the current update interval.
See Also:
fireOn(), advance(double)

explode

public void explode()
Explodes the ship and removes it from the universe. If the parameter decorations is true, a cloud of sparks is created at the site of the explosion according to the parameters sparksOnCloud and sparkMaxVelocity.
See Also:
Spark

shape

public java.awt.Shape shape()
Description copied from interface: Shapable
Returns a Shape object that defines the appearance of the object.
Specified by:
shape in interface Shapable
Following copied from interface: fi.utu.cs.appearance.Shapable
See Also:
Shape

isDrawn

public boolean isDrawn()
Description copied from interface: Shapable
Returns a boolean value indicating whether the outline of the shape is drawn or not.
Specified by:
isDrawn in interface Shapable
Following copied from interface: fi.utu.cs.appearance.Shapable
See Also:
Shapable.stroke(), Shapable.color()

stroke

public java.awt.Stroke stroke()
Description copied from interface: Shapable
Returns a Stroke object that is used for drawing the outline.
Specified by:
stroke in interface Shapable
Following copied from interface: fi.utu.cs.appearance.Shapable
See Also:
Shapable.isDrawn(), Stroke

color

public java.awt.Color color()
Description copied from interface: Shapable
Returns a Color object that is used for drawing the outline.
Specified by:
color in interface Shapable
Following copied from interface: fi.utu.cs.appearance.Shapable
See Also:
Shapable.isDrawn(), Color

isFilled

public boolean isFilled()
Description copied from interface: Shapable
Returns a boolean value indicating whether the shape is filled or not.
Specified by:
isFilled in interface Shapable
Following copied from interface: fi.utu.cs.appearance.Shapable
See Also:
Shapable.paint()

paint

public java.awt.Paint paint()
Description copied from interface: Shapable
Returns a Paint object that is used for filling the shape.
Specified by:
paint in interface Shapable
Following copied from interface: fi.utu.cs.appearance.Shapable
See Also:
Shapable.isFilled(), Paint

toString

public java.lang.String toString()
Description copied from class: Body
Returns a string that contains the values of the attributes.
Overrides:
toString in class Body