-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoin.pde
78 lines (69 loc) · 1.08 KB
/
Coin.pde
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
66
67
68
69
70
71
72
73
74
75
76
77
78
public class Coin
{
float x;
float y;
float diameter;
float xdif;
float ydif;
float colorR = 250;
float colorG = 250;
float colorB = 250;
PImage img = loadImage("coin.png");
Coin(float d)
{
diameter = d;
}
void place(float x, float y)
{
this.x = x;
this.y = y;
imageMode(CENTER);
tint(colorR, colorG, colorB);
image(img, x, y, d, d);
}
void setColor(float colorR, float colorG, float colorB)
{
this.colorR = colorR;
this.colorG = colorG;
this.colorB = colorB;
}
float getX()
{
return x;
}
float getY()
{
return y;
}
boolean isClicked()
{
xdif = x - mouseX;
ydif = y - mouseY;
float tdif = sqrt(xdif*xdif + ydif*ydif);
if (tdif <= diameter/2)
{
return true;
} else
{
return false;
}
}
float getXDif()
{
return xdif;
}
float getYDif()
{
return ydif;
}
boolean hasCollisionWith(Coin coin)
{
if (dist(this.x, this.y, coin.getX(), coin.getY()) <= d + 5)
{
return true;
} else
{
return false;
}
}
}