added support for smooth movement on conveyor belts in BD engine
authorHolger Schemel <holger.schemel@virtion.de>
Wed, 26 Jun 2024 16:21:10 +0000 (18:21 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Wed, 26 Jun 2024 16:21:34 +0000 (18:21 +0200)
src/game_bd/bd_caveengine.c

index 9df249eba1fba020e9ef53063c92c0aed0b8dbe7..98c188df523550e7cc6c6026f31a17fba7b6b8ad 100644 (file)
@@ -3318,8 +3318,27 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire,
              if (!is_scanned_dir(cave, x, y, GD_MV_UP) &&
                  is_space_dir(cave, x, y, dir[GD_MV_UP]))
              {
-               store_dir(cave, x, y, dir[GD_MV_UP], get_dir(cave, x, y, GD_MV_UP));    // move
-               store_dir(cave, x, y, GD_MV_UP, O_SPACE);    // and place a space.
+                // to allow smooth movement of game elements on conveyor belts,
+                // the moving direction set by "store_dir()" must be set to the
+                // direction the game element on the conveyor belt is moving;
+                // without smooth movement, the following lines would do it:
+                //
+               // store_dir(cave, x, y, dir[GD_MV_UP], get_dir(cave, x, y, GD_MV_UP));    // move
+               // store_dir(cave, x, y, GD_MV_UP, O_SPACE);    // and place a space.
+
+               int tile = get_dir(cave, x, y, GD_MV_UP);
+                int move_dir = (left ? GD_MV_LEFT : GD_MV_RIGHT); // top side direction
+
+                // raw values without range correction
+                int raw_x = x + gd_dx[GD_MV_UP];
+                int raw_y = y + gd_dy[GD_MV_UP];
+
+                // final values with range correction
+                int old_x = getx(cave, raw_x, raw_y);
+                int old_y = gety(cave, raw_x, raw_y);
+
+               store_dir(cave, x, y, GD_MV_UP, O_SPACE);        // place a space ...
+               store_dir(cave, old_x, old_y, move_dir, tile);   // and move element.
              }
            }
 
@@ -3332,8 +3351,27 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire,
              if (!is_scanned_dir(cave, x, y, GD_MV_DOWN) &&
                  is_space_dir(cave, x, y, dir[GD_MV_DOWN]))
              {
-               store_dir(cave, x, y, dir[GD_MV_DOWN], get_dir(cave, x, y, GD_MV_DOWN));    // move
-               store_dir(cave, x, y, GD_MV_DOWN, O_SPACE);    // and clear.
+                // to allow smooth movement of game elements on conveyor belts,
+                // the moving direction set by "store_dir()" must be set to the
+                // direction the game element on the conveyor belt is moving;
+                // without smooth movement, the following lines would do it:
+                //
+               // store_dir(cave, x, y, dir[GD_MV_DOWN], get_dir(cave, x, y, GD_MV_DOWN)); // move
+               // store_dir(cave, x, y, GD_MV_DOWN, O_SPACE);    // and clear.
+
+               int tile = get_dir(cave, x, y, GD_MV_DOWN);
+                int move_dir = (left ? GD_MV_RIGHT : GD_MV_LEFT); // bottom side direction
+
+                // raw values without range correction
+                int raw_x = x + gd_dx[GD_MV_DOWN];
+                int raw_y = y + gd_dy[GD_MV_DOWN];
+
+                // final values with range correction
+                int old_x = getx(cave, raw_x, raw_y);
+                int old_y = gety(cave, raw_x, raw_y);
+
+               store_dir(cave, x, y, GD_MV_DOWN, O_SPACE);      // place a space ...
+               store_dir(cave, old_x, old_y, move_dir, tile);   // and move element.
              }
            }
          }