-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.pde
57 lines (43 loc) · 888 Bytes
/
Home.pde
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
class Home {
PVector pos;
float radius;
float food = 0;
int counter = 0;
final int BIRTH_RATE = 10;
final float NEW_ANT_COST = 3;
final float NEW_ANT_MINIM = 20;
Home(PVector pos_, float radius_) {
pos = pos_;
radius = radius_;
}
void update() {
counter++;
if (food > NEW_ANT_MINIM && counter >= BIRTH_RATE) {
counter = 0;
newAnt();
food -= NEW_ANT_COST;
}
}
void newAnt() {
ants.add(new Ant(pos.copy(), PVector.random2D()));
}
boolean take_food(float f) {
if (food == 0) {
return false;
}
food -= f;
if (food <= 0) {
food = 0;
}
return true;
}
void show() {
pushStyle();
fill(HOME_COLOR);
circle(pos.x, pos.y, radius);
noStroke();
fill(FOOD_COLOR);
circle(pos.x, pos.y, 0.9*min(1, food/NEW_ANT_MINIM) * radius);
popStyle();
}
}