-
Notifications
You must be signed in to change notification settings - Fork 1
/
Food.js
49 lines (43 loc) · 927 Bytes
/
Food.js
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
class Food {
constructor(num) {
// Start with some food
this.food = [];
for (var i = 0; i < num; i++) {
this.food.push(createVector(random(width), random(height)));
}
}
// Add some food at a position
add(l) {
this.food.push(l.copy());
}
// Display the food
run() {
var f;
for (let i=this.food.length-1; i>=0; i--) {
let f = this.food[i];
this.display(f);
}
// There's a small chance food will appear randomly
if (random(1) < 0.28) {
this.food.push(createVector(random(width), random(height)));
}
}
display(f) {
push();
ellipseMode(CENTER);
stroke(0);
fill(102, 255, 102);
translate(f.x, f.y);
rotate(7*PI/4);
ellipse(7, 7, 12, 4);
rotate(6*PI/4);
ellipse(0, 0, 12, 4);
rotate(PI/4);
ellipse(5, 5, 12, 4);
pop();
}
// Return the list of food
getFood() {
return this.food;
}
}