-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFeeder.java
More file actions
46 lines (37 loc) · 1.22 KB
/
Copy pathFeeder.java
File metadata and controls
46 lines (37 loc) · 1.22 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
import greenfoot.Actor;
public class Feeder extends Actor {
private int load;
private int l;
private long lastHopperRefill;
public Feeder() {
l = 2;
load = 50;
lastHopperRefill = System.currentTimeMillis();
}
public void act() {
updateDrawing();
if ( (System.currentTimeMillis() - lastHopperRefill) > 13500) {
load = 50; // - this.getWorld().getObjects(Ball.class).toArray().length; // Used to "limit" number of balls to 50 on the field for I'm guessing performance reasons.
lastHopperRefill = System.currentTimeMillis();
}
}
private void updateDrawing() {
// Updates Drawing that shows how full the Feeder is
if (load > 35) {
l = 2;
} else if (load > 0) {
l = 1;
} else {
l = 0;
}
this.setImage("FuelContainer" + l + ".png");
}
public void dump() {
while(load > 0) {
--load;
int x = this.getX() + (int)Math.floor(Math.random() * 50.0D) - 25;
int y = this.getY() - (int)Math.floor(Math.random() * 50.0D);
this.getWorld().addObject(new Ball(0.0D, 0.0D, x, y, false), x, y);
}
}
}