forked from twig33/ynoclient
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgame_screen.h
263 lines (213 loc) · 6.22 KB
/
game_screen.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
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_GAME_SCREEN_H
#define EP_GAME_SCREEN_H
#include <vector>
#include <cassert>
#include "system.h"
#include "options.h"
#include "compiler.h"
#include "game_character.h"
#include "battle_animation.h"
#include "flash.h"
#include <lcf/rpg/savescreen.h>
class Game_Battler;
class Screen;
class Weather;
class Game_Screen {
public:
Game_Screen();
~Game_Screen();
void InitGraphics();
void SetSaveData(lcf::rpg::SaveScreen screen);
const lcf::rpg::SaveScreen& GetSaveData() const;
void TintScreen(int r, int g, int b, int s, int tenths);
void FlashOnce(int r, int g, int b, int s, int frames);
void FlashBegin(int r, int g, int b, int s, int frames);
void FlashEnd();
void FlashMapStepDamage();
void ShakeOnce(int power, int speed, int tenths);
void ShakeBegin(int power, int speed);
void ShakeEnd();
void SetWeatherEffect(int type, int strength);
void PlayMovie(std::string filename,
int pos_x, int pos_y, int res_x, int res_y);
void Update();
/**
* Returns the current screen tone.
*
* @return Tone
*/
Tone GetTone();
/**
* Returns the current flash color.
*
* @param current_level Current strength adjusted to 0-255
* @return Flash color
*/
Color GetFlashColor() const;
/**
* Returns the weather type
*
* @return Weather type
*/
int GetWeatherType();
/**
* Returns weather effect strength from (0 low to 2 high)
*
* @return Weather effect strength
*/
int GetWeatherStrength();
struct Particle {
int16_t t = 0;
int16_t x = 0;
int16_t y = 0;
// These are only used for sandstorm particles.
// RPG_RT uses double. We use float to save space.
int16_t alpha = 0;
float vx = 0.0;
float vy = 0.0;
float ax = 0.0;
float ay = 0.0;
};
const std::vector<Particle>& GetParticles();
enum WeatherType {
Weather_None,
Weather_Rain,
Weather_Snow,
Weather_Fog,
Weather_Sandstorm
};
/**
* Plays the given animation against a character.
*
* @param animation_id the animation ID
* @param target_id the ID of the targeted character
* @param global whether to "show on the entire map"
* @param start_frame which frame to start on.
*
* @return the number of frames the animation will run.
*/
int ShowBattleAnimation(int animation_id, int target_id, bool global, int start_frame = 0);
/**
* Update the currently running battle animation by 1 frame.
*/
void UpdateBattleAnimation();
/**
* Cancel the currently running battle animation.
*/
void CancelBattleAnimation();
/**
* Whether or not a battle animation is currently playing.
*/
bool IsBattleAnimationWaiting();
/** @return current pan_x offset for screen effects in 1/16 pixels */
int GetPanX() const;
/** @return current pan_y offset for screen effects in 1/16 pixels */
int GetPanY() const;
/** @return maximum pan_x offset for screen effects in 1/16 pixels */
static constexpr int GetPanLimitX();
/** @return maximum pan_y offset for screen effects in 1/16 pixels */
static constexpr int GetPanLimitY();
/** @return a Rect describing position and size of screen effects in pixels */
Rect GetScreenEffectsRect() const;
/** @return Return screen shake X offset */
int GetShakeOffsetX() const;
/** @return Return screen shake Y offset */
int GetShakeOffsetY() const;
/** To be called when the map changes */
void OnMapChange();
/** To be called when a battle ends */
void OnBattleEnd();
/**
* Called when map scrolls
*
* @param dx x distance in 1/16th pixels
* @param dy y distance in 1/16th pixels
*/
void OnMapScrolled(int dx, int dy);
private:
std::unique_ptr<BattleAnimation> animation;
std::unique_ptr<Weather> weather;
lcf::rpg::SaveScreen data;
int flash_sat; // RPGMaker bug: this isn't saved
int flash_period; // RPGMaker bug: this isn't saved
std::string movie_filename;
int movie_pos_x;
int movie_pos_y;
int movie_res_x;
int movie_res_y;
protected:
std::vector<Particle> particles;
void StopWeather();
void UpdateRain();
void UpdateSnow();
void UpdateFog();
void UpdateSandstorm();
void UpdateScreenEffects();
void UpdateMovie();
void UpdateWeather();
void UpdateFog(int dx, int dy);
void OnWeatherChanged();
void InitParticles(int n);
};
inline int Game_Screen::GetPanX() const {
return data.pan_x;
}
inline int Game_Screen::GetPanY() const {
return data.pan_y;
}
inline constexpr int Game_Screen::GetPanLimitX() {
return SCREEN_TARGET_WIDTH * 16;
}
inline constexpr int Game_Screen::GetPanLimitY() {
return SCREEN_TARGET_HEIGHT * 16 * 2 / 3;
}
inline Rect Game_Screen::GetScreenEffectsRect() const {
return Rect{ GetPanX() / 16, GetPanY() / 16, GetPanLimitX() / 16, GetPanLimitY() / 16 };
}
inline int Game_Screen::GetShakeOffsetX() const {
return data.shake_position;
}
inline int Game_Screen::GetShakeOffsetY() const {
return data.shake_position_y;
}
inline Tone Game_Screen::GetTone() {
return Tone((int) ((data.tint_current_red) * 128 / 100),
(int) ((data.tint_current_green) * 128 / 100),
(int) ((data.tint_current_blue) * 128 / 100),
(int) ((data.tint_current_sat) * 128 / 100));
}
inline Color Game_Screen::GetFlashColor() const {
return Flash::MakeColor(data.flash_red, data.flash_green, data.flash_blue, data.flash_current_level);
}
inline int Game_Screen::GetWeatherType() {
return data.weather;
}
inline int Game_Screen::GetWeatherStrength() {
return data.weather_strength;
}
inline const std::vector<Game_Screen::Particle>& Game_Screen::GetParticles() {
return particles;
}
inline bool Game_Screen::IsBattleAnimationWaiting() {
return (bool)animation;
}
inline const lcf::rpg::SaveScreen& Game_Screen::GetSaveData() const {
return data;
}
#endif