-
Notifications
You must be signed in to change notification settings - Fork 0
/
Food.pde
60 lines (51 loc) · 1.19 KB
/
Food.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
// Fred Limouzin
// Food Class
// v1 - 20170216
class Food {
PVector pos;
float diam;
boolean empty;
//Constructor: default position chosen randomly on a circle centered on the nest
//but eventually should be "true" random
Food (float tDiam) {
float angle = random(-PI, PI);
float rn1 = random(0.8, 1);
float rn2 = random(0.8, 1);
this.pos = new PVector(width/2 * (1 + rn1 * cos(angle)), height/2 * (1 + rn2 * sin(angle)));
this.diam = tDiam;
this.empty = false;
}
//Constructor: Can also force position
Food (float tDiam, PVector tPos) {
this.pos = tPos.copy();
this.diam = tDiam;
this.empty = false;
}
boolean isEmpty() {
return this.empty;
}
float getDiam() {
return this.diam;
}
PVector getPos() {
return this.pos.copy();
}
void update() {
if (this.diam < 1) {
this.diam = 0;
this.empty = true;
}
}
void show() {
if (!(this.isEmpty())) {
strokeWeight(2);
stroke(0, 128, 0);
fill(0, 255, 0);
ellipse(this.pos.x, this.pos.y, this.diam, this.diam);
}
}
void run() {
this.update();
this.show();
}
}