-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBomb.java
More file actions
55 lines (48 loc) · 1.62 KB
/
Copy pathBomb.java
File metadata and controls
55 lines (48 loc) · 1.62 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
53
54
55
import java.util.List;
import greenfoot.Greenfoot;
import greenfoot.GreenfootImage;
/**
* A special projectile that is shot by an bomb tower. It can attack several
* zombies in a small range.
*/
public class Bomb extends Projectile {
private static final String BOMB_IMAGE_NAME = "bomb-projectile.png";
private static final int DEFAULT_RANGE = PathCell.PATH_WIDTH - 5;
private static final String EXPLOSION_SOUND = "Bomb_Explosion.wav";
private static final double DEFAULT_SPEED = 1.5;
/**
* Creates an bomb object based on a projectile. Scales and sets its image.
*
* @param destinationX - the x-coordinate of the target
* @param destinationY - the x-coordinate of the target
* @param damage - the damage dealt by the bomb
*/
public Bomb(int destinationX, int destinationY, int damage) {
super(destinationX, destinationY, DEFAULT_SPEED, BOMB_IMAGE_NAME, damage);
GreenfootImage img = new GreenfootImage(BOMB_IMAGE_NAME);
img.scale((int) (img.getWidth() / 1.5), (int) (img.getHeight() / 1.5));
setImage(img);
}
/**
* Attacks other targets in a small range around the original target when
* reaching it, then gets removed.
*/
@Override
protected void behaviourIfReachedDestination() {
List<Zombie> zombies = getObjectsInRange((int) Math.floor(DEFAULT_RANGE), Zombie.class);
if(zombies.size() > 0) {
for (Zombie zombie : zombies) {
zombie.absorbDamage(getDamage());
}
}
Greenfoot.playSound(EXPLOSION_SOUND);
getWorld().removeObject(this);
}
/**
* Rotates while flying to the target.
*/
@Override
protected void behaviorWhileMoving() {
this.setRotation(getRotation() + 5);
}
}