From: Holger Schemel Date: Wed, 26 Jun 2024 16:21:10 +0000 (+0200) Subject: added support for smooth movement on conveyor belts in BD engine X-Git-Tag: 4.4.0.0-test-3~23 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=8a7090f569a6a4450574fcc0c013c2cada5177a6;p=rocksndiamonds.git added support for smooth movement on conveyor belts in BD engine --- diff --git a/src/game_bd/bd_caveengine.c b/src/game_bd/bd_caveengine.c index 9df249eb..98c188df 100644 --- a/src/game_bd/bd_caveengine.c +++ b/src/game_bd/bd_caveengine.c @@ -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. } } }