fixed keeping vertical player position when wrapping in EM engine
[rocksndiamonds.git] / src / game_em / graphics.c
index 859fc298916b1b42926017fb16364d918b18dcb8..4ea90bd68e701aea885118c3b6931e7ca8ab1fb7 100644 (file)
@@ -73,44 +73,40 @@ void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
   int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
   int sxsize = (full_xsize < xsize ? full_xsize : xsize);
   int sysize = (full_ysize < ysize ? full_ysize : ysize);
+  int xxsize = MAX_BUF_XSIZE * TILEX - x;
+  int yysize = MAX_BUF_YSIZE * TILEY - y;
+  int xoffset = 2 * CAVE_BUFFER_XOFFSET * TILEX;
+  int yoffset = 2 * CAVE_BUFFER_YOFFSET * TILEY;
 
-  if (x < 2 * TILEX && y < 2 * TILEY)
+  if (x < xoffset && y < yoffset)
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              sxsize, sysize, sx, sy);
+    BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, sysize,
+              sx, sy);
   }
-  else if (x < 2 * TILEX && y >= 2 * TILEY)
+  else if (x < xoffset && y >= yoffset)
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              sxsize, MAX_BUF_YSIZE * TILEY - y,
+    BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, yysize,
               sx, sy);
-    BlitBitmap(screenBitmap, target_bitmap, x, 0,
-              sxsize, y - 2 * TILEY,
-              sx, sy + MAX_BUF_YSIZE * TILEY - y);
+    BlitBitmap(screenBitmap, target_bitmap, x, 0, sxsize, y - yoffset,
+              sx, sy + yysize);
   }
-  else if (x >= 2 * TILEX && y < 2 * TILEY)
+  else if (x >= xoffset && y < yoffset)
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              MAX_BUF_XSIZE * TILEX - x, sysize,
+    BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, sysize,
               sx, sy);
-    BlitBitmap(screenBitmap, target_bitmap, 0, y,
-              x - 2 * TILEX, sysize,
-              sx + MAX_BUF_XSIZE * TILEX - x, sy);
+    BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, sysize,
+              sx + xxsize, sy);
   }
   else
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
+    BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, yysize,
               sx, sy);
-    BlitBitmap(screenBitmap, target_bitmap, 0, y,
-              x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
-              sx + MAX_BUF_XSIZE * TILEX - x, sy);
-    BlitBitmap(screenBitmap, target_bitmap, x, 0,
-              MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
-              sx, sy + MAX_BUF_YSIZE * TILEY - y);
-    BlitBitmap(screenBitmap, target_bitmap, 0, 0,
-              x - 2 * TILEX, y - 2 * TILEY,
-              sx + MAX_BUF_XSIZE * TILEX - x, sy + MAX_BUF_YSIZE * TILEY - y);
+    BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, yysize,
+              sx + xxsize, sy);
+    BlitBitmap(screenBitmap, target_bitmap, x, 0, xxsize, y - yoffset,
+              sx, sy + yysize);
+    BlitBitmap(screenBitmap, target_bitmap, 0, 0, x - xoffset, y - yoffset,
+              sx + xxsize, sy + yysize);
   }
 }
 
@@ -558,7 +554,7 @@ static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
 void RedrawPlayfield_EM(boolean force_redraw)
 {
   boolean draw_new_player_location = FALSE;
-  boolean draw_new_player_location_fast = FALSE;
+  boolean draw_new_player_location_wrap = FALSE;
   boolean quick_relocation = setup.quick_switch;
   int max_center_distance_player_nr =
     getMaxCenterDistancePlayerNr(screen_x, screen_y);
@@ -597,11 +593,11 @@ void RedrawPlayfield_EM(boolean force_redraw)
     game.centered_player_nr = game.centered_player_nr_next;
 
     draw_new_player_location = TRUE;
-    draw_new_player_location_fast = game.set_centered_player_fast;
+    draw_new_player_location_wrap = game.set_centered_player_wrap;
     force_redraw = TRUE;
 
     game.set_centered_player = FALSE;
-    game.set_centered_player_fast = FALSE;
+    game.set_centered_player_wrap = FALSE;
   }
 
   if (game.centered_player_nr == -1)
@@ -637,8 +633,14 @@ void RedrawPlayfield_EM(boolean force_redraw)
     int screen_xx = VALID_SCREEN_X(sx);
     int screen_yy = VALID_SCREEN_Y(sy);
 
-    if (draw_new_player_location_fast)
+    if (draw_new_player_location_wrap)
+    {
+      // when wrapping around (horizontally), keep vertical player position
+      screen_yy = screen_y;
+
+      // scrolling for wrapping should be faster than for switching players
       wait_delay_value /= 4;
+    }
 
     SetVideoFrameDelay(wait_delay_value);