-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game.h
239 lines (202 loc) · 6.45 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
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
#ifndef _GAME_H_
#define _GAME_H_
#include <memory>
#include <list>
#include <string>
#include <vector>
#include <SDL2/SDL_mixer.h>
#include "Entity.h"
#include "Timer.h"
#include "Player.h"
#include "Vector.h"
#include "Colour.h"
#include "PhraseBook.h"
#include "EnemyWave.h"
#include "Powerup.h"
#include "Effect.h"
#include "Camera.h"
#include "Utils.h"
#include "SoundManager.h"
namespace typing
{
class Game
{
public:
// Methods
void Init();
void Update();
void Draw();
void OnKeyDown(SDL_Keycode keycode);
void OnType(char c);
void StartNewGame();
void Damage();
void EndGame(float pause = 0);
void StartShortenPhrases();
void AddEntity(const EntityPtr& ent)
{
ent->OnSpawn();
m_entities.push_back(ent);
}
void AddEffect(const EffectPtr& effect)
{
effect->OnSpawn();
m_effects.push_back(effect);
}
void AddEffect2d(const EffectPtr& effect)
{
effect->OnSpawn();
m_effects2d.push_back(effect);
}
void Pause(bool pause)
{
m_timer.Pause(pause);
m_paused = pause;
}
bool IsPaused() const
{
return m_paused;
}
void Activate(bool activate)
{
m_active = activate;
}
bool IsActive() const
{
return m_active;
}
const juzutil::Vector3& GetPlayerOrigin() const
{
return m_player.GetOrigin();
}
float GetTime() const
{
return m_timer.GetTime();
}
float GetFrameTime() const
{
return m_timer.GetFrameTime();
}
unsigned int GetLevel() const
{
return m_level;
}
const std::string& GetPhrase(PhraseBook::PhraseLength len)
{
return m_phrases.GetPhrase(len);
}
const std::string GetComboPhrase(unsigned int words,
PhraseBook::PhraseLength len)
{
return m_phrases.GetComboPhrase(words, len);
}
void MakeCharAvail(char c)
{
m_phrases.MakeCharAvail(c);
}
unsigned int GetScore() const
{
return m_score;
}
unsigned int GetMaxStreak() const
{
return m_maxStreak;
}
const Camera GetCam() const
{
return m_camera;
}
void AddExtraLife()
{
m_player.ExtraLife();
}
unsigned int GetCycles() const
{
return m_bossWaveCreator.Cycles();
}
// Singleton implementation
static Game& GetGame();
private:
// Constants/Enums
static const unsigned int GAME_START_LIVES = 3;
static const unsigned int END_GAME_SCREEN_PAUSE = 1;
static const unsigned int MAX_PROGRESS = 5000;
static const float FINAL_DEATH_PAUSE;
static const float MIN_POWERUP_SPAWN_TIME;
static const float MAX_POWERUP_SPAWN_TIME;
static const std::string HUD_FONT;
static const std::string ENDGAME_FONT;
static const std::string MISS_SOUND;
static const std::string TARGET_SOUND;
static const std::string GAME_MUSIC;
// Ctors/Dtors
// These are private in order to protect the singleton implementation.
Game();
Game(const Game& g);
// Typedefs
typedef std::list<EntityPtr> EntityList;
typedef std::list<EffectPtr> EffectList;
typedef std::vector<EnemyWavePtr> WaveVec;
// Methods
void SpawnEnemies();
void SpawnPowerups();
void DrawHud();
void DrawBackground();
void DrawEndScreen();
void PhraseFinished(EntityPtr &ent);
bool IsAlive() const
{
return (m_player.Lives() > 0);
}
bool HasGameEnded() const
{
return (m_gameEndTime != 0.0f && GetTime() >= m_gameEndTime);
}
// Members
Camera m_camera;
EntityList m_entities;
EntityWeakPtr m_targetEnt;
Player m_player;
EffectList m_effects;
EffectList m_effects2d;
bool m_streakValid;
bool m_active;
bool m_paused;
bool m_invincible;
Timer m_timer;
unsigned int m_score;
unsigned int m_streak;
float m_gameEndTime;
PhraseBook m_phrases;
Mix_Music *m_music;
PowerupFactory m_powerups;
float m_nextPowerupTime;
unsigned int m_level;
float m_nextLevelTime;
float m_damageTime;
float m_shortenPhrasesTime;
// Enemy spawn variables
RandomEnemyWaveFactory m_waveCreator;
WaveVec m_activeWaves;
float m_nextWaveTime;
CyclicEnemyWaveFactory m_bossWaveCreator;
WaveVec m_bossWaves;
WaveVec::size_type m_nextBossWaveIndex;
bool m_bossWavePending;
float m_bossWaveStartTime;
bool m_bossWaveActive;
// Stats
unsigned int m_hits;
unsigned int m_misses;
unsigned int m_excellents;
unsigned int m_goods;
unsigned int m_oks;
unsigned int m_poors;
unsigned int m_bads;
unsigned int m_usedLives;
unsigned int m_maxStreak;
// Singleton implementation
static std::auto_ptr<Game> m_singleton;
};
#define GAME Game::GetGame()
}
#endif // _GAME_H_