-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game Event.h
452 lines (398 loc) · 8.32 KB
/
Game Event.h
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#ifndef GAME_EVENT_H_
#define GAME_EVENT_H_
#include <SDL.h>
#include "globals.h"
#include "Image Processing.h"
#include "Enemy.h"
//A game event is to trigger some actions (like spawn monsters, open/close,\
doors, whatever) whenever the kid collides with a box. Maybe other things can trigger\
events?
class Game_Event
{
public:
Game_Event(double x, double y, double w, double h) :
event_box_(Rect(x, y, w, h)),
activated_(false),
done_(false)
{}
virtual void logic() = 0;
virtual ~Game_Event() {}
void activate_if_ready();
void remove_event()
{
done_ = true;
}
void reset_event()
{
activated_ = false;
}
//return true if activated is true and done is false
inline bool activated()
{
return activated_ && done_ == false;
}
bool done()
{
if (done_)
delete this;
return done_;
}
protected:
//When The Kid laps over this rect, the Event begins
Rect event_box_;
bool activated_;
bool done_;
};
class First_Event : public Game_Event
{
public:
First_Event() :
Game_Event(160, 352, 32, 200),
timer_(0),
the_state_(Pause_Character_Movement),
current_spawn_point(0)
{
for (int x = 0; x != NUMBER_OF_ENEMIES; ++x)
{
spawn_times[x] = 400 * x + 1;
}
}
void logic();
private:
enum First_Event_Steps
{
Pause_Character_Movement,
Close_Doors,
Spawn_Some_Stuff,
Wait,
Open_Doors
};
const static int NUMBER_OF_ENEMIES = 32;
double spawn_times[NUMBER_OF_ENEMIES];
Enemy* event_enemies[NUMBER_OF_ENEMIES];
const static double PAUSE_CHARACTER_TIME;
const static double SPAWN_LOCATION_A_X;
const static double SPAWN_LOCATION_Y;
const static double SPAWN_LOCATION_B_X;
const static double SPAWN_LOCATION_C_X;
const static double SPAWN_LOCATION_D_X;
First_Event_Steps the_state_;
double timer_;
int current_spawn_point;
};
class Yellow_Switch_Event : public Game_Event
{
public:
Yellow_Switch_Event() :
Game_Event(0, 0, 0, 0),
current_position_(0),
timer_(0)
{
int counter = 0;
int current_time = 1;
int current_position_x = 26;
int current_position_y = 32;
for (current_position_x = 26; current_position_x != 40; current_position_x++)
{
counter_x[counter] = current_position_x;
counter_y[counter] = current_position_y;
time[counter] = current_time;
counter++;
current_time += 500;
}
current_position_y--;
current_time += 1500;
for (current_position_x = 30; current_position_x != 36; current_position_x++)
{
counter_x[counter] = current_position_x;
counter_y[counter] = current_position_y;
time[counter] = current_time;
counter++;
current_time += 2000;
}
current_time += 5000;
current_position_y--;
for (current_position_x = 32; current_position_x != 34; current_position_x++)
{
counter_x[counter] = current_position_x;
counter_y[counter] = current_position_y;
time[counter] = current_time;
counter++;
current_time += 100;
}
activated_ = true;
}
void logic();
private:
int timer_;
int counter_x[22];
int counter_y[22];
int time[22];
int current_position_;
};
class Moon_Spawner : public Game_Event
{
public:
Moon_Spawner();
void logic();
private:
const static double SPAWN_FREQUENCY;
double timer_;
};
class Barry_Spawn_Event : public Game_Event
{
public:
Barry_Spawn_Event() :
Game_Event(0, 480, 1260, 48)
{}
void logic();
private:
};
class Left_Spring_Pressed_In_Barry_Fight : public Game_Event
{
public:
Left_Spring_Pressed_In_Barry_Fight() :
Game_Event(48, 511, 32, 16),
timer_(0)
{}
void logic();
private:
const static double SPEED;
double timer_;
};
class Right_Spring_Pressed_In_Barry_Fight : public Game_Event
{
public:
Right_Spring_Pressed_In_Barry_Fight() :
Game_Event(944, 511, 32, 16),
timer_(0)
{}
void logic();
private:
const static double SPEED;
double timer_;
};
class Barry_Dead_Event : public Game_Event
{
public:
Barry_Dead_Event() :
Game_Event(0, 0, 0, 0),
timer_(0)
{
activated_ = true;
}
void logic();
private:
double timer_;
};
class Big_Explosion_Event : public Game_Event
{
public:
Big_Explosion_Event(Rect box, int number_of_explosions, int frequency) :
Game_Event(0, 0, 0, 0),
box_(box),
timer_(0),
number_of_explosions_left_(number_of_explosions),
frequency_(frequency)
{
activated_ = true;
}
void logic();
private:
Rect box_;
int timer_;
int number_of_explosions_left_;
int frequency_;
};
class Destroy_Bridge_Event : public Game_Event
{
public:
Destroy_Bridge_Event(bool left);
void logic();
private:
int timer_;
const int frequency_;
int position_;
bool left_;
};
class Frog_Event : public Game_Event
{
public:
Frog_Event() :
Game_Event(784, 16, 32, 128),
timer_(0),
the_state_(Pause_Character_Movement),
current_spawn_point(0)
{
for (int x = 0; x != NUMBER_OF_ENEMIES; ++x)
{
spawn_times[x] = 400 * x + 1;
}
}
void logic();
private:
enum Frog_Event_Steps
{
Pause_Character_Movement,
Close_Doors,
Spawn_Some_Stuff,
Wait,
Open_Doors
};
const static int NUMBER_OF_ENEMIES = 32;
double spawn_times[NUMBER_OF_ENEMIES];
Enemy* event_enemies[NUMBER_OF_ENEMIES];
const static double PAUSE_CHARACTER_TIME;
const static double SPAWN_LOCATION_A_X;
const static double SPAWN_LOCATION_Y;
const static double SPAWN_LOCATION_B_X;
const static double SPAWN_LOCATION_C_X;
const static double SPAWN_LOCATION_D_X;
Frog_Event_Steps the_state_;
double timer_;
int current_spawn_point;
};
class Create_A_Door : public Game_Event
{
public:
Create_A_Door(int start_x, int start_y, int how_many, int frequency) :
Game_Event(0, 0, 0, 0),
spot_x_(start_x),
spot_y_(start_y),
how_many_(how_many),
frequency_(frequency),
timer_(0)
{
activated_ = true;
}
void logic();
private:
int spot_x_;
int spot_y_;
int how_many_;
int frequency_;
double timer_;
};
//Destroys a line of tiles in the y direction going from bottom to top
//It works the same way as Create_A_Door, except destroys the tiles
class Close_A_Door : public Game_Event
{
public:
//Put in the tile where the top of the door is. The same one you used
//to create a door.
Close_A_Door(int start_x, int start_y, int how_many, int frequency, char tile_id) :
Game_Event(0, 0, 0, 0),
spot_x_(start_x),
spot_y_(start_y),
how_many_(how_many),
frequency_(frequency),
timer_(0),
tile_id_(tile_id)
{
activated_ = true;
}
void logic();
private:
int spot_x_;
int spot_y_;
int how_many_;
int frequency_;
double timer_;
char tile_id_;
};
class Moving_Spikes_Screen : public Game_Event
{
public:
//Put in the tile where the top of the door is. The same one you used
//to create a door
Moving_Spikes_Screen() :
Game_Event(0, 0, 0, 0)
{
activated_ = true;
entry_pos_x_[0] = 4832;
entry_frequency_[0] = 1400;
entry_timer_[0] = 0;
new_velocity[0] = 110;
entry_pos_y_[0] = -96;
entry_pos_x_[1] = 4896;
entry_frequency_[1] = 1400;
entry_timer_[1] = 0;
new_velocity[1] = -110;
entry_pos_y_[1] = 672;
}
void logic();
private:
int entry_timer_[2];
int entry_frequency_[2];
int entry_pos_x_[2];
int entry_pos_y_[2];
int new_velocity[2];
};
class Falling_Spikes_Screen_1 : public Game_Event
{
public:
Falling_Spikes_Screen_1() :
Game_Event(5472, 48, 96, 500),
entry_frequency_(500),
timer_(0)
{
for (int x = 0; x != 4; x++)
{
entry_pos_x_[x] = 32 * x + 5472;
}
}
void logic();
private:
const int entry_frequency_;
int timer_;
int entry_pos_x_[4];
};
class Falling_Spikes_Screen_2 : public Game_Event
{
public:
//Put in the tile where the top of the door is. The same one you used
//to create a door.
Falling_Spikes_Screen_2() :
Game_Event(6208, 0, 100, 384)
{
for (int x = 0; x != 5; x++)
{
entry_pos_x_[x] = 160 * (x + 1) + 6198;
entry_frequency_[x] = 350 - (x * 45);
entry_timer_[x] = 0;
}
}
void logic();
private:
int entry_timer_[5];
int entry_frequency_[5];
int entry_pos_x_[5];
};
//Controls the trap in World 1 screen 4. I need to do this so blood will stick to\
the tiles and not the spikes, so nothing seems out of the ordinary.
class Troll_Spike_Platform : public Game_Event
{
public:
Troll_Spike_Platform() :
Game_Event(0, 0, 0, 0),
activation_box_(Rect(5600, 0, 96, 1000))
{
activated_ = true;
}
private:
void logic();
const Rect activation_box_;
};
class End_Game_Action : public Game_Event
{
public:
End_Game_Action();
void logic();
private:
Countdown i_won_;
Frequency_Timer fireworks_frequency_;
bool i_won_done_;
const int firework_entry_left_x;
const int firework_entry_right_x;
};
#endif