fixed bug with scrolling screen towards initially created player
authorHolger Schemel <holger.schemel@virtion.de>
Wed, 1 Jan 2025 13:32:30 +0000 (14:32 +0100)
committerHolger Schemel <holger.schemel@virtion.de>
Wed, 1 Jan 2025 13:32:32 +0000 (14:32 +0100)
src/game.c

index e4caad4ceef5c2c6e14811d2df5435c9093548da..d0ba94923350d0c627fe77a7ce9f77f75c152a98 100644 (file)
@@ -5857,13 +5857,22 @@ static void DrawRelocateScreen(int old_x, int old_y, int x, int y,
   {
     // relocation _without_ centering of screen
 
-    // apply distance between old and new player position to scroll position
-    int shifted_scroll_x = scroll_x + (x - old_x);
-    int shifted_scroll_y = scroll_y + (y - old_y);
+    if (IN_LEV_FIELD(old_x, old_y))
+    {
+      // apply distance between old and new player position to scroll position
+      int shifted_scroll_x = scroll_x + (x - old_x);
+      int shifted_scroll_y = scroll_y + (y - old_y);
 
-    // make sure that shifted scroll position does not scroll beyond screen
-    new_scroll_x = SCROLL_POSITION_X(shifted_scroll_x + MIDPOSX);
-    new_scroll_y = SCROLL_POSITION_Y(shifted_scroll_y + MIDPOSY);
+      // make sure that shifted scroll position does not scroll beyond screen
+      new_scroll_x = SCROLL_POSITION_X(shifted_scroll_x + MIDPOSX);
+      new_scroll_y = SCROLL_POSITION_Y(shifted_scroll_y + MIDPOSY);
+    }
+    else
+    {
+      // player not on playfield before -- scroll to initial player position
+      new_scroll_x = SCROLL_POSITION_X(x);
+      new_scroll_y = SCROLL_POSITION_Y(y);
+    }
 
     // special case for teleporting from one end of the playfield to the other
     // (this kludge prevents the destination area to be shifted by half a tile