-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoin.js
65 lines (50 loc) · 1.18 KB
/
Coin.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Coin {
constructor(num, x, y, w) {
this.num = num;
this.x = x;
this.y = y;
this.w = w;
this.highlighted = false;
this.showCost = false;
this.cost = 0;
}
update() {
//rect(this.x-40, this.y-40, this.w, this.w);
if (this.highlighted) {
strokeWeight(10);
stroke('red');
ellipse(this.x, this.y, this.w+5, this.w+5);
strokeWeight(1);
stroke('black');
}
if (this.showCost) {
textAlign(CENTER,CENTER);
strokeWeight(0);
text('$'+this.cost, this.x-this.w/2+3, this.y+this.w/2+2, this.w, this.w);
strokeWeight(1);
}
ellipse(this.x, this.y, this.w, this.w);
textAlign(CENTER, CENTER);
text(this.num, this.x-this.w/2+3, this.y-this.w/2+2, this.w, this.w);
}
setNum(num) {
this.num = num;
}
highlight() {
this.highlighted = true;
}
noHighlight() {
this.highlighted = false;
}
setCost(cost) {
this.cost = cost;
this.showCost = true;
}
clearCost() {
this.showCost = false;
}
isMouseClose() {
let mouse = new p5.Vector(mouseX-this.x,mouseY-this.y);
return mouse.mag() < this.w/2;
}
}