forked from Code-Bullet/Jump-King
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coin.js
36 lines (29 loc) · 788 Bytes
/
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
class Coin{
constructor(x,y, type = "reward") {
this.levelNo = 0;
this.x = x;
this.y= y;
this.radius = 50;
this.type = type;
}
collidesWithPlayer(playerToCheck){
let playerMidPoint = playerToCheck.currentPos.copy();
playerMidPoint.x += playerToCheck.width/2;
playerMidPoint.y += playerToCheck.height/2;
if(dist(playerMidPoint.x,playerMidPoint.y,this.x,this.y)<this.radius + playerToCheck.width/2){
return true;
}
return false;
}
show(){
push();
if(this.type == "reward"){
fill(255,150,0);
}else{
fill(0,200,0,100);
}
noStroke();
ellipse(this.x,this.y,this.radius*2);
pop();
}
}