rnd-20030417-3-src
[rocksndiamonds.git] / src / tools.c
index 8bd0a153ebf8483ff3de6a0fc4ac2abbfef96fbc..ab66bdf21921c5f72f565bc67fea60ec5f2cafbb 100644 (file)
@@ -745,16 +745,20 @@ void DrawPlayer(struct PlayerInfo *player)
   }
 
   /* ----------------------------------------------------------------------- */
-  /* draw elements that stay over the player                                 */
+  /* draw elements the player is just walking/passing through/under          */
   /* ----------------------------------------------------------------------- */
 
   /* handle the field the player is leaving ... */
-  if (player_is_moving && IS_OVER_PLAYER(last_element))
+  if (player_is_moving && IS_ACCESSIBLE_INSIDE(last_element))
     DrawLevelField(last_jx, last_jy);
+  else if (player_is_moving && IS_ACCESSIBLE_UNDER(last_element))
+    DrawLevelFieldThruMask(last_jx, last_jy);
 
   /* ... and the field the player is entering */
-  if (IS_OVER_PLAYER(element))
+  if (IS_ACCESSIBLE_INSIDE(element))
     DrawLevelField(jx, jy);
+  else if (IS_ACCESSIBLE_UNDER(element))
+    DrawLevelFieldThruMask(jx, jy);
 
   if (setup.direct_draw)
   {
@@ -773,15 +777,29 @@ void DrawPlayer(struct PlayerInfo *player)
 
 void getGraphicSource(int graphic, int frame, Bitmap **bitmap, int *x, int *y)
 {
-  Bitmap *src_bitmap = graphic_info[graphic].bitmap;
-  int offset_x = graphic_info[graphic].offset_x;
-  int offset_y = graphic_info[graphic].offset_y;
-  int src_x = graphic_info[graphic].src_x + frame * offset_x;
-  int src_y = graphic_info[graphic].src_y + frame * offset_y;
+  struct GraphicInfo *g = &graphic_info[graphic];
 
-  *bitmap = src_bitmap;
-  *x = src_x;
-  *y = src_y;
+  *bitmap = g->bitmap;
+
+  if (g->offset_y == 0)                /* frames are ordered horizontally */
+  {
+    int max_width = g->anim_frames_per_line * g->width;
+
+    *x = (g->src_x + frame * g->offset_x) % max_width;
+    *y = g->src_y + (g->src_x + frame * g->offset_x) / max_width * g->height;
+  }
+  else if (g->offset_x == 0)   /* frames are ordered vertically */
+  {
+    int max_height = g->anim_frames_per_line * g->height;
+
+    *x = g->src_x + (g->src_y + frame * g->offset_y) / max_height * g->width;
+    *y = (g->src_y + frame * g->offset_y) % max_height;
+  }
+  else                         /* frames are ordered diagonally */
+  {
+    *x = g->src_x + frame * g->offset_x;
+    *y = g->src_y + frame * g->offset_y;
+  }
 }
 
 void DrawGraphic(int x, int y, int graphic, int frame)
@@ -883,32 +901,13 @@ void DrawMiniGraphic(int x, int y, int graphic)
 
 void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
 {
-  Bitmap *src_bitmap = graphic_info[graphic].bitmap;
+  struct GraphicInfo *g = &graphic_info[graphic];
   int mini_startx = 0;
-  int mini_starty = src_bitmap->height * 2 / 3;
-  int src_x = mini_startx + graphic_info[graphic].src_x / 2;
-  int src_y = mini_starty + graphic_info[graphic].src_y / 2;
-
-#if 0
-  /* !!! not needed anymore, because of automatically created mini graphics */
-  if (src_x + MINI_TILEX > src_bitmap->width ||
-      src_y + MINI_TILEY > src_bitmap->height)
-  {
-    /* graphic of desired size seems not to be contained in this image;
-       dirty workaround: get it from the middle of the normal sized image */
-
-    printf("::: using dirty workaround for %d (%d, %d)\n",
-          graphic, src_bitmap->width, src_bitmap->height);
+  int mini_starty = g->bitmap->height * 2 / 3;
 
-    getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
-    src_x += (TILEX / 2 - MINI_TILEX / 2);
-    src_y += (TILEY / 2 - MINI_TILEY / 2);
-  }
-#endif
-
-  *bitmap = src_bitmap;
-  *x = src_x;
-  *y = src_y;
+  *bitmap = g->bitmap;
+  *x = mini_startx + g->src_x / 2;
+  *y = mini_starty + g->src_y / 2;
 }
 
 void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic)