forked from twig33/ynoclient
-
Notifications
You must be signed in to change notification settings - Fork 8
/
battle_animation.h
179 lines (147 loc) · 5.31 KB
/
battle_animation.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
/*
* 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_BATTLE_ANIMATION_H
#define EP_BATTLE_ANIMATION_H
// Headers
#include "game_battler.h"
#include "game_character.h"
#include "system.h"
#include <lcf/rpg/animation.h>
#include "drawable.h"
#include "sprite_battler.h"
struct FileRequestResult;
// BattleAnimation is responsible for playing an animation.
// It's an abstract class; there are derived classes below
// that can be used, depending on what is targeted.
class BattleAnimation : public Sprite {
public:
/** Update the animation to the next animation **/
void Update();
/** @return the current timing frame (2x the number of frames in the underlying animation **/
int GetFrame() const;
/** @return the animation frame that is currently being displayed **/
int GetRealFrame() const;
/** @return the number of frames the animation will play for **/
int GetFrames() const;
/** @return the number of frames in the underlying animation **/
int GetRealFrames() const;
/**
* Set the current running frame
*
* @param frame the frame to set.
**/
void SetFrame(int frame);
/** @return true if the animation has finished **/
bool IsDone() const;
/** @return true if the animation only plays audio and doesn't display **/
bool IsOnlySound() const;
/**
* @return the animation cell width
*/
int GetAnimationCellWidth() const;
/**
* @return the animation cell height
*/
int GetAnimationCellHeight() const;
/**
* Set if the animation is inverted
*
* @param inverted if the animation is inverted
**/
void SetInvert(bool inverted);
protected:
BattleAnimation(const lcf::rpg::Animation& anim, bool only_sound = false, int cutoff = -1);
virtual void FlashTargets(int r, int g, int b, int p) = 0;
virtual void ShakeTargets(int str, int spd, int time) = 0;
void DrawAt(Bitmap& dst, int x, int y);
virtual void ProcessAnimationTiming(const lcf::rpg::AnimationTiming& timing);
virtual void ProcessAnimationFlash(const lcf::rpg::AnimationTiming& timing);
void OnBattleSpriteReady(FileRequestResult* result);
void OnBattle2SpriteReady(FileRequestResult* result);
virtual void UpdateScreenFlash();
virtual void UpdateTargetFlash();
void UpdateFlashGeneric(int timing_idx, int& r, int& g, int& b, int& p);
const lcf::rpg::Animation& animation;
int frame = 0;
int num_frames = 0;
int screen_flash_timing = -1;
int target_flash_timing = -1;
FileRequestBinding request_id;
bool only_sound = false;
bool invert = false;
};
// For playing animations on the map.
class BattleAnimationMap : public BattleAnimation {
public:
BattleAnimationMap(const lcf::rpg::Animation& anim, Game_Character& target, bool global);
void Draw(Bitmap& dst) override;
protected:
void FlashTargets(int r, int g, int b, int p) override;
void ShakeTargets(int str, int spd, int time) override;
void DrawSingle(Bitmap& dst);
void DrawGlobal(Bitmap& dst);
Game_Character& target;
bool global = false;
};
// For playing animations against a (group of) battlers in battle.
class BattleAnimationBattle : public BattleAnimation {
public:
BattleAnimationBattle(const lcf::rpg::Animation& anim, std::vector<Game_Battler*> battlers, bool only_sound = false, int cutoff_frame = -1, bool set_invert = false);
void Draw(Bitmap& dst) override;
protected:
void FlashTargets(int r, int g, int b, int p) override;
void ShakeTargets(int str, int spd, int time) override;
std::vector<Game_Battler*> battlers;
};
class BattleAnimationBattler : public BattleAnimation {
public:
BattleAnimationBattler(const lcf::rpg::Animation& anim, std::vector<Game_Battler*> battlers, bool only_sound = false, int cutoff_frame = -1, bool set_invert = false);
void Draw(Bitmap& dst) override;
protected:
void FlashTargets(int r, int g, int b, int p) override;
void ShakeTargets(int str, int spd, int time) override;
void ProcessAnimationTiming(const lcf::rpg::AnimationTiming& timing) override;
void ProcessAnimationFlash(const lcf::rpg::AnimationTiming& timing) override;
void UpdateScreenFlash() override;
void UpdateTargetFlash() override;
std::vector<Game_Battler*> battlers;
};
inline int BattleAnimation::GetFrame() const {
return frame;
}
inline int BattleAnimation::GetRealFrame() const {
return GetFrame() / 2;
}
inline int BattleAnimation::GetFrames() const {
return num_frames;
}
inline int BattleAnimation::GetRealFrames() const {
return animation.frames.size();
}
inline bool BattleAnimation::IsDone() const {
return GetFrame() >= GetFrames();
}
inline bool BattleAnimation::IsOnlySound() const {
return only_sound;
}
inline int BattleAnimation::GetAnimationCellWidth() const {
return (animation.large ? 128 : 96);
}
inline int BattleAnimation::GetAnimationCellHeight() const {
return (animation.large ? 128 : 96);
}
#endif