-
Notifications
You must be signed in to change notification settings - Fork 0
/
food.js
41 lines (33 loc) · 987 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
// Originally by:
// Daniel Shiffman
// http://codingrainbow.com
// http://patreon.com/codingrainbow
// Code for: https://youtu.be/AaGK-fj-BAM
function Food() {
var cols = floor((width)/scl);
var rows = floor((height-score_box)/scl);
luck = random(1);
if (luck >= 0.95){
this.weight = Food_limit;
} else if (luck >=0.1) {
this.weight = floor(luck * Food_limit/2);
}
else {
this.weight = 20;
}
this.toDelete = false;
this.locat = createVector(floor(random(1,cols+1))-1/2, floor(score_box/scl) + floor(random(1,rows+1))-1/2);
this.locat.mult(scl);
this.show = function(){
fill(255+0*this.weight, 255-2*this.weight, 255-2*this.weight);
textSize(ceil(scl*2/3));
textAlign(CENTER,CENTER);
text(ceil(this.weight),this.locat.x, this.locat.y);
noFill(255, 0, 100);
//rectMode(CENTER);
rect(this.locat.x, this.locat.y,scl,scl);
}
this.die = function(){
this.toDelete = true;
}
}