The bitmap wars source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

item.c 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "item.h"
  2. #include "map.h"
  3. // displaying avec dépendance
  4. /// murs, maisons, routes
  5. int get_item_type(int mx,int my)
  6. {
  7. generic_item* item=get_item(mx,my);
  8. if (item==0)
  9. return EMPTY;
  10. return item->type;
  11. }
  12. void display_item_etendu(image_t* res,int mx, int my, int sx, int sy)
  13. {
  14. int type=get_item_type(mx,my);
  15. unsigned char val=0x00; // on n'utilise que les 4 premiers bits 0<=val<=15 mais on multiplie nativement par 8
  16. val|=(get_item_type(mx-1,my)==type)<<3;
  17. val|=(get_item_type(mx+1,my)==type)<<4;
  18. val|=(get_item_type(mx,my-1)==type)<<5;
  19. val|=(get_item_type(mx,my+1)==type)<<6;
  20. dsubimage(sx,sy,res,val,0,8,8,0);
  21. }
  22. void display_brouillard(int mx, int my, int sx, int sy)
  23. {
  24. char val=0x00; // on n'utilise que les 4 premiers bits 0<=val<=15 mais on multiplie nativement par 8
  25. val|=(!get_visibility(mx-1,my))<<3;
  26. val|=(!get_visibility(mx+1,my))<<4;
  27. val|=(!get_visibility(mx,my-1))<<5;
  28. val|=(!get_visibility(mx,my+1))<<6;
  29. dsubimage(sx,sy, &img_brouillard, val, 0, 8, 8, DIMAGE_NONE);
  30. }
  31. void display_water(int mx, int my, int sx, int sy)
  32. {
  33. char val=0x00; // on n'utilise que les 4 premiers bits 0<=val<=15 mais on multiplie nativement par 8
  34. val|=(WATER==get_terrain(mx-1,my))<<3;
  35. val|=(WATER==get_terrain(mx+1,my))<<4;
  36. val|=(WATER==get_terrain(mx,my-1))<<5;
  37. val|=(WATER==get_terrain(mx,my+1))<<6;
  38. dsubimage(sx,sy, &img_water, val, 0, 8, 8, DIMAGE_NONE);
  39. }
  40. void display_case(int mx, int my, int sx, int sy)
  41. {
  42. int type=get_item_type(mx,my);
  43. switch (type)
  44. {
  45. case WALL:
  46. display_item_etendu(&img_wall,mx,my,sx,sy);
  47. return;
  48. case HOUSE:
  49. display_item_etendu(&img_houses,mx,my,sx,sy);
  50. return;
  51. default:
  52. if (get_terrain(mx,my)==WATER)
  53. display_water(mx,my,sx,sy);
  54. if (!get_visibility(mx,my))
  55. display_brouillard(mx,my,sx,sy);
  56. }
  57. }