-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShip.java
53 lines (51 loc) · 1.86 KB
/
Ship.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
import java.io.*;
import javax.imageio.ImageIO;
// By moving weapons from SpaceObj to Ship we optimize a little all the
// SpaceObj's that don't use weapons. Profiling showed that allocating the
// weapons was a significant extra overhead for projectile objects, for
// example, which are constantly created and destroyed.
public abstract class Ship extends SpaceObj {
public static final int COUNTDOWN_END = 0;
public static final int COUNTDOWN_INIT = 170;
public int countDown;
public ShipStatus status;
public ArrayList<Weapon> weapons;
// Index of selected weapon.
public int selectedWeapon;
protected Ship() { }
public Ship(double mv) {
super(mv);
countDown = COUNTDOWN_INIT;
status = ShipStatus.ALIVE;
weapons = new ArrayList<Weapon>();
selectedWeapon = 0;
}
public void die() {
isAccel = 0;
isBoosting = false;
turningRight = false;
turningLeft = false;
firing = false;
// If the ship is not motionless, which would screw up the angle
// calculation, then calculate the new angle.
if (dx != 0 || dy != 0) {
// East is 0, west is -pi. Pi is outside the range of directions.
// I think Math.atan returns theta in the range {-pi/2, pi/2}. (I
// think it can differentiate between straight down and straight
// up because Java has Infinity and -Infinity.)
angle = Math.atan(dy/dx);
if (dx < 0) {
if (angle >= 0)
angle -= Math.PI;
else
angle += Math.PI;
}
}
try {
origObjImg =
ImageIO.read(getClass().getResource("ballofflame.png"));
} catch (IOException e) { e.printStackTrace(); }
status = ShipStatus.DYING;
}
}