-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectile.java
60 lines (51 loc) · 1.98 KB
/
Projectile.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
54
55
56
57
58
59
60
class Projectile extends Entity {
protected static String[] SPRITES_PROJ_PLAYER = {"projPlayer0.png", "projPlayer1.png", "projPlayer2.png"};
protected static String[] SPRITES_PROJ_ENEMY = {"projEnemy0.png", "projEnemy1.png", "projEnemy2.png"};
private static final int[] LEVEL = {0, 1, 2};
private int damage;
private boolean isEnemy;
public Projectile(int r, int c, int typeChoice, boolean isHostile) {
super(r, c, typeChoice);
isEnemy = isHostile;
if (!isEnemy) {
setSprite(SPRITES_PROJ_PLAYER[getType()]);
if (getType() == LEVEL[0]) {
damage = 1;
setSpeed(1);
} else if (getType() == LEVEL[1]) {
damage = 1;
setSpeed(2);
} else if (getType() == LEVEL[2]) {
damage = 1;
setSpeed(3);
}
} else {
setSprite(SPRITES_PROJ_ENEMY[getType()]);
if (getType() == LEVEL[0]) {
damage = 1;
setSpeed(1);
} else if (getType() == LEVEL[1]) {
damage = 2;
setSpeed(1);
} else if (getType() == LEVEL[2]) {
damage = 1;
setSpeed(2);
}
}
}
public Projectile(Location loc, int typeChoice, boolean isHostile) {
this(loc.getRow(), loc.getCol(), typeChoice, isHostile);
}
// Creates a projectile based on data from the argument ship
public Projectile(Ship attackingShip) {
this(attackingShip.getRow(), attackingShip.getCol(), attackingShip.getProjType(), attackingShip.isEnemy());
}
// Creates a "clone" of the argument projectile, which retains all of its fields
public Projectile(Projectile clone) {
this(clone.getRow(), clone.getCol(), clone.getType(), clone.isEnemy());
damage = clone.getDamage();
isEnemy = clone.isEnemy();
}
public int getDamage() { return damage; }
public boolean isEnemy() { return isEnemy; }
}