forked from Markominer/Jumpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.pde
More file actions
142 lines (132 loc) · 3.75 KB
/
Player.pde
File metadata and controls
142 lines (132 loc) · 3.75 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
public class PLAYER {
PVector pos = new PVector();
float fv = 0, a = 0.01;
int max = 1;
int hMax = 5;
float v = 0;
int size = 25;
int w = 25, h = 25;
float jumps = 20;
int leben = 1;
int streak = 1;
float ha = 0.3;
boolean hit = false, alive = true;
boolean right = false;
boolean left = false;
boolean wait = false, jump = false;
int points = 0;
PImage flame;
PLAYER() {
flame = loadImage("Flame.png");
pos.set(width/2 -25, 100);
}
void update() {
bewegung();
collision();
setPoints();
paintS();
paintP();
if (!jump && jumps <100) jumps += 0.02;
}
void bewegung() {
if (pos.y <= 0) fv = 1;
if (fv + a < max)fv += a;
pos.add(0, fv);
if (pos.y>= height/2)fv = -0.1;
if (v + ha < hMax && (right||left))v += ha;
if (!(right||left)) {
v = 0;
}
//rechts
if (right) pos.add(v, 0);
// links
if (left) pos.add(-v, 0);
}
void paintJet() {
if (jumps >= 0.2 ) {
noStroke();
fill(255, 155, 0);
image(flame, pos.x, pos.y + h, w, h*3/2);
if (alive)jumps -= 0.2;
a = -0.1;
for (OBSTACLE oi : o) {
oi.a = - 0.05 + (oi.v/10);
}
} else {
jump= false;
a = 0.02;
for (OBSTACLE oi : o) {
oi.a = 0.05;
}
}
}
void collision() {
if (!hit) {
for (OBSTACLE oi : o) {
if ((pos.x < oi.pos.x && pos.y > oi.pos.y-h && pos.y < oi.pos.y+oHeight) ||(pos.x + w > oi.pos.x+100 && pos.y > oi.pos.y-h && pos.y < oi.pos.y+oHeight) ) {
if (leben > 0) leben--;
if (leben <= 0) alive = false;
hit = true;
bgt = 0;
w = size + (size*streak /50);
h =w;
}
}
}
}
void setPoints() {
for (OBSTACLE oi : o) {
if (pos.y -oHeight+h > oi.pos.y && !hit && !wait) {
streak ++;
points += streak-1;
w = size + (size*streak /50);
h =w;
if (streak %5 == 0) {
jumps+=(streak/5);
}
wait =true;
}
}
}
void paintP() {
fill(255, 0, 100);
if (pos.x> width)pos.set(1, pos.y);
if (pos.x <= 0)pos.set(width, pos.y);
if (pos.x + w <= width && pos.x>= 0) {
rect(pos.x, pos.y, w, h);
} else {
if ((pos.x + w >= width)) {
rect(pos.x, pos.y, w, h);
rect(0, pos.y, w -(width-(pos.x)), h);
} else if ( pos.x - w>= 0) {
rect(pos.x, pos.y, w, h);
rect(width-pos.x, pos.y, w, h);
}
}
}
void paintS() {
float shadowLength = 0.00035;
float TRD = sqrt(sq(pos.x+w-lightX)+sq(pos.y-lightY));
float factor = (TRD*shadowLength);
float sTRX = (pos.x+w+factor*(pos.x+w-lightX));
float sTRY = (pos.y+factor*(pos.y-lightY));
TRD = sqrt(sq(pos.x+w-lightX)+sq(pos.y+h-lightY));
factor = (TRD*shadowLength);
float sBRX = (pos.x+w+factor*(pos.x+w-lightX));
float sBRY = (pos.y+h+factor*(pos.y+h-lightY));
TRD = sqrt((pos.x-lightX)*(pos.x-lightX)+(pos.y-lightY)*(pos.y-lightY));
factor = (TRD*shadowLength);
float sTLX = (pos.x+factor*(pos.x-lightX));
float sTLY = (pos.y+factor*(pos.y-lightY));
TRD = sqrt(sq(pos.x-lightX)+sq(pos.y+h-lightY));
factor = (TRD*shadowLength);
float sBLX = (pos.x+factor*(pos.x-lightX));
float sBLY = (pos.y+h+factor*(pos.y+h-lightY));
fill(0, 60);
quad(pos.x+w, pos.y, pos.x+w, pos.y+h, sBRX, sBRY, sTRX, sTRY);
quad(pos.x, pos.y+h, pos.x+w, pos.y+h, sBRX, sBRY, sBLX, sBLY);
quad(pos.x, pos.y, pos.x, pos.y+h, sBLX, sBLY, sTLX, sTLY);
quad(pos.x, pos.y, pos.x+w, pos.y, sTRX, sTRY, sTLX, sTLY);
quad(sBRX, sBRY, sTRX, sTRY, sTLX, sTLY, sBLX, sBLY);
}
}