-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMapBlocks.h
396 lines (302 loc) · 9.03 KB
/
MapBlocks.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
#ifndef MapBlocks_H
#define MapBlocks_H
#include <SDL.h>
#include "Player.h"
#include "Enemy.h"
#include "CaveSystem.h"
#include "Kamikaze.h"
#include <vector>
#include "missile.h"
class WallBlock
{
public:
static const int block_side = 72;
static const int border = 1;
int CEILING_ABS_X;
int CEILING_ABS_Y;
int FLOOR_ABS_X;
int FLOOR_ABS_Y;
double CEILING_REL_X;
double CEILING_REL_Y;
double FLOOR_REL_X;
double FLOOR_REL_Y;
WallBlock();
WallBlock(int num);
};
class AllyPlaneBlock
{
public:
int ALLY_PLANE_ABS_Y;
int ALLY_PLANE_ABS_X;
double ALLY_PLANE_REL_Y;
double ALLY_PLANE_REL_X;
int ALLY_PLANE_HEIGHT;
int ALLY_PLANE_WIDTH;
AllyPlaneBlock();
AllyPlaneBlock(int LEVEL_WIDTH, int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
};
class HealthBlock
{
public:
int HEALTH_ABS_Y;
int HEALTH_ABS_X;
double HEALTH_REL_Y;
double HEALTH_REL_X;
int HEALTH_HEIGHT;
int HEALTH_WIDTH;
HealthBlock();
HealthBlock(int LEVEL_WIDTH,int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
};
class InfFireBlock
{
public:
int INF_FIRE_ABS_Y;
int INF_FIRE_ABS_X;
double INF_FIRE_REL_Y;
double INF_FIRE_REL_X;
int INF_FIRE_HEIGHT;
int INF_FIRE_WIDTH;
InfFireBlock();
InfFireBlock(int LEVEL_WIDTH,int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
};
class AutoFireBlock
{
public:
int AUTOFIRE_ABS_Y;
int AUTOFIRE_ABS_X;
double AUTOFIRE_REL_Y;
double AUTOFIRE_REL_X;
int AUTOFIRE_HEIGHT;
int AUTOFIRE_WIDTH;
AutoFireBlock();
AutoFireBlock(int LEVEL_WIDTH,int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
};
class InvincBlock
{
public:
int INVINCE_ABS_Y;
int INVINCE_ABS_X;
double INVINCE_REL_Y;
double INVINCE_REL_X;
int INVINCE_HEIGHT;
int INVINCE_WIDTH;
InvincBlock();
InvincBlock(int LEVEL_WIDTH,int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
};
class SmallBlock
{
public:
int SMALL_ABS_Y;
int SMALL_ABS_X;
double SMALL_REL_Y;
double SMALL_REL_X;
int SMALL_HEIGHT;
int SMALL_WIDTH;
SmallBlock();
SmallBlock(int LEVEL_WIDTH,int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
};
class Stalagmite
{
public:
int STALAG_ABS_Y;
int STALAG_ABS_X;
double STALAG_REL_Y;
double STALAG_REL_X;
int STALAG_HEIGHT;
int STALAG_WIDTH;
int hitboxWidth;
Stalagmite();
Stalagmite(int LEVEL_WIDTH,int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
int stalagShapeNum;
int alreadyExploded;
};
class Stalagtite
{
public:
int STALAG_ABS_Y;
int STALAG_ABS_X;
double STALAG_REL_Y;
double STALAG_REL_X;
int STALAG_HEIGHT;
int STALAG_WIDTH;
int hitboxWidth;
Stalagtite();
Stalagtite(int LEVEL_WIDTH,int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength);
int stalagShapeNum;
int beenShot;
int last_move;
int time_since_move;
float acceleration;
int terminalVelocityYValue = 360;
};
class Turret
{
public:
// Move and shooting times, needed for framerate-independent shooting
int time_since_move;
int last_move;
static const int SHOOT_FREQ = 3000;
// absolute coordinates of each Turret
int BLOCK_ABS_X;
int BLOCK_ABS_Y;
// coordinates of each Turret relative to camera
double BLOCK_REL_X;
double BLOCK_REL_Y;
int BLOCK_HEIGHT;
int BLOCK_WIDTH;
int BLOCK_SPRITE; // Map to which sprite image this Turret will use.
// 1 if bottom turret, 0 if top
int bottom;
SDL_Renderer* gRenderer;
Turret();
Turret(int LEVEL_WIDTH, int LEVEL_HEIGHT, SDL_Renderer *gRenderer, int cave_freq, int cave_width, int openAir, int openAirLength, SDL_Texture* missileSprite1, SDL_Texture* missileSprite2);
int getRelX();
int getRelY();
int getAbsX();
int getAbsY();
//defines the turret asset
SDL_Rect FB_sprite;
//defines the hitbox of the turret
SDL_Rect FB_hitbox;
SDL_Texture* missileSprite1;
SDL_Texture* missileSprite2;
Missile* handleFiring(int posX, int posY);
};
class Explosion
{
public:
// Variables needed to control the size of the explosion and make it disappear at the right time
int initial_explosion_size;
int final_explosion_size;
int explosion_speed;
int explosion_time;
double current_size;
// Absolute location of the explosion's center
double center_x;
double center_y;
// Absolute location of the explosion's top left corner
double abs_x;
double abs_y;
// Location relative to the camera
double rel_x;
double rel_y;
// True if the explosion stays in constant position relative to the camera, false otherwise
bool stationary;
//0 for explosion, 1 for dust cloud
int type;
Explosion();
Explosion(int x, int y, int size);
Explosion(int x_loc, int y_loc, int t, SDL_Renderer *gRenderer);
//defines the explosion
SDL_Rect hitbox;
};
class MapBlocks
{
public:
int BLOCKS_N;
int STALAG_N = 30;
int HEALTH_N;
int INF_FIRE_N;
int INVINCE_N;
int AUTOFIRE_N;
int SMALL_N;
int ALLY_N;
static const int BLOCK_HEIGHT = 100;
static const int BLOCK_WIDTH = 100;
int CEILING_N;
SDL_Renderer *gRenderer;
SDL_Texture* explosionSprite;
SDL_Texture* dustCloudSprite;
SDL_Texture* topTurretSprite;
SDL_Texture* bottomTurretSprite;
SDL_Texture* stalactiteSprite1;
SDL_Texture* stalactiteSprite2;
SDL_Texture* stalactiteSprite3;
SDL_Texture* stalactiteSprite4;
SDL_Texture* stalagmiteSprite1;
SDL_Texture* stalagmiteSprite2;
SDL_Texture* stalagmiteSprite3;
SDL_Texture* stalagmiteSprite4;
SDL_Texture* healthSprite;
SDL_Texture* mSprite1;
SDL_Texture* mSprite2;
SDL_Texture* infFireSprite;
SDL_Texture* invinceSprite;
SDL_Texture* autofireSprite;
SDL_Texture *smallSprite;
SDL_Texture *allySprite;
std::vector<Turret> blocks_arr;
std::vector<Stalagmite> stalagm_arr;
std::vector<Stalagtite> stalagt_arr;
std::vector<Explosion> explosion_arr;
std::vector<WallBlock> ceiling_arr;
std::vector<WallBlock> floor_arr;
std::vector<HealthBlock> health_arr;
std::vector<InfFireBlock> infFire_arr;
std::vector<InvincBlock> invince_arr;
std::vector<AutoFireBlock> autofire_arr;
std::vector<SmallBlock> small_arr;
std::vector<AllyPlaneBlock> ally_arr;
MapBlocks();
~MapBlocks();
MapBlocks(int LEVEL_WIDTH, int LEVEL_HEIGHT, SDL_Renderer *gr, int cave_freq, int cave_width, int openAir, int openAirLength, int diff);
bool checkCollide(int x, int y, int pWidth, int pHeight, int xTwo, int yTwo, int pTwoWidth, int pTwoHeight);
void moveBlocks(int camX, int camY);
void checkCollision(Player *p);
void checkCollision(Enemy *e);
bool checkCollision(Kamikaze *kam);
bool checkCollision(Missile* m);
int checkCollision(Bullet *b);
std::vector<Missile*> handleFiring(std::vector<Missile*> missiles, int posX, int posY);
std::vector<Stalagmite> getStalagmites();
std::vector<Stalagtite> getStalagtites();
std::vector<Turret> getTurrets();
void render(int SCREEN_WIDTH, int SCREEN_HEIGHT, SDL_Renderer *gRenderer, bool isCaveEnabled);
void addExplosion(int x, int y, int w, int h, int type);
private:
//Animation frequency
static const int ANIMATION_FREQ = 100;
// Sounds
Mix_Chunk *explosion_sound;
};
class BossBlocks
{
public:
std::vector<Explosion> explosion_arr;
std::vector<HealthBlock> health_arr;
std::vector<InfFireBlock> infFire_arr;
std::vector<InvincBlock> invince_arr;
std::vector<AutoFireBlock> autofire_arr;
std::vector<SmallBlock> small_arr;
std::vector<AllyPlaneBlock> ally_arr;
SDL_Renderer *gRenderer;
SDL_Texture* explosionSprite;
SDL_Texture* dustCloudSprite;
SDL_Texture* healthSprite;
SDL_Texture* infFireSprite;
SDL_Texture* invinceSprite;
SDL_Texture* autofireSprite;
SDL_Texture *smallSprite;
SDL_Texture *allySprite;
BossBlocks(int SCREEN_WIDTH, int SCREEN_HEIGHT, SDL_Renderer* gr, int diff);
~BossBlocks();
bool checkCollide(int x, int y, int pWidth, int pHeight, int xTwo, int yTwo, int pTwoWidth, int pTwoHeight);
void moveBlocks(double camShift);
void createPowerups();
void addExplosion(int x, int y, int w, int h, int type);
void addExplosion(int x, int y, int size);
void checkCollision(Player *p);
void renderPowerups(SDL_Renderer* gRenderer);
void renderExplosions(SDL_Renderer* gRenderer);
private:
// Margin is the minimum distance between powerups and the edge of the screen
static const int MARGIN = 100;
// Tracks the x position so that new powerups can be made every SCREEN_WIDTH pixels
double currentX;
int screen_width;
int screen_height;
int difficulty;
// Sounds
Mix_Chunk *explosion_sound;
};
#endif