-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanthill.pde
71 lines (62 loc) · 1.2 KB
/
anthill.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class AntHill
{
QVector2D position;
int food;
ArrayList ants;
int timer = 0;
boolean dead = false;
AntHill (QVector2D _position)
{
this.position = _position;
this.food = 6000;
this.ants = new ArrayList();
}
void addFood (int _food)
{
this.food += _food;
}
int takeFood (int _food)
{
if (!unlimitedFood) {
if (this.food > _food) {
this.food -= _food;
return _food;
} else {
return 0;
}
} else {
return _food;
}
}
void addAnt ()
{
this.ants.add(new Ant(this));
}
void draw ()
{
if (drawObjects) {
noStroke();
fill(50);
ellipse(this.position.x, this.position.y, 10, 10);
}
Ant ant;
for (int i = 0; i < this.ants.size(); i++) {
ant = (Ant) this.ants.get(i);
if (ant.timeWithoutFood > 600) {
this.ants.remove(i);
} else {
ant.draw();
}
}
this.timer++;
if (this.food > 5000 && this.timer >= 600) {
this.addAnt();
this.timer = 0;
}
if (this.food < 500 && this.ants.size() == 0) this.dead = true;
}
QVector2D getPosition ()
{
return this.position.get();
}
}