added drawing player twice when wrapping-around in fully visible levels
authorHolger Schemel <info@artsoft.org>
Wed, 26 Feb 2020 07:59:24 +0000 (08:59 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 19 May 2020 16:20:01 +0000 (18:20 +0200)
src/game_em/graphics.c

index 363cb9af7eb08f31f4a67361ce5d84c214cf0dd7..dab61eb7b5ffbe02cc67519ede178637db12427d 100644 (file)
@@ -368,7 +368,7 @@ static void animscreen(void)
  * handles transparency and movement
  */
 
-static void blitplayer(int nr)
+static void blitplayer_ext(int nr)
 {
   int x1, y1, x2, y2;
 
@@ -430,6 +430,28 @@ static void blitplayer(int nr)
   }
 }
 
+static void blitplayer(int nr)
+{
+  blitplayer_ext(nr);
+
+  /* check for wrap-around movement ... */
+  if (ply[nr].x < lev.left ||
+      ply[nr].x > lev.right - 1)
+  {
+    struct PLAYER ply_last = ply[nr];
+    int dx = ply[nr].x - ply[nr].prev_x;
+
+    ply[nr].x = (ply[nr].x < lev.left ? lev.right - 1 : lev.left);
+    ply[nr].prev_x = ply[nr].x - dx;
+
+    /* draw player entering playfield from the opposite side */
+    blitplayer_ext(nr);
+
+    /* ... but keep the old player position until game logic */
+    ply[nr] = ply_last;
+  }
+}
+
 void game_initscreen(void)
 {
   int player_nr;