-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerActions.cpp
328 lines (239 loc) · 7.29 KB
/
PlayerActions.cpp
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#include "PlayerActions.h"
PlayerActions::PlayerActions(){}
PlayerActions::~PlayerActions(){}
void PlayerActions::activateHitbox(CollisionBox &box){
box.SetIsActive(true);
glm::vec3 pos = box.GetSceneGraphObject()->GetLocalPosition();
box.GetSceneGraphObject()->SetLocalPosition(glm::vec3(pos.x, pos.y, 0.0f));
}
void PlayerActions::deactivateHitbox(CollisionBox &box){
box.SetIsActive(false);
glm::vec3 pos = box.GetSceneGraphObject()->GetLocalPosition();
box.GetSceneGraphObject()->SetLocalPosition(glm::vec3(pos.x, pos.y, 1000.0f));
}
//doesn't deactivate body hitbox
void PlayerActions::deactivateAllHitbox(std::vector<CollisionBox> &hitboxList){
deactivateHitbox(hitboxList[PUNCHBOX]);
deactivateHitbox(hitboxList[KICKBOX]);
deactivateHitbox(hitboxList[LASERBOX]);
deactivateHitbox(hitboxList[BLASTBOX]);
}
Actions PlayerActions::moveLeftAction(int &t, glm::vec3 &vel){
int moveVel = -150;
//if speed is less than max, increase it otherwise reduce it
if(vel.x < moveVel)
vel.x += 25;
else
vel.x -= 25;
t+=1;
return MOVE_LEFT;
}
Actions PlayerActions::moveRightAction(int &t, glm::vec3 &vel){
int moveVel = 150;
if(vel.x > moveVel)
vel.x -= 25;
else
vel.x += 25;
t+=1;
return MOVE_RIGHT;
}
Actions PlayerActions::dashLeftAction(int &t, glm::vec3 &vel, int &sp){
int dashVel = -150;
if (sp > 50){
vel.x = dashVel;
vel.y = 30;
sp -= 100;
}
return IDLE;
}
Actions PlayerActions::dashRightAction(int &t, glm::vec3 &vel, int &sp){
int dashVel = 150;
if (sp > 50){
vel.x = dashVel;
vel.y = 30;
sp -= 100;
}
return IDLE;
}
//TODO: Ground
Actions PlayerActions::jumpAction(glm::vec3 &vel, int onGround){
int jumpVel = 80;
if(onGround == 1)
vel.y = jumpVel;
return IDLE;
}
Actions PlayerActions::punchAction(int &t, glm::vec3 &vel, int facing, std::vector<CollisionBox> &hitboxList, int onGround){
float vel_curve[4] = { 0, 0.5, 0.8, 1 };
float casttime = 10;
float recovery = 15;
float punchVel = 250;
deactivateAllHitbox(hitboxList);
if (t > (casttime + recovery))
return IDLE;
if (t<casttime){
activateHitbox(hitboxList[PUNCHBOX]);
glm::vec3 pos = hitboxList[PUNCHBOX].GetSceneGraphObject()->GetLocalPosition();
hitboxList[PUNCHBOX].GetSceneGraphObject()->SetLocalPosition(glm::vec3(0.f, 4.f, (4 + (4 * (float)t / casttime))));
int x = Bezier(vel_curve, 1, (float)t / casttime);
vel.x = Bezier(vel_curve, 1, (float)t / casttime)*punchVel*facing;
vel.y = 0;
}
if (t>casttime){
deactivateHitbox(hitboxList[PUNCHBOX]);
if (onGround == 1){
vel.x = 0;
}
else {
vel.x = vel.x*0.99f;
}
}
t += 1;
return PUNCH;
}
Actions PlayerActions::kickAction(int &t, glm::vec3 &vel, int facing, int onGround, std::vector<CollisionBox> &hitboxList){
float vel_curveup[4] = { 1, 0.5, 0.8, 0 };
float vel_curvedown[4] = { 1, 0.5, 0.8, 0 };
glm::vec3 kickVel;
float casttime = 20;
float recovery = 20;
deactivateAllHitbox(hitboxList);
if (t>casttime + recovery)
return IDLE;
//initial check for starting point, if 0 starting from ground
if ((t == 0) && (onGround == 1)){
kickStart = 0;
}
else if ((t == 0) && (onGround == 0)){
kickStart = 1;
}
if (t < casttime){
activateHitbox(hitboxList[KICKBOX]);
glm::vec3 pos = hitboxList[KICKBOX].GetSceneGraphObject()->GetLocalPosition();
if (kickStart == 0){
hitboxList[KICKBOX].GetSceneGraphObject()->SetLocalPosition(glm::vec3(0.f, -4.f + (8 * (float)t / casttime), (4 + (4 * (float)t / casttime))));
kickVel = glm::vec3(100 * facing, 40, 0);
kickVel.y = Bezier(vel_curvedown, 1, (float)t / casttime)*kickVel.y;
}
else if (kickStart == 1){ // diiiiive kiiiickuuuu
//if hit the ground, stop
hitboxList[KICKBOX].GetSceneGraphObject()->SetLocalPosition(glm::vec3(0.f, -4.f, (4 + (2 * (float)t / casttime))));
if (onGround == 1){
t = casttime + 1;
vel.x = 0;
vel.y = 0;
return KICK;
}
kickVel = glm::vec3(100 * facing, -60, 0);
kickVel.y = Bezier(vel_curveup, 1, (float)t / casttime)*kickVel.y;
}
vel = kickVel;
}
if (t > casttime){
if (kickStart == 1 && onGround == 1 && t < (casttime + (recovery / 2.f))){
hitboxList[KICKBOX].GetSceneGraphObject()->SetLocalPosition(glm::vec3(0.f, -4.f, 4));
hitboxList[KICKBOX].GetCollisionBox()->GetSceneGraphObject()->SetScale(glm::vec3(20.f*((float)t / (casttime + recovery)), 5.f*((float)t / (casttime + recovery)), 10.f*((float)t / (casttime + recovery))));
}
else {
deactivateHitbox(hitboxList[KICKBOX]);
hitboxList[KICKBOX].GetCollisionBox()->GetSceneGraphObject()->SetScale(glm::vec3(1.f, 1.f, 1.f));
}
if (onGround == 0){
vel.x = vel.x*0.95f;
}
else {
vel.x = 0;
}
}
t += 1;
return KICK;
}
Actions PlayerActions::laserAction(int &t, glm::vec3 &vel, int facing, std::vector<CollisionBox> &hitboxList){
float vel_curve[4] = { 0.5, 1, 0.5, 0 };
float casttime = 2;
float recovery = 30;
deactivateAllHitbox(hitboxList);
if (t > casttime + recovery)
return IDLE;
int laserVel = -55;
if (t<casttime){
activateHitbox(hitboxList[LASERBOX]);
glm::vec3 pos = hitboxList[LASERBOX].GetSceneGraphObject()->GetLocalPosition();
hitboxList[LASERBOX].GetSceneGraphObject()->SetLocalPosition(glm::vec3(0.f, 3.f,25.f));
vel.y = 0;
vel.x = Bezier(vel_curve, 1, (float)t / casttime)*laserVel*facing;
}
if (t>casttime){
vel.x = 0;
deactivateHitbox(hitboxList[LASERBOX]);
}
t += 1;
return LASER;
}
Actions PlayerActions::blastAction(int &t, glm::vec3 &vel, std::vector<CollisionBox> &hitboxList){
float casttime = 20;
float recovery = 15;
deactivateAllHitbox(hitboxList);
if (t > casttime + recovery)
return IDLE;
if (t < casttime){
activateHitbox(hitboxList[BLASTBOX]);
hitboxList[BLASTBOX].GetCollisionBox()->GetSceneGraphObject()->SetScale(glm::vec3(30.f*((float)t / casttime), 20.f*((float)t / casttime), 10.f*((float)t / casttime)));
vel.x = 0;
vel.y = 0;
}
if (t > casttime)
deactivateHitbox(hitboxList[BLASTBOX]);
t += 1;
return BLAST;
}
Actions PlayerActions::blockAction(int &t, glm::vec3 &vel, std::vector<CollisionBox> &hitboxList, int &sp){
deactivateAllHitbox(hitboxList);
//if not enough sp left then can't block
if(sp < 100)
return IDLE;
//stop movement while blocking
vel.x = 0;
vel.y = 0;
//update timer, reduce sp
t+=1;
sp -= 20;
return IDLE;
}
Actions PlayerActions::staggerGAction(int &t, glm::vec3 &vel, int facing, std::vector<CollisionBox> &hitboxList, int &hasBeenHit){
float vel_curve[4] = { 1, 0.8, 0.5, 0 };
float casttime = 10;
float recovery = 5;
deactivateAllHitbox(hitboxList);
if (t > casttime + recovery){
hasBeenHit = 0;
return IDLE;
}
int staggerGVel = -150;
if (t < casttime)
vel.x = Bezier(vel_curve, 1, (float)t / casttime)*staggerGVel*facing;
t += 1;
return STAGGER_G;
}
Actions PlayerActions::staggerAAction(int &t, glm::vec3 &vel, int facing, std::vector<CollisionBox> &hitboxList, int &hasBeenHit){
float vel_curveX[4] = { 1, 0.4, 0.4, 0 };
float casttime = 10;
float recovery = 5;
float staggerAVelX = -150;
deactivateAllHitbox(hitboxList);
if (t > casttime + recovery){
hasBeenHit = 0;
return IDLE;
}
hasBeenHit += 1;
if (t < casttime){
vel.x = Bezier(vel_curveX, 1, t / casttime)*staggerAVelX*facing;
vel.y = 0;
}
t += 1;
return STAGGER_A;
}
Actions PlayerActions::idleAction(int &t, std::vector<CollisionBox> &hitboxList){
t = 0;
deactivateAllHitbox(hitboxList);
return IDLE;
}