forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_airshipshadow.cpp
81 lines (68 loc) · 2.53 KB
/
sprite_airshipshadow.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
/*
* 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 "cache.h"
#include "bitmap.h"
#include "game_map.h"
#include "game_player.h"
#include "game_system.h"
#include "main_data.h"
#include "sprite_airshipshadow.h"
#include <string>
Sprite_AirshipShadow::Sprite_AirshipShadow(int x_offset, int y_offset) :
x_offset(x_offset), y_offset(y_offset) {
SetBitmap(Bitmap::Create(16,16));
SetOx(TILE_SIZE/2);
SetOy(TILE_SIZE);
RecreateShadow();
}
// Draws the two shadow sprites to a single intermediate bitmap to be blit to the map
// Needs to be recalled when the System graphic changes
void Sprite_AirshipShadow::RecreateShadow() {
GetBitmap()->Clear();
// RPG_RT never displays shadows if there is no system graphic.
BitmapRef system = Cache::System();
if (!system) {
return;
}
// Offset of the shadow in the System graphic as per
// https://wiki.easyrpg.org/development/technical-details/system-graphics
// TODO 26% opacity looks okay, but isn't accurate to RPG_RT
Opacity opacity = Opacity(0.26 * 255);
GetBitmap()->Blit(0, 0, *system, Rect(128,32,16,16), opacity);
GetBitmap()->Blit(0, 0, *system, Rect(128+16,32,16,16), opacity);
}
void Sprite_AirshipShadow::Draw(Bitmap &dst) {
Game_Vehicle* airship = Game_Map::GetVehicle(Game_Vehicle::Airship);
const int altitude = airship->GetAltitude();
const int max_altitude = TILE_SIZE;
const double opacity = (double)altitude / max_altitude;
SetOpacity(opacity * 255);
SetX(Main_Data::game_player->GetScreenX() + x_offset);
SetY(Main_Data::game_player->GetScreenY() + y_offset + Main_Data::game_player->GetJumpHeight());
Sprite::Draw(dst);
}
void Sprite_AirshipShadow::Update() {
if (!Main_Data::game_player->InAirship()) {
SetVisible(false);
return;
}
SetVisible(true);
Game_Vehicle* airship = Game_Map::GetVehicle(Game_Vehicle::Airship);
// Synchronized with airship priority
SetZ(airship->GetScreenZ(x_offset, y_offset) - 1);
}