added using faster scrolling speed also for teleporting
authorHolger Schemel <info@artsoft.org>
Tue, 26 Mar 2024 17:48:58 +0000 (18:48 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 26 Mar 2024 17:48:58 +0000 (18:48 +0100)
src/game_bd/bd_graphics.c

index cafd9b212702f21874062a70fed75987311e8d53..2dce22248f7dbf09cbd0900d58cbd8f8f4c3460e 100644 (file)
@@ -274,6 +274,7 @@ static boolean player_out_of_window(GdGame *game, int player_x, int player_y)
 boolean gd_scroll(GdGame *game, boolean exact_scroll, boolean immediate)
 {
   static int scroll_desired_x = 0, scroll_desired_y = 0;
+  static int scroll_speed_last = -1;
   int player_x, player_y, visible_x, visible_y;
   boolean changed;
 
@@ -295,13 +296,18 @@ boolean gd_scroll(GdGame *game, boolean exact_scroll, boolean immediate)
   player_x = game->cave->player_x - game->cave->x1; // cell coordinates of player
   player_y = game->cave->player_y - game->cave->y1;
 
-  // when wrapping around to opposite level border, use faster scrolling
-  if (game->cave->player_x == game->cave->x1 ||
-      game->cave->player_x == game->cave->x2 ||
-      game->cave->player_y == game->cave->y1 ||
-      game->cave->player_y == game->cave->y2)
+  // if player is outside visible playfield area, use faster scrolling
+  // (might happen when wrapping around the playfield, teleporting etc.)
+  if (player_out_of_window(game, player_x, player_y))
     scroll_speed *= 4;
 
+  // if scrolling started with player outside visible playfield area, keep faster scrolling
+  if (scroll_speed_last > scroll_speed)
+    scroll_speed = scroll_speed_last;
+
+  // store current (potentially faster) scrolling speed for next time
+  scroll_speed_last = scroll_speed;
+
   // pixel size of visible part of the cave (may be smaller in intermissions)
   visible_x = (game->cave->x2 - game->cave->x1 + 1) * cell_size;
   visible_y = (game->cave->y2 - game->cave->y1 + 1) * cell_size;
@@ -327,6 +333,10 @@ boolean gd_scroll(GdGame *game, boolean exact_scroll, boolean immediate)
        game->gfx_buffer[y][x] |= GD_REDRAW;
   }
 
+  // if no scrolling required, reset last (potentially faster) scrolling speed
+  if (!changed)
+    scroll_speed_last = -1;
+
   // check if active player is visible at the moment.
   return player_out_of_window(game, player_x, player_y);
 }