-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSave Box.h
279 lines (243 loc) · 5.01 KB
/
Save Box.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
#ifndef SAVE_BOX_H
#define SAVE_BOX_H
#include <SDL.h>
#include "Image Processing.h"
#include "timer.h"
#include "globals.h"
#include "Smart Object.h"
#include "Special Platform.h"
#include <fstream>
#include <vector>
class Save_Switch : public Special_Platform
{
public:
Save_Switch(double x, double y, bool wussify) :
Special_Platform(x, y, 32, 32),
the_state_(Checking),
wuss_(wussify)
{
add_new_texture(Pic::save_switch_idle);
add_new_texture(Pic::save_switch_pressed);
add_new_texture(Pic::wuss_switch_idle);
add_new_texture(Pic::wuss_switch_pressed);
}
void logic();
private:
enum Switch_State
{
Checking,
Waiting,
Pressed
};
Switch_State the_state_;
bool wuss_;
};
class Save_Box : public Smart_Object
{
public:
Save_Box(double x, double y) :
Smart_Object(x, y),
saving_(false),
save_animation_timer_(0)
{
Pic::save_box_idle->init();
Pic::save_box_saving->init();
the_pics_.push_back(Pic::save_box_idle);
the_pics_.push_back(Pic::save_box_saving);
}
inline Rect the_box()
{
Rect new_rect(location_.x, location_.y, WIDTH, HEIGHT);
return new_rect;
}
void logic();
private:
int save_animation_timer_;
bool saving_;
const static int SAVE_ANIMATION_DURATION = 600;
const static double HEIGHT;
const static double WIDTH;
};
class Wuss_Box : public Save_Box
{
public:
Wuss_Box(double x, double y) :
Save_Box(x, y)
{
the_pics_.clear();
Pic::wuss_box_idle->init();
Pic::wuss_box_saving->init();
the_pics_.push_back(Pic::wuss_box_idle);
the_pics_.push_back(Pic::wuss_box_saving);
}
};
class Common_Save_Data
{
public:
Common_Save_Data(string file_name) :
file_name_(file_name)
{
open_from_file();
}
void open_from_file()
{
ifstream save_file(file_name_);
save_file >> blood_intensity_;
save_file >> sound_volume_;
save_file >> music_volume_;
}
int music_volume()
{
return music_volume_;
}
int sound_volume()
{
return sound_volume_;
}
int blood_intensity()
{
return blood_intensity_;
}
void update_and_save(int blood_intensity, int sound_volume, int music_volume)
{
blood_intensity_ = blood_intensity;
sound_volume_ = sound_volume;
music_volume_ = music_volume;
write_to_file();
}
void write_to_file()
{
ofstream save_data(file_name_);
save_data.clear();
save_data << blood_intensity_ << "\n";
save_data << sound_volume_ << "\n";
save_data << music_volume_ << "\n";
}
private:
string file_name_;
int blood_intensity_;
int sound_volume_;
int music_volume_;
};
class Save_File
{
public:
Save_File(string file_name) :
file_name_(file_name)
{
open_from_file();
}
//Called at the end of every function that changes save data.
void open_from_file()
{
ifstream save_file(file_name_);
save_file >> player_name_;
save_file >> the_set_difficulty_;
save_file >> world_;
save_file >> screen_x_;
save_file >> screen_y_;
save_file >> character_position_x_;
save_file >> character_position_y_;
save_file >> death_counter_;
save_file >> reset_counter_;
save_file >> time_;
save_file >> has_star_;
save_file >> has_teleporter_;
}
bool has_star()
{
return has_star_;
}
string file_name()
{
return file_name_;
}
inline double character_position_x()
{
return character_position_x_;
}
inline double character_position_y()
{
return character_position_y_;
}
inline int world()
{
return world_;
}
inline int screen_x()
{
return screen_x_;
}
inline int screen_y()
{
return screen_y_;
}
inline int death_counter()
{
return death_counter_;
}
inline int reset_counter()
{
return reset_counter_;
}
inline long time()
{
return time_;
}
inline int difficulty()
{
return the_set_difficulty_;
}
inline void add_time(long value)
{
time_ += value;
}
bool has_teleporter()
{
return has_teleporter_;
}
void update_location_and_save(double position_x, double position_y);
void get_star_and_save();
void get_star_in_hard_mode();
void get_teleporter_and_save();
void increment_deaths_and_save();
void increment_resets_and_save();
void update_time_and_save();
private:
void write_to_file()
{
ofstream save_data(file_name_);
save_data.clear();
save_data << player_name_ << "\n";
save_data << the_set_difficulty_ << "\n";
save_data << world_ << "\n";
save_data << screen_x_ << "\n";
save_data << screen_y_ << "\n";
save_data << character_position_x_ << "\n";
save_data << character_position_y_ << "\n";
save_data << death_counter_ << "\n";
save_data << reset_counter_ << "\n";
save_data << time_ << "\n";
save_data << has_star_ << "\n";
save_data << has_teleporter_ << "\n";
}
string player_name_;
double character_position_x_;
double character_position_y_;
int world_;
int screen_x_;
int screen_y_;
int death_counter_;
int reset_counter_;
//Time spent playing a file in ms.
long time_;
const string file_name_;
int file_position_;
int the_set_difficulty_;
bool has_star_;
bool has_teleporter_;
};
extern Save_File* save_file;
extern Common_Save_Data* common_save_data;
inline void save_the_game(double new_position_x, double new_position_y);
#endif