added using faster scrolling speed also for teleporting
[rocksndiamonds.git] / src / game_bd / bd_graphics.c
index 43964906918c7e81472904d54d9b13182cc0df4d..2dce22248f7dbf09cbd0900d58cbd8f8f4c3460e 100644 (file)
@@ -232,6 +232,38 @@ int get_play_area_h(void)
   return play_area_h / cell_size;
 }
 
+static boolean player_out_of_window(GdGame *game, int player_x, int player_y)
+{
+  // if not yet born, we treat as visible. so cave will run.
+  // the user is unable to control an unborn player, so this is the right behaviour.
+  if (game->cave->player_state == GD_PL_NOT_YET)
+    return FALSE;
+
+  // check if active player is outside drawing area. if yes, we should wait for scrolling
+  if ((player_x * cell_size) < scroll_x ||
+      (player_x * cell_size + cell_size - 1) > scroll_x + play_area_w)
+  {
+    // but only do the wait, if the player SHOULD BE visible, ie. he is inside
+    // the defined visible area of the cave
+    if (game->cave->player_x >= game->cave->x1 &&
+       game->cave->player_x <= game->cave->x2)
+      return TRUE;
+  }
+
+  if ((player_y * cell_size) < scroll_y ||
+      (player_y * cell_size + cell_size - 1) > scroll_y + play_area_h)
+  {
+    // but only do the wait, if the player SHOULD BE visible, ie. he is inside
+    // the defined visible area of the cave
+    if (game->cave->player_y >= game->cave->y1 &&
+       game->cave->player_y <= game->cave->y2)
+      return TRUE;
+  }
+
+  // player is inside visible window
+  return FALSE;
+}
+
 /*
   SCROLLING
   
@@ -242,7 +274,7 @@ int get_play_area_h(void)
 boolean gd_scroll(GdGame *game, boolean exact_scroll, boolean immediate)
 {
   static int scroll_desired_x = 0, scroll_desired_y = 0;
-  boolean out_of_window;
+  static int scroll_speed_last = -1;
   int player_x, player_y, visible_x, visible_y;
   boolean changed;
 
@@ -264,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;
@@ -296,34 +333,12 @@ boolean gd_scroll(GdGame *game, boolean exact_scroll, boolean immediate)
        game->gfx_buffer[y][x] |= GD_REDRAW;
   }
 
-  // check if active player is visible at the moment.
-  out_of_window = FALSE;
-
-  // check if active player is outside drawing area. if yes, we should wait for scrolling
-  if ((player_x * cell_size) < scroll_x ||
-      (player_x * cell_size + cell_size - 1) > scroll_x + play_area_w)
-  {
-    // but only do the wait, if the player SHOULD BE visible, ie. he is inside
-    // the defined visible area of the cave
-    if (game->cave->player_x >= game->cave->x1 &&
-       game->cave->player_x <= game->cave->x2)
-      out_of_window = TRUE;
-  }
-
-  if ((player_y * cell_size) < scroll_y ||
-      (player_y * cell_size + cell_size - 1) > scroll_y + play_area_h)
-    // but only do the wait, if the player SHOULD BE visible, ie. he is inside
-    // the defined visible area of the cave
-    if (game->cave->player_y >= game->cave->y1 &&
-       game->cave->player_y <= game->cave->y2)
-      out_of_window = TRUE;
+  // if no scrolling required, reset last (potentially faster) scrolling speed
+  if (!changed)
+    scroll_speed_last = -1;
 
-  // if not yet born, we treat as visible. so cave will run.
-  // the user is unable to control an unborn player, so this is the right behaviour.
-  if (game->cave->player_state == GD_PL_NOT_YET)
-    return FALSE;
-
-  return out_of_window;
+  // check if active player is visible at the moment.
+  return player_out_of_window(game, player_x, player_y);
 }
 
 // returns true, if the given surface seems to be a c64 imported image.