import java.awt.*; import java.awt.geom.*; import physics2D.*; public class SpaceShip extends Object2D implements Drawable { private double thrust = 100; private double angularThrust = 4; private int thrustOn = 0; private int angularThrustOn = 0; private int damage = 0; private Shape shipShape = new Polygon( new int[] { 54, 108, 100, 141, 85, 73, 106, 89, 80, 40, 54, -54, -40, -80, -89,-106, -73, -85,-141,-100,-108, -54}, new int[] { -89, 3, 18, 89, 89, 69, 69, 38, 53, 53, 75, 75, 53, 53, 38, 69, 69, 89, 89, 18, 3, -89}, 22); private Shape thrustShape = new Polygon( new int[] { 44, -44, 0}, new int[] { 65, 65, 200}, 3); private Color shipColor = new Color(109,192,255); private Color thrustColor = new Color(255,242,23); public SpaceShip(Vector2D position, double scale) { super(110 * scale, 1); AffineTransform scaleT = AffineTransform.getScaleInstance(scale, scale); shipShape = scaleT.createTransformedShape(shipShape); thrustShape = scaleT.createTransformedShape(thrustShape); angle = Math.PI; move(position); } public void move(Vector2D m) { AffineTransform translate = AffineTransform.getTranslateInstance(m.getXComponent(), m.getYComponent()); shipShape = translate.createTransformedShape(shipShape); thrustShape = translate.createTransformedShape(thrustShape); super.move(m); } public void rotate(double r) { AffineTransform rotate = AffineTransform.getRotateInstance(r, position.getXComponent(), position.getYComponent()); shipShape = rotate.createTransformedShape(shipShape); thrustShape = rotate.createTransformedShape(thrustShape); super.rotate(r); } public Vector2D getAcceleration() { return new Vector2D(thrustOn * thrust, angle); } public double getAngularVelocity() { return angularThrustOn * angularThrust; } public Shape[] getShapes() { if (thrustOn != 0) return new Shape[] {shipShape, thrustShape}; else return new Shape[] {shipShape}; } public Color[] getColors() { if (thrustOn != 0) return new Color[] {shipColor, thrustColor}; else return new Color[] {shipColor}; } public void thrusterOn() { thrustOn = 1; } public void thrusterOff() { thrustOn = 0; } public void turnLeft() { angularThrustOn = -1; } public void turnRight() { angularThrustOn = 1; } public void stopTurn() { angularThrustOn = 0; } }