forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_enemy.cpp
145 lines (120 loc) · 3.65 KB
/
sprite_enemy.cpp
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
/*
* 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/>.
*/
// Headers
#include "battle_animation.h"
#include "game_enemy.h"
#include "game_screen.h"
#include "sprite_enemy.h"
#include "bitmap.h"
#include "cache.h"
#include "main_data.h"
#include "player.h"
#include <lcf/reader_util.h>
#include "output.h"
#include "feature.h"
#include "game_battle.h"
Sprite_Enemy::Sprite_Enemy(Game_Enemy* enemy)
: Sprite_Battler(enemy, enemy->GetTroopMemberId())
{
CreateSprite();
auto condition = Game_Battle::GetBattleCondition();
if ((condition == lcf::rpg::System::BattleCondition_none || condition == lcf::rpg::System::BattleCondition_initiative) && Feature::HasFixedEnemyFacingDirection()) {
fixed_facing = static_cast<FixedFacing>(lcf::Data::battlecommands.easyrpg_fixed_enemy_facing_direction);
}
}
Sprite_Enemy::~Sprite_Enemy() {
}
Game_Enemy* Sprite_Enemy::GetBattler() const {
return static_cast<Game_Enemy*>(Sprite_Battler::GetBattler());
}
void Sprite_Enemy::CreateSprite() {
sprite_name = ToString(GetBattler()->GetSpriteName());
hue = GetBattler()->GetHue();
SetX(GetBattler()->GetDisplayX());
SetY(GetBattler()->GetDisplayY());
// Not animated -> Monster
if (sprite_name.empty()) {
graphic = Bitmap::Create(0, 0);
SetOx(graphic->GetWidth() / 2);
SetOy(graphic->GetHeight() / 2);
SetBitmap(graphic);
ResetZ();
}
else {
FileRequestAsync* request = AsyncHandler::RequestFile("Monster", sprite_name);
request->SetGraphicFile(true);
request_id = request->Bind(&Sprite_Enemy::OnMonsterSpriteReady, this);
request->Start();
}
}
void Sprite_Enemy::OnMonsterSpriteReady(FileRequestResult* result) {
graphic = Cache::Monster(result->file);
SetOx(graphic->GetWidth() / 2);
SetOy(graphic->GetHeight() / 2);
bool hue_change = hue != 0;
if (hue_change) {
BitmapRef new_graphic = Bitmap::Create(graphic->GetWidth(), graphic->GetHeight());
new_graphic->HueChangeBlit(0, 0, *graphic, graphic->GetRect(), hue);
graphic = new_graphic;
}
SetBitmap(graphic);
ResetZ();
}
void Sprite_Enemy::Draw(Bitmap& dst) {
auto alpha = 255;
auto zoom = 1.0;
auto* enemy = static_cast<Game_Enemy*>(GetBattler());
const auto bt = enemy->GetBlinkTimer();
const auto dt = enemy->GetDeathTimer();
const auto et = enemy->GetExplodeTimer();
if (!enemy->Exists() && dt == 0 && et == 0) {
return;
}
if (bt % 10 >= 5) {
return;
}
if (dt > 0) {
alpha = 7 * dt;
} else if (et > 0) {
alpha = 12 * et;
zoom = static_cast<double>(20 - et) / 20.0 + 1.0;
}
if (enemy->IsTransparent()) {
alpha = 160 * alpha / 255;
}
SetOpacity(alpha);
SetZoomX(zoom);
SetZoomY(zoom);
SetTone(Main_Data::game_screen->GetTone());
SetX(enemy->GetDisplayX());
SetY(enemy->GetDisplayY());
SetFlashEffect(enemy->GetFlashColor());
if (fixed_facing != Disabled) {
SetFixedFlipX();
} else {
SetFlipX(enemy->IsDirectionFlipped());
}
Sprite_Battler::Draw(dst);
}
void Sprite_Enemy::Refresh() {
if (sprite_name != GetBattler()->GetSpriteName() || hue != GetBattler()->GetHue()) {
CreateSprite();
}
}
void Sprite_Enemy::ResetZ() {
Sprite_Battler::ResetZ();
}