-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game.hpp
232 lines (156 loc) · 4.62 KB
/
Game.hpp
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
#pragma once
#include "SDL.h"
#include "SDL_image.h"
#include <stdio.h>
#include <string>
#include <array>
#include "Constants.hpp"
#include "Player.hpp"
#include "Spritesheet.hpp"
#include "InputManager.hpp"
#include "ParticleManager.hpp"
#include "TimerManager.hpp"
#include "Bezier.hpp"
#include "TextManager.hpp"
//#include "Utilities.hpp"
#include "LevelManager.hpp"
#include "TransitionManager.hpp"
#include "AudioManager.hpp"
#include "JSONManager.hpp"
#include "Assets.hpp"
// Game class
class Game {
public:
Game();
void run();
private:
bool init();
void quit();
void load_data();
void clear_data();
std::string find_assets_path(std::string test_file, uint8_t depth = 4);
void update(float dt);
void render();
// Update and render functions for each state
void update_menu_intro(float dt);
void render_menu_intro();
void update_menu_title(float dt);
void render_menu_title();
void update_menu_settings(float dt);
void render_menu_settings();
void update_menu_level_select(float dt);
void render_menu_level_select();
void update_game_running(float dt);
void render_game_running();
void update_game_paused(float dt);
void render_game_paused();
void update_game_end(float dt);
void render_game_end();
// Setup functions for each state
void setup_menu_intro();
void setup_menu_title();
void setup_menu_settings();
void setup_menu_level_select();
void setup_game_running(uint8_t level_number);
void setup_game_paused();
void setup_game_end();
void resume_game_running();
void restart_game();
// Transition functions
void render_fade_in_rect(float delay);
void render_fade_out_rect(float delay);
void render_fade_rect(uint8_t alpha);
std::pair<float, float> get_bezier_text_positions();
// Utility functions
void handle_menu_shape_particles();
ImageParticle create_menu_shape_particle();
ImageParticle create_game_finish_particle(float x, float y, uint8_t id);
void render_hint();
void fill_menu_shape_particle(uint8_t count);
void setup_menu_shape_particles();
bool level_is_completed();
void handle_music();
void load_save_data(std::string assets_path);
void write_save_data(std::string assets_path);
// Loading functions
SDL_Texture* load_texture(std::string path, bool display_errors = true);
SDL_Surface* load_surface(std::string path, bool display_errors = true);
enum class GameState {
MENU_INTRO,
MENU_TITLE,
MENU_SETTINGS,
MENU_LEVEL_SELECT,
GAME_RUNNING,
GAME_PAUSED,
GAME_END
};
enum class FadeState {
FADE,
UNFADE,
NONE
};
// Variables
// Main game window
SDL_Window* window = NULL;
// Renderer for window
SDL_Renderer* renderer = NULL;
// Audio
AudioHandler audio_handler;
// Spritesheet
SDL_Texture* spritesheet_texture = NULL;
Spritesheet spritesheet;
// Icon
SDL_Surface* window_icon_surface = NULL;
// Fonts
SDL_Texture* font_sheet_texture = NULL;
FontHandler::Font font_white, font_selected, font_highlighted, font_hint;// , font_title_blue, font_title_pink;
FontHandler::Font font_blue, font_pink; // temporary
// Input handler
InputHandler input_handler;
// Particle handler
struct {
ParticleHandler back, front, spare;
} particle_handlers;
// Timer handler
TimerHandler timer_handler;
// Transition handlers
TransitionHandler pause_transition, resetting_transition;//menu_transition,
// Player
Player player;
// Level handler
LevelHandler level_handler;
// State/data variables
// Game state
GameState game_state = GameState::MENU_INTRO;
// Fade state
FadeState fade_state = FadeState::NONE;
bool running = false;
bool paused = false;
bool resetting = false;
bool intro_music_started = false;
bool show_level_locked_message = false;
uint8_t option_selected = 0;
bool option_confirmed = false;
uint8_t current_level = 0;
uint8_t menu_shape_particle_count = 0;
// Todo: load/save from file
struct {
bool audio_music = true;
bool audio_sfx = true;
//bool show_hints = true;
uint8_t level_reached = 0;
std::vector<float> highscore_times;
std::vector<uint8_t> highscore_orbs;
} data;
struct {
bool time = false;
bool orbs = false;
} new_highscore;
std::string assets_path;
};
// Transition functions
// Not sure why can't be inside Game scope
void pause_transition_update(TransitionState* transition_state, float* timer, float dt);
void pause_transition_render(TransitionState* transition_state, float* timer, SDL_Renderer* renderer, Spritesheet& spritesheet);
void resetting_transition_update(TransitionState* transition_state, float* timer, float dt);
void resetting_transition_render(TransitionState* transition_state, float* timer, SDL_Renderer* renderer, Spritesheet& spritesheet);