-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCoin.js
More file actions
34 lines (25 loc) · 744 Bytes
/
Coin.js
File metadata and controls
34 lines (25 loc) · 744 Bytes
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
class Coin {
constructor(x,y){
this.taken = false;
this.pos = createVector(x,y);
this.diameter = tileSize/2.0;
}
show(){
if(!showedCoin && !this.taken){
stroke(0);
fill(255,230,230);
ellipse(this.pos.x,this.pos.y,this.diameter);
showedCoin = true;
}
}
collides(ptl, pbr) {//player dimensions
if(this.taken){ return false;}
var topLeft = createVector(this.pos.x - this.diameter/2, this.pos.y-this.diameter/2);
var bottomRight = createVector(this.pos.x + this.diameter/2, this.pos.y + this.diameter/2);
if ((ptl.x <bottomRight.x && pbr.x > topLeft.x) &&( ptl.y < bottomRight.y && pbr.y > topLeft.y)) {
this.taken = true;
return;
}
return;
}
}