-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSlimeField.java
More file actions
51 lines (44 loc) · 1.1 KB
/
Copy pathSlimeField.java
File metadata and controls
51 lines (44 loc) · 1.1 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
import greenfoot.Color;
/**
* An obstacle, which slows down all zombies that walk over it for a certain
* time. It can be bought and placed by the player.
*/
public class SlimeField extends Obstacle {
public static final int PRICE = 20;
private static final double DEFAULT_SLOWDOWN = 0.5; // should be from 0.0-1.0, example: 0.7 stands for 70% less speed
private int slowdownDuration = 500;
private static final Color COLOR = new Color(0, 255, 0);
private static final int POINTS = 1500;
/**
* Creates an slime field object and its image.
*/
public SlimeField() {
createImage(COLOR, POINTS);
}
/**
* Does what an obstacle does and slows down all zombies in its range, when the
* game is not paused.
*/
@Override
public void act() {
super.act();
if(!IsCountdownNotZero()) {
getWorld().removeObject(this);
}
}
private boolean IsCountdownNotZero() {
slowdownDuration--;
if(slowdownDuration > 0) {
return true;
} else {
return false;
}
}
@Override
public int getPrice() {
return PRICE;
}
public static double getDefaultSlowdown() {
return DEFAULT_SLOWDOWN;
}
}