-
Notifications
You must be signed in to change notification settings - Fork 1
/
WatermelonSmash.h
165 lines (142 loc) · 4 KB
/
WatermelonSmash.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
#ifndef __WatermelonSmash__
#define __WatermelonSmash__
#include <queue>
#include <algorithm>
#include <functional>
#include "includes.h"
#include "Clicks.h"
#include "Texture.h"
#include "Window.h"
#include "Sound.h"
#include "Program.h"
#include "FontEngine.h"
#include "Particle.h"
#include "Camera.h"
#include "ParticleSorter.h"
#define BULLET_SPD 20.0
#define MELON_DEPTH 4.0
#define MELON_TIME 30.0
#define MELON_SPAWN 0.5
#define MELON_LEFT -2.5
#define MELON_RIGHT 2.5
#define MELON_SWING 0.5
#define NUM_PARTICLES 50
#define EXPLOSION_TIME 50
class Watermelon {
public:
// constructor & deconstructor
Watermelon(Camera* _camera, Object *obj, float x) {
camera = _camera;
object = obj;
xPos = x;
// decide how big to make the watermelon
int num = Util::randF() * 10 + 1;
if (num <= 5) { // small = 50% chance, 2 hit break
maxHits = 2;
points = 5;
size = 2.0;
yPos = 1.3;
lifeSpan = 3;
}
else if (num <= 9) { // medium = 40% chance, 7 hit break
maxHits = 6;
points = 20;
size = 2.5;
yPos = 1.5;
lifeSpan = 4;
}
else if (num <= 10) { // large = 10% chance, 15 hit break
maxHits = 15;
points = 50;
size = 3.0;
yPos = 2.0;
lifeSpan = 5;
}
hits = maxHits;
scale = (size - 1.0)/(maxHits - 1);
yScale = (yPos - 1.0)/(maxHits - 1);
object->setPos(glm::vec3(xPos, yPos, MELON_DEPTH));
object->scale(glm::vec3(size, size, size));
object->updateRadius();
isRed = false;
}
virtual ~Watermelon() {
delete object;
}
// hits the watermelon and returns the score earned
int hit() {
int pEarned = 1;
hits--;
size -= scale;
yPos -= yScale;
// determine if the shell was broken
if (hits == 1) {
object->setTexture(textures[TEX_MELON_IN]);
}
// determine if the watermelon was broken
else if (hits == 0) {
pEarned = points;
}
object->setPos(glm::vec3(xPos, yPos, MELON_DEPTH));
object->scale(glm::vec3(size, size, size));
object->updateRadius();
return pEarned;
}
// getters
Object *object;
float hits, xPos, yPos, size, lifeSpan;
bool isRed;
private:
Camera* camera;
vector<tinyobj::shape_t> shapes;
vector<tinyobj::material_t> materials;
int maxHits, points;
float scale, yScale;
float timer;
};
class WatermelonSmash {
public:
// constructor & deconstructor
WatermelonSmash(GLuint _ShadeProg, Program* _particleProg, Camera* _camera, Sound* _sound);
virtual ~WatermelonSmash();
// clicks
void mouseClick(glm::vec3 direction, glm::vec4 point);
// called by main program
void step(Window* window);
// getters and setters
bool gameOver, gameStart;
private:
// Variables
Program *particleProg;
Camera* camera;
vector<Object*> bullets;
vector<Object*> misc_objects;
vector<tinyobj::shape_t> shapes;
vector<tinyobj::material_t> materials;
// Paticles
vector<vector<Particle*> > fireworks;
int numFireworks;
// time info for particles
float t, t0_disp, t_disp;
float h;
glm::vec3 g;
GLuint ShadeProg;
Sound* sound;
Object *hammer;
// Minigame variables
vector<Watermelon*> melons;
int score, numMelons, timeLMelon, timeRMelon;
double timeStart, timer, timeLeft, timeRight, timeSwing;
double ageRight, ageLeft;
bool spawnLeft, spawnRight;
// Minigame functions
void newMelon(float xPos);
void checkTime(Window *window);
void setUp();
void addNewFirework(glm::vec3 pos, float melonSize);
void particleStep();
// Text functions
void textStep(Window* window);
void printInstructions();
};
#endif