added cave buffer offsets to level structure in EM engine
authorHolger Schemel <info@artsoft.org>
Wed, 29 Jan 2020 21:46:46 +0000 (22:46 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 19 May 2020 16:12:57 +0000 (18:12 +0200)
src/game_em/convert.c
src/game_em/emerald.h
src/game_em/logic.c

index 0b3f05aa04a5c96c8467b3b20f5f28a7028ca3ca..5553772e62f6ece5654cf91c702e8cf14adfbed9 100644 (file)
@@ -938,10 +938,14 @@ void prepare_em_level(void)
 
   /* reset all runtime variables to their initial values */
 
+  lev.left = CAVE_BUFFER_XOFFSET;
+  lev.top  = CAVE_BUFFER_YOFFSET;
+  lev.right = lev.left + lev.width;
+  lev.bottom = lev.top + lev.height;
+
   for (y = 0; y < CAVE_HEIGHT; y++)
     for (x = 0; x < CAVE_WIDTH; x++)
-      lev.cave[x + CAVE_BUFFER_XOFFSET][y + CAVE_BUFFER_YOFFSET] =
-       native_em_level.cave[x][y];
+      lev.cave[lev.left + x][lev.top + y] = native_em_level.cave[x][y];
 
   for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
     for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
@@ -1022,9 +1026,9 @@ void prepare_em_level(void)
 
        native_em_level.cave[x][y] = Xblank;
 
-       lev.cave[x + CAVE_BUFFER_XOFFSET][y + CAVE_BUFFER_YOFFSET] = Xblank;
-       lev.next[x + CAVE_BUFFER_XOFFSET][y + CAVE_BUFFER_YOFFSET] = Xblank;
-       lev.draw[x + CAVE_BUFFER_XOFFSET][y + CAVE_BUFFER_YOFFSET] = Xblank;
+       lev.cave[lev.left + x][lev.top + y] = Xblank;
+       lev.next[lev.left + x][lev.top + y] = Xblank;
+       lev.draw[lev.left + x][lev.top + y] = Xblank;
       }
     }
   }
@@ -1037,8 +1041,8 @@ void prepare_em_level(void)
     ply[i].dynamite_cnt = 0;
     ply[i].keys = 0;
     ply[i].anim = 0;
-    ply[i].oldx = ply[i].x = ply[i].x_initial + CAVE_BUFFER_XOFFSET;
-    ply[i].oldy = ply[i].y = ply[i].y_initial + CAVE_BUFFER_YOFFSET;
+    ply[i].oldx = ply[i].x = ply[i].x_initial + lev.left;
+    ply[i].oldy = ply[i].y = ply[i].y_initial + lev.top;
     ply[i].last_move_dir = MV_NONE;
     ply[i].joy_n = ply[i].joy_e = ply[i].joy_s = ply[i].joy_w = 0;
     ply[i].joy_snap  = ply[i].joy_drop = 0;
index 9dc949fb1e83bbf9958cc8aa17c4c25361fed458..d83a182da26d8fce0cc41905b2c73e9e22e6be7d 100644 (file)
@@ -637,6 +637,11 @@ struct LEVEL
   int width;                   /* playfield width */
   int height;                  /* playfield height */
 
+  int left;                    /* playfield left edge */
+  int top;                     /* playfield top edge */
+  int right;                   /* playfield right edge */
+  int bottom;                  /* playfield bottom edge */
+
   int time_seconds;            /* available time (seconds) */
   int time_initial;            /* available time (initial) */
   int time;                    /* time remaining (runtime) */
index 8bd29b3c4f9753145da0bf491c7721c1716298c5..808db47d18ef338d4841b642cfc046df2f1bb863 100644 (file)
@@ -6334,8 +6334,8 @@ void logic_3(void)
 
   for (count = lev.amoeba_time; count--;)
   {
-    x = CAVE_BUFFER_XOFFSET - 1 + (random >> 10) % CAVE_WIDTH;
-    y = CAVE_BUFFER_YOFFSET - 1 + (random >> 20) % CAVE_HEIGHT;
+    x = lev.left - 1 + (random >> 10) % CAVE_WIDTH;
+    y = lev.top  - 1 + (random >> 20) % CAVE_HEIGHT;
 
     Lamoeba(x, y);