-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkausch.h
433 lines (356 loc) · 10.1 KB
/
mkausch.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
/********************************************************************
*
* Program: mkausch.h
* Authors: Michael Kausch (Group 1 - DAHM)
* Date Code Originated: 2/17/23
*
* Classes: Manu
* Uses:
* Creates a menu object based on num text params, size and position
**********************************************************************/
// INCLUDES
#pragma once
#include <GL/glx.h>
#include <iostream>
#include <new>
#include <sstream>
#include <chrono>
#include <time.h>
#include <cstdlib>
#include <list>
#include "Box.h"
#include "fonts.h"
#include "hzhang.h"
#define SUB_BLOCK_N 150
#define NUM_BLOCKY_BULLETS 5
using namespace std;
inline const int NUM_SOUNDS = 16;
// inline const int NUM_SONGS = 1;
enum PBType {HEALTH, COOLDOWN, DONUT};
// #define USE_OPENAL_SOUND
#ifdef USE_OPENAL_SOUND
#include </usr/include/AL/alut.h>
#endif //USE_OPENAL_SOUND
// const int U_TO_S = 1000000;
// const int SONG_LENGTH = U_TO_S * ((4 * 60) + 30);
class Menu
{
public:
// vars
Box boarder;
Box mainbox;
//float w, h, bw, bh; // width, height, boarder width, boarder height
float pos[3];
unsigned char color[3];
unsigned char bcolor[3];
int n_texts;
Rect *texts;
// Rect texts[4];
Box *t_boxs;
std::string *words;
int centering;
// constructors
Menu(int n_texts,
float _w, float _h,
float _x, float _y,
std::string* _words,
int _centering = 1);
~Menu();
// setters
// void setBcolor(int r, int g, int b); // sets boarder color
void setColor(int r, int g, int b); // sets mainbox color
void setPos(float x, float y, float z);
void setHighlight(Box * b);
void setOrigColor();
// getters
// unsigned char * get_tcolor();
// std::string getInfo(); // get debug info
// other
void draw();
Box* checkTBox(int x, int y);
} ;
class Timer
{
private:
// variables
std::chrono::time_point<std::chrono::system_clock> start;
double duration;
bool paused;
Timer * pause_timer;
double pause_duration;
public:
Timer(); // used to create a timer that counts up or dc about it expiring
// note: the isDone() function is pretty useless and you should
// be looking at getTime to see how long the timer has gone
// for
Timer(double sec); // used to create a timer that counts down and will tell
// you if it expires
~Timer();
// setters
void reset();
void pause();
void unPause();
// getters
int getTime(char);
bool isDone();
bool isPaused();
};
#ifdef USE_OPENAL_SOUND
class Sound
{
private:
ALuint alBuffers[NUM_SOUNDS];
ALuint alSources[NUM_SOUNDS];
ALuint menuQueueSource;
ALuint songQueueSource;
ALint buffersDone;
ALint buffersQueued;
bool is_intro;
bool is_game;
bool is_music_paused;
bool user_pause;
int current_track;
void initOpenal();
void closeOpenal();
string buildSongPath(string s);
string sound_names[NUM_SOUNDS] = {
"bullet_fire.wav",
"Edzes-64TheMagicNumber-intro8kHz.wav",
"beep.wav",
"boop.wav",
"Edzes-64TheMagicNumber-loop8kHz.wav",
"AdhesiveWombat-8bitAdventure_16kHz.wav",
"zap1.wav",
"zap2.wav",
"zap3.wav",
"zap4.wav",
"shield.wav",
"doosh.wav",
"doosh2.wav",
"explo3.wav",
"explo4.wav",
"zap2.wav"};
public:
// Source refers to the sound.
bool gun_shooting;
float m_vol;
float sfx_vol;
Sound();
~Sound();
void playStartTrack();
bool checkIntroBufferDone();
void resetBufferDone();
void loopIntro();
void setupGameMode();
string getSongName();
void pause();
void unpause();
void toggleUserPause();
bool getPause();
void rewindGameMusic();
void gunPlay(int btype);
void gunStop();
void doosh(int i = 0);
void shieldSFX();
void exploSFX();
void beep();
void boop();
void updateMusicVol();
void updateSFXVol();
void playZap2();
void bombExplosion();
};
#endif
class PowerBar
{
private:
Box total; // a box that is proportionate to the overall hp of the Item pointed to by itm
Box health; // a box that is proportionate to the size of the current hp of itm
Rect text;
PBType type;
const Toaster * tos; // item that this healthbar is attached to
const Item * itm; // item that this healthbar is attached to
const Donut * donut; // item that this healthbar is attached to
// void hp_resize(); // resizes hp box based on passed on item's health
public:
PowerBar(const Toaster & _tos_, PBType type, float x, float y);
PowerBar(const Item & _itm_, PBType type, float x, float y);
PowerBar(const Donut & _itm_, PBType _type_, float x, float y);
void draw();
};
class Blocky : public Item
{
private:
// void setRandColor();
void setRandPosition();
void initRotationVel();
// so it doesn't continuously damage it
Item sub_boxes[SUB_BLOCK_N];
int sb_angles[SUB_BLOCK_N];
int rot_speed[SUB_BLOCK_N];
int rot_angle[SUB_BLOCK_N];
list<Bullet> bullets;
double delay_t;
public:
bool was_hit; // set when the block strikes the toaster that fall
int point;
int bul_point;
bool gun_active;
// int lives;
Blocky(char type, bool gun_active);
~Blocky();
void reset(); // tests to see if the player killed poor forky
void draw(); // overload function to include redraw
void move();
bool isAlive();
bool didDamage();
void setHit();
void explode();
bool explode_done;
bool subScreenIn();
void gamereset();
bool subBoxCollision(Item & itm);
bool subBoxCollision(Entity & ent);
void setBulletVectors();
bool allBulletsGone();
Timer * delay;
int getPlayerRelativeQuad(float xvec, float yvec);
bool did_shoot;
bool removeBullet(list<Bullet>::iterator bul);
list<Bullet>::iterator bulCollision(Item & a);
list<Bullet>::iterator getEndBullets();
bool delayBlocky();
// inherited void Item::draw()
// inherited bool Item::ScreenOut()
// inherited bool Item::HP_check()
};
void setRandColor(Item & it);
void checkSound(void);
void checkLevel();
void initializeLogFile(ofstream & fout);
class Bomb
{
public:
// vars
// float radius;
float start_radius;
float curr_radius;
float stop_radius;
// float angle;
float pos[3];
float w, h;
float hitbox_dim[3];
Timer * bomb_timer;
// Item * shards;
unsigned char color[3];
unsigned char launch_color[3];
bool is_thrown;
bool is_exploding;
int num_bombs;
// bool is_gone;
GLuint * tex;
bool show_message;
Rect message;
// constructors
Bomb();
~Bomb();
// setters
void setColor(unsigned char * col, int r, int g, int b);
void setPos(float x, float y, float z);
// void setRad(float _r);
void launch();
void move();
void draw();
void explode();
void updateHitbox();
bool hitboxCollision(Item & itm);
bool hitboxCollision(Entity & ent);
bool collision(Item & itm);
bool collision(Entity & ent);
void toggleDisplayMessage();
int text_vel;
int text_accel;
// bool onScreen();
};
struct HighScore
{
string uname;
int score;
HighScore(string n, int s);
bool operator < (const HighScore & rhs);
bool operator == (const HighScore & rhs);
bool operator == (int val);
bool operator == (string str);
};
class Gamerecord
{
private:
void genFakeNames();
bool testConnection();
public:
int n = 0; // letter input index
// current gamers name, set for the first time when the first game ends
char gamer[10]; // type in name
HighScore * user_score; // struct of last scores info
int place; // index of the last score
int highscore; //the highest score in file
// string reName; //the name in the file
vector<HighScore> scores; // vector of all scores from highscore file
// true mean no record in it
// false means file exist
// bool delt;
Gamerecord();
~Gamerecord();
void submitRecord(int); // submits score to be added to list of scores
// and makes a new menu
bool getRecord(); // gets all the records (from local txt file currently)
void writeRecord();// writes out the records (to a local txt file currently)
void sortRecord(); // sorts the records
void addRecord(HighScore s); // adds a record
bool isHighScore(); // tests if the user's score is a high score
bool isTopTen(); // tests if the the scores is in top ten
Menu * hs_menu; // use menu class to display the names nicely
void makeMenu(); // makes the high score menu
};
class SoundBar
{
private:
float slider_left_stop_pos;
float slider_right_stop_pos;
//---------- design ---------------//
public: // ______________________________
Box boarder;// / ________________________ /
Box bckgr; // / / / /
Box leftb; // < L |
Box rightb; // | H >
Box line; // ----------
// _
Box slider; // <--|_| -->
float pos[3];
unsigned char color[3];
Rect texts[3];
std::string words[2];
float slider_position;
float * value;
float getSliderPosition();
void moveSliderDown();
void moveSliderUp();
std::string bar_name;
SoundBar(float * _val, float _x, float _y, std::string _bn_);
// ~SoundBar();
void draw();
Box* checkButtons(float x, float y);
// void setColor(int r, int g, int b);
void setOrigColor();
void setHighlight(Box * b);
// void move(float y
};
class FeatureModeBlock : public Box
{
private:
GLuint * tex;
public:
FeatureModeBlock();
void draw();
void setTexture();
};