-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBombTower.java
More file actions
52 lines (44 loc) · 1.55 KB
/
BombTower.java
File metadata and controls
52 lines (44 loc) · 1.55 KB
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
import greenfoot.Greenfoot;
/**
* A special tower with low range, medium damage and medium reload time. It attacks zombies with
* bombs and is more expensive than the archer tower.
*/
public class BombTower extends Tower {
public static final int PRICE = 30;
private static final int DEFAULT_DAMAGE = 50;
private static final int DEFAULT_RANGE = 100;
private static final int DEFAULT_RELOAD_TIME = 250;
private static final int ZOMBIE_MOVEMENT_FORWARD_PREDICTION = 5;
private static final String FLYING_SOUND = "Bomb_Ignite.wav";
/**
* Creates an bomb tower object with its default values.
*/
public BombTower() {
super(DEFAULT_RANGE, DEFAULT_RELOAD_TIME, DEFAULT_DAMAGE);
setImage("Tower-darker.png");
}
@Override
public int getPrice() {
return PRICE;
}
/**
* Shoots an bomb which attacks all zombies in a small range around its impact.
*
* @param destinationX - the x-coordinate of the target
* @param destinationY - the y-coordinate of the target
* @param damage - the damage an bomb deals
*/
protected void shootProjectile(int destinationX, int destinationY, int damage) {
Bomb bomb = new Bomb(destinationX, destinationY, damage);
getWorld().addObject(bomb, getX(), getY());
Greenfoot.playSound(FLYING_SOUND);
}
@Override
public int getZombieMovementForwardPrediction() {
return (int) (ZOMBIE_MOVEMENT_FORWARD_PREDICTION + 10 / getProjetile(0, 0, 0).getSpeed());
}
@Override
public Projectile getProjetile(int destinationX, int destinationY, int damage) {
return new Bomb(destinationX, destinationY, damage);
}
}