-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
209 lines (169 loc) · 7.15 KB
/
game.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
/*********************************************************************
* File: game.h
* Description: Defines the game class for Asteroids
*
*********************************************************************/
#include <vector>
#include "uiDraw.h"
#include "uiInteract.h"
#include "point.h"
#include "velocity.h"
#include "flyingObject.h"
#include "bullet.h"
#include "ship.h"
#include "rocks.h"
#include "powerUp.h"
#ifndef GAME_H
#define GAME_H
#define STARTING_SHIELD_TIME 49
#define CLOSE_ENOUGH 15
#define NEW_GAME_RELOAD_TIME 12
/*****************************************
* GAME
* The main game class containing all the state
*****************************************/
class Game
{
public:
/*********************************************
* Constructor
* Initializes the game
*********************************************/
Game(Point tl, Point br);
~Game();
/*********************************************
* Function: resetWin
* Description: Resets game after a win
*********************************************/
void resetWin();
/*********************************************
* Function: resetLose
* Description: Resets game after a lose
*********************************************/
void resetLose();
/*********************************************
* Function: handleInput
* Description: Takes actions according to whatever
* keys the user has pressed.
*********************************************/
void handleInput(const Interface & ui);
/*********************************************
* Function: advance
* Description: Move everything forward one
* step in time.
*********************************************/
void advance();
void advanceShip();
void advanceRocks();
void advanceBullets();
void advancePowerups();
/*********************************************
* Function: Handle Collisions
* Description: handles all collisions of objects
*********************************************/
void handleCollisions();
void rockBulletCollision();
void shipPowerCollision();
void rockShipCollision();
void bulletPowerCollision();
void rockRockCollision();
void handleRockCollision(Rock & rock1, Rock & rock2);
/*********************************************
* Function: draw
* Description: draws everything for the game.
*********************************************/
void draw(const Interface & ui);
/*********************************************
* Function: Create New Rocks
* Description: will call one of the next
* three functions based on the rock size
*********************************************/
void createNewRocks(Point p, Velocity V, int rockSize);
/*********************************************
* Function: Generate Big Rocks
* Description: Spawns Big Rocks at start
* and restart of game
*********************************************/
void generateBigRocks();
/*********************************************
* Function: Break Big Rock
* Description: Spawns 2 Medium Rocks and one
* small rock while suppying thier velocities
*********************************************/
void breakBigRock(Point p, Velocity v);
/*********************************************
* Function: Break Medium Rock
* Description: Spawns 2 Small Rocks while
* supplying their velocities
*********************************************/
void breakMediumRock(Point p, Velocity v);
/*********************************************
* Function: Clean Up Zombies
* Description: cleans up memory used for
* destroyed bullets and rocks
*********************************************/
void cleanUpZombies();
/*********************************************
* Function: release power up
* Description: release a power up
*********************************************/
void releasePowerUp();
/*********************************************
* Function: draw info
* Description: draws game info at the top of
* the screen
*********************************************/
void drawInfo();
//get maxX and maxY
float getMaxx() { return bottomRight.getX(); }
float getMaxy() { return topLeft.getY(); }
//get and set winFlag
void setWinFlag(bool flag) { winFlag = flag; }
bool getWinFlag() { return winFlag; }
//get and set loseFlag
void setLoseFlag(bool loseFlag) { this->loseFlag = loseFlag; }
bool getLoseFlag() { return loseFlag; }
//get and set loseFlagTime
void setLoseFlagTime(int loseFlagTime) { this->loseFlagTime = loseFlagTime; }
int getLoseFlagTime() { return loseFlagTime; }
//get and set time
void setTime(int time) { this->time = time; }
int getTime() { return time; }
//get and set lastAsteroidAdd
void setLastAsteroidAdd(int lastAsteroidAdd) { this->lastAsteroidAdd = lastAsteroidAdd; }
int getLastAsteroidAdd() { return lastAsteroidAdd; }
//get and set asteroidWait
void setAsteroidWait(int asteroidWait) { this->asteroidWait = asteroidWait; }
int getAsteroidWait() { return asteroidWait; }
//get and set powers
void setPowers(int powers) { this->powers = powers; }
int getPowers() { return powers; }
//get and set score
void setScore(int score) { this->score = score; }
int getScore() { return score; }
void setShowInfo(bool showInfo) { this->showInfo = showInfo; }
bool getShowInfo() { return showInfo; }
private:
// The coordinates of the screen
Point topLeft;
Point bottomRight;
//integer properties
int time; //how long the game has been going without a lose
int lastAsteroidAdd; //time since the last large asteroid was added
int asteroidWait; //time that the game will wait before adding a new asteroid
int powers; //how long the shield will be up for
int loseFlagTime; //timestamp of when the ship was destroyed
int score; //the number of small asteroids destroyed
//win & lose flags
bool winFlag;
bool loseFlag;
bool showInfo;
//function used to handle collisions
float getClosestDistance(FlyingObject &obj1, FlyingObject &obj2) const;
//objects in game
Ship ship;
std::vector<Bullet> bullets;
std::vector<Rock*> rocks;
std::vector<PowerUp> powerups;
};
#endif /* GAME_H */