fixed default graphics for growing or exploding BD engine elements
[rocksndiamonds.git] / src / game_bd / bd_graphics.c
index edc8003788e68ef268ee792eb1903716c47eeca2..aa091ba131b44404613d50aebcdde97ce18ee4d6 100644 (file)
@@ -58,8 +58,6 @@ static int scroll_x, scroll_y;
 // quit, global variable which is set to true if the application should quit
 boolean gd_quit = FALSE;
 
-const byte *gd_keystate;
-
 static int cell_size = 0;
 
 // graphic info for game objects/frames and players/actions/frames
@@ -110,11 +108,9 @@ void set_play_area(int w, int h)
   play_area_h = h;
 }
 
-void gd_init_keystate(void)
+void gd_init_play_area(void)
 {
   set_play_area(SXSIZE, SYSIZE);
-
-  gd_keystate = SDL_GetKeyboardState(NULL);
 }
 
 /*
@@ -542,11 +538,13 @@ static inline boolean el_diggable(const int element)
   return (gd_elements[element & O_MASK].properties & P_DIGGABLE) != 0;
 }
 
+#if 0
 // returns true if the element is collectible
 static inline boolean el_collectible(const int element)
 {
   return (gd_elements[element & O_MASK].properties & P_COLLECTIBLE) != 0;
 }
+#endif
 
 // returns true if the element is pushable
 static inline boolean el_pushable(const int element)
@@ -555,15 +553,21 @@ static inline boolean el_pushable(const int element)
 }
 
 // returns true if the element can move
-static inline boolean can_move(const int element)
+static inline boolean el_can_move(const int element)
 {
   return (gd_elements[element & O_MASK].properties & P_CAN_MOVE) != 0;
 }
 
 // returns true if the element can fall
-static inline boolean can_fall(const int element)
+static inline boolean el_falling(const int element)
 {
-  return (gd_elements[element & O_MASK].properties & P_CAN_FALL) != 0;
+  return (gd_elements[element & O_MASK].properties & P_FALLING) != 0;
+}
+
+// returns true if the element is growing
+static inline boolean el_growing(const int element)
+{
+  return (gd_elements[element & O_MASK].properties & P_GROWING) != 0;
 }
 
 // returns true if the element is exploding
@@ -584,14 +588,38 @@ static void gd_drawcave_tile(Bitmap *dest, GdGame *game, int x, int y, boolean d
   int frame = game->animcycle;
   struct GraphicInfo_BD *g = &graphic_info_bd_object[tile][frame];
   Bitmap *tile_bitmap = gd_get_tile_bitmap(g->bitmap);
-  boolean is_movable = (can_move(tile) || can_fall(tile) || el_pushable(tile) || el_player(tile));
+  boolean is_movable = (el_can_move(tile) || el_falling(tile) || el_pushable(tile) ||
+                       el_player(tile));
   boolean is_movable_or_diggable = (is_movable || el_diggable(game->last_element_buffer[y][x]));
   boolean is_moving = (is_movable_or_diggable && dir != GD_MV_STILL);
   boolean use_smooth_movements = use_bd_smooth_movements();
 
-  // do not use smooth movement animation for exploding game elements (like player)
-  if (el_explosion(tile) && dir != GD_MV_STILL)
+  // do not use smooth movement animation for growing or exploding game elements
+  if ((el_growing(tile) || el_explosion(tile)) && dir != GD_MV_STILL)
+  {
+    int dx = (dir == GD_MV_LEFT ? +1 : dir == GD_MV_RIGHT ? -1 : 0);
+    int dy = (dir == GD_MV_UP   ? +1 : dir == GD_MV_DOWN  ? -1 : 0);
+    int old_x = cave->getx(cave, x + dx, y + dy);
+    int old_y = cave->gety(cave, x + dx, y + dy);
+    int last_tile_from = game->last_element_buffer[old_y][old_x] & ~SKIPPED;
+    boolean old_is_player = el_player(last_tile_from);
+
+    // check special case of player running into enemy from top or left side
+    if (old_is_player)
+    {
+      game->element_buffer[y][x] = (dir == GD_MV_LEFT  ? O_PLAYER_LEFT  :
+                                    dir == GD_MV_RIGHT ? O_PLAYER_RIGHT :
+                                    dir == GD_MV_UP    ? O_PLAYER_UP    :
+                                    dir == GD_MV_DOWN  ? O_PLAYER_DOWN  : O_PLAYER);
+
+      // draw player running into explosion (else player would disappear immediately)
+      gd_drawcave_tile(dest, game, x, y, draw_masked);
+
+      game->element_buffer[y][x] = tile;
+    }
+
     use_smooth_movements = FALSE;
+  }
 
   // do not use smooth movement animation for player entering exit (engine stopped)
   if (cave->player_state == GD_PL_EXITED)