forked from dylanneve1/spaceDodgeAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlife.pde
97 lines (86 loc) · 1.57 KB
/
life.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class Life
{
float x;
float y;
float yspeed = displayWidth*0.02;
float r = displayHeight*0.04;
float rightEdge;
float leftEdge;
float topEdge;
float bottomEdge;
boolean collided = false;
boolean notYetTapped = true;
Life()
{
x = random(width);
y = random(-500, -50);
}
void call()
{
fall();
show();
respawn();
edgeDetect();
collision();
getOneUp();
reset();
}
void fall()
{
y += yspeed;
}
void show()
{
ellipseMode(CENTER);
fill(0, 255, 0);
if (notYetTapped == true)
{
ellipse(x, y, r, r);
}
}
void respawn()
{
if (y >= displayHeight + (displayHeight/2))
{
y = random(displayHeight*-1, displayHeight*-0.1);
x = random(displayWidth);
notYetTapped = true;
}
}
void edgeDetect()
{
leftEdge = x - r/2;
rightEdge = x + r/2;
topEdge = y - r/2;
bottomEdge = y + r/2;
}
void collision()
{
if (notYetTapped == true)
{
if (leftEdge <= player.rightEdge && rightEdge >= player.leftEdge && bottomEdge >= player.topEdge && bottomEdge <= player.bottomEdge)
{
collided = true;
notYetTapped = false;
Vibrator vibrer = (Vibrator) act.getSystemService(Context.VIBRATOR_SERVICE);
vibrer.vibrate(100);
powerUp.play();
}
}
}
void getOneUp()
{
if (collided == true)
{
player.lives += 1;
collided = false;
}
}
void reset()
{
if (menu.deadActive == true)
{
y = random(displayHeight*-1, displayHeight*-0.1);
}
}
}