forked from EasyRPG/Player
/
spriteset_map.cpp
122 lines (106 loc) · 3.79 KB
/
spriteset_map.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
/*
* 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 "spriteset_map.h"
#include "cache.h"
#include "game_map.h"
#include "main_data.h"
#include "sprite_airshipshadow.h"
#include "sprite_character.h"
#include "game_character.h"
#include "game_player.h"
#include "game_vehicle.h"
#include "bitmap.h"
// Constructor
Spriteset_Map::Spriteset_Map() {
tilemap.SetWidth(Game_Map::GetWidth());
tilemap.SetHeight(Game_Map::GetHeight());
ChipsetUpdated();
tilemap.SetMapDataDown(Game_Map::GetMapDataDown());
tilemap.SetMapDataUp(Game_Map::GetMapDataUp());
panorama.SetZ(-1000);
tEventHash events = Game_Map::GetEvents();
for (tEventHash::iterator i = events.begin(); i != events.end(); ++i) {
character_sprites.push_back(EASYRPG_MAKE_SHARED<Sprite_Character>(i->second.get()));
}
Game_Vehicle* vehicle;
for (int i = 1; i <= 3; ++i) {
vehicle = Game_Map::GetVehicle((Game_Vehicle::Type) i);
character_sprites.push_back(EASYRPG_MAKE_SHARED<Sprite_Character>(vehicle));
}
airship_shadow.reset(new Sprite_AirshipShadow());
character_sprites.push_back
(EASYRPG_MAKE_SHARED<Sprite_Character>(Main_Data::game_player.get()));
timer1.reset(new Sprite_Timer(0));
timer2.reset(new Sprite_Timer(1));
Update();
}
// Update
void Spriteset_Map::Update() {
tilemap.SetOx(Game_Map::GetDisplayX() / (SCREEN_TILE_WIDTH / TILE_SIZE));
tilemap.SetOy(Game_Map::GetDisplayY() / (SCREEN_TILE_WIDTH / TILE_SIZE));
tilemap.Update();
for (size_t i = 0; i < character_sprites.size(); i++) {
character_sprites[i]->Update();
}
const std::string& name = Game_Map::GetParallaxName();
if (name != panorama_name) {
panorama_name = name;
BitmapRef panorama_bmp = Cache::Panorama(panorama_name);
Game_Map::SetParallaxSize(panorama_bmp->GetWidth(), panorama_bmp->GetHeight());
panorama.SetBitmap(panorama_bmp);
Game_Map::InitializeParallax();
}
panorama.SetOx(Game_Map::GetParallaxX());
panorama.SetOy(Game_Map::GetParallaxY());
airship_shadow->Update();
timer1->Update();
timer2->Update();
}
// Finds the sprite for a specific character
Sprite_Character* Spriteset_Map::FindCharacter(Game_Character* character) const
{
std::vector<EASYRPG_SHARED_PTR<Sprite_Character> >::const_iterator it;
for (it = character_sprites.begin(); it != character_sprites.end(); ++it) {
Sprite_Character* sprite = it->get();
if (sprite->GetCharacter() == character)
return sprite;
}
return NULL;
}
void Spriteset_Map::ChipsetUpdated() {
if (!Game_Map::GetChipsetName().empty()) {
tilemap.SetChipset(Cache::Chipset(Game_Map::GetChipsetName()));
} else {
tilemap.SetChipset(Bitmap::Create(480, 256, true));
}
tilemap.SetPassableDown(Game_Map::GetPassagesDown());
tilemap.SetPassableUp(Game_Map::GetPassagesUp());
tilemap.SetAnimationType(Game_Map::GetAnimationType());
tilemap.SetAnimationSpeed(Game_Map::GetAnimationSpeed());
}
void Spriteset_Map::SystemGraphicUpdated() {
airship_shadow->RecreateShadow();
}
void Spriteset_Map::SubstituteDown(int old_id, int new_id) {
Game_Map::SubstituteDown(old_id, new_id);
tilemap.SubstituteDown(old_id, new_id);
}
void Spriteset_Map::SubstituteUp(int old_id, int new_id) {
Game_Map::SubstituteUp(old_id, new_id);
tilemap.SubstituteUp(old_id, new_id);
}