Skip to content

Commit 9c6dd4c

Browse files
committed
Fix pan (position and behaviour after teleport)
1 parent 2d05f18 commit 9c6dd4c

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

src/game_map.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace {
6363
int scroll_speed;
6464

6565
boost::scoped_ptr<Game_Interpreter> interpreter;
66-
std::vector<EASYRPG_SHARED_PTR<Game_Interpreter>> free_interpreters;
66+
std::vector<EASYRPG_SHARED_PTR<Game_Interpreter> > free_interpreters;
6767
Game_Vehicle* vehicles[3];
6868

6969
bool pan_locked;
@@ -229,7 +229,6 @@ void Game_Map::SetupCommon(int _id) {
229229
for (int i = 0; i < 3; i++)
230230
vehicles[i]->Refresh();
231231

232-
pan_locked = false;
233232
pan_wait = false;
234233
pan_speed = 0;
235234

src/game_player.cpp

+36-30
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Game_Player::Game_Player():
3636
vehicle_getting_off(false),
3737
new_map_id(0),
3838
new_x(0),
39-
new_y(0) {
39+
new_y(0),
40+
last_pan_x(0),
41+
last_pan_y(0) {
4042
SetDirection(RPG::EventPage::Direction_down);
4143
SetMoveSpeed(4);
4244
}
@@ -199,6 +201,8 @@ void Game_Player::ReserveTeleport(int map_id, int x, int y) {
199201
new_map_id = map_id;
200202
new_x = x;
201203
new_y = y;
204+
last_pan_x = 0;
205+
last_pan_y = 0;
202206
}
203207

204208
void Game_Player::StartTeleport() {
@@ -225,8 +229,8 @@ bool Game_Player::IsTeleporting() const {
225229
}
226230

227231
void Game_Player::Center(int x, int y) {
228-
int center_x = (DisplayUi->GetWidth() / ( TILE_SIZE / 16) - TILE_SIZE * 2) * 8;
229-
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE / 16) - TILE_SIZE) * 8;
232+
int center_x = (DisplayUi->GetWidth() / (TILE_SIZE / 16) - TILE_SIZE * 2) * 8 - Game_Map::GetPanX();
233+
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE / 16) - TILE_SIZE) * 8 - Game_Map::GetPanY();
230234
int max_x = (Game_Map::GetWidth() - DisplayUi->GetWidth() / TILE_SIZE) * (SCREEN_TILE_WIDTH);
231235
int max_y = (Game_Map::GetHeight() - DisplayUi->GetHeight() / TILE_SIZE) * (SCREEN_TILE_WIDTH);
232236
Game_Map::SetDisplayX(max(0, min((x * SCREEN_TILE_WIDTH - center_x), max_x)));
@@ -248,36 +252,38 @@ void Game_Player::MoveTo(int x, int y) {
248252
}
249253

250254
void Game_Player::UpdateScroll(int last_real_x, int last_real_y) {
251-
int center_x = (DisplayUi->GetWidth() / (TILE_SIZE / 16) - TILE_SIZE * 2) * 8;
252-
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE / 16) - TILE_SIZE) * 8;
255+
int center_x = (DisplayUi->GetWidth() / (TILE_SIZE / 16) - TILE_SIZE * 2) * 8 - Game_Map::GetPanX();
256+
int center_y = (DisplayUi->GetHeight() / (TILE_SIZE / 16) - TILE_SIZE) * 8 - Game_Map::GetPanY();
257+
int dx = 0;
258+
int dy = 0;
259+
260+
if (!Game_Map::IsPanLocked()) {
261+
if ((real_x > last_real_x && real_x - Game_Map::GetDisplayX() > center_x) ||
262+
(real_x < last_real_x && real_x - Game_Map::GetDisplayX() < center_x)) {
263+
dx = real_x - last_real_x;
264+
}
265+
if ((real_y > last_real_y && real_y - Game_Map::GetDisplayY() > center_y) ||
266+
(real_y < last_real_y && real_y - Game_Map::GetDisplayY() < center_y)) {
267+
dy = real_y - last_real_y;
268+
}
269+
}
253270

254-
if (Game_Map::IsPanLocked())
255-
return;
271+
if (Game_Map::GetPanX() != last_pan_x || Game_Map::GetPanY() != last_pan_y) {
272+
dx += Game_Map::GetPanX() - last_pan_x;
273+
dy += Game_Map::GetPanY() - last_pan_y;
256274

257-
if (Game_Map::GetPanX() != 0 || Game_Map::GetPanY() != 0) {
258-
int dx = real_x - center_x + Game_Map::GetPanX() - Game_Map::GetDisplayX();
259-
int dy = real_y - center_y + Game_Map::GetPanY() - Game_Map::GetDisplayY();
260-
if (dx > 0)
261-
Game_Map::ScrollRight(dx);
262-
if (dx < 0)
263-
Game_Map::ScrollLeft(-dx);
264-
if (dy > 0)
265-
Game_Map::ScrollDown(dy);
266-
if (dy < 0)
267-
Game_Map::ScrollUp(-dy);
268-
} else {
269-
if (real_y > last_real_y && real_y - Game_Map::GetDisplayY() > center_y)
270-
Game_Map::ScrollDown(real_y - last_real_y);
271-
272-
if (real_x < last_real_x && real_x - Game_Map::GetDisplayX() < center_x)
273-
Game_Map::ScrollLeft(last_real_x - real_x);
274-
275-
if (real_x > last_real_x && real_x - Game_Map::GetDisplayX() > center_x)
276-
Game_Map::ScrollRight(real_x - last_real_x);
277-
278-
if (real_y < last_real_y && real_y - Game_Map::GetDisplayY() < center_y)
279-
Game_Map::ScrollUp(last_real_y - real_y);
275+
last_pan_x = Game_Map::GetPanX();
276+
last_pan_y = Game_Map::GetPanY();
280277
}
278+
279+
if (dx > 0)
280+
Game_Map::ScrollRight(dx);
281+
else if (dx < 0)
282+
Game_Map::ScrollLeft(-dx);
283+
if (dy > 0)
284+
Game_Map::ScrollDown(dy);
285+
else if (dy < 0)
286+
Game_Map::ScrollUp(-dy);
281287
}
282288

283289
void Game_Player::Update() {

src/game_player.h

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class Game_Player : public Game_Character {
102102
bool vehicle_getting_on;
103103
bool vehicle_getting_off;
104104
int new_map_id, new_x, new_y;
105+
int last_pan_x, last_pan_y;
105106
RPG::Music walking_bgm;
106107

107108
void UpdateScroll(int last_real_x, int last_real_y);

0 commit comments

Comments
 (0)