@@ -36,7 +36,9 @@ Game_Player::Game_Player():
36
36
vehicle_getting_off(false ),
37
37
new_map_id(0 ),
38
38
new_x(0 ),
39
- new_y(0 ) {
39
+ new_y(0 ),
40
+ last_pan_x(0 ),
41
+ last_pan_y(0 ) {
40
42
SetDirection (RPG::EventPage::Direction_down);
41
43
SetMoveSpeed (4 );
42
44
}
@@ -199,6 +201,8 @@ void Game_Player::ReserveTeleport(int map_id, int x, int y) {
199
201
new_map_id = map_id;
200
202
new_x = x;
201
203
new_y = y;
204
+ last_pan_x = 0 ;
205
+ last_pan_y = 0 ;
202
206
}
203
207
204
208
void Game_Player::StartTeleport () {
@@ -225,8 +229,8 @@ bool Game_Player::IsTeleporting() const {
225
229
}
226
230
227
231
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 () ;
230
234
int max_x = (Game_Map::GetWidth () - DisplayUi->GetWidth () / TILE_SIZE) * (SCREEN_TILE_WIDTH);
231
235
int max_y = (Game_Map::GetHeight () - DisplayUi->GetHeight () / TILE_SIZE) * (SCREEN_TILE_WIDTH);
232
236
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) {
248
252
}
249
253
250
254
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
+ }
253
270
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;
256
274
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 ();
280
277
}
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);
281
287
}
282
288
283
289
void Game_Player::Update () {
0 commit comments