draw.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <draw/draw.h>
  2. // Global variables to store camera position
  3. int camera_x = 0;
  4. int camera_y = 0;
  5. // Draw a line of icons (16 width)
  6. void draw_icon_line(Canvas *canvas, Vector pos, int amount, bool horizontal, const Icon *icon)
  7. {
  8. for (int i = 0; i < amount; i++)
  9. {
  10. if (horizontal)
  11. {
  12. // check if element is outside the world
  13. if (pos.x + (i * 17) > WORLD_WIDTH)
  14. {
  15. break;
  16. }
  17. canvas_draw_icon(canvas, pos.x + (i * 17) - camera_x, pos.y - camera_y, icon);
  18. }
  19. else
  20. {
  21. // check if element is outside the world
  22. if (pos.y + (i * 17) > WORLD_HEIGHT)
  23. {
  24. break;
  25. }
  26. canvas_draw_icon(canvas, pos.x - camera_x, pos.y + (i * 17) - camera_y, icon);
  27. }
  28. }
  29. }
  30. // Draw a half section of icons (16 width)
  31. void draw_icon_half_world(Canvas *canvas, bool right, const Icon *icon)
  32. {
  33. for (int i = 0; i < 10; i++)
  34. {
  35. if (right)
  36. {
  37. draw_icon_line(canvas, (Vector){WORLD_WIDTH / 2 + 6, i * 19 + 2}, 11, true, icon);
  38. }
  39. else
  40. {
  41. draw_icon_line(canvas, (Vector){0, i * 19 + 2}, 11, true, icon);
  42. }
  43. }
  44. }
  45. const Icon *get_icon(char *name)
  46. {
  47. if (strcmp(name, "earth") == 0)
  48. {
  49. return &I_icon_earth;
  50. }
  51. if (strcmp(name, "home") == 0)
  52. {
  53. return &I_icon_home;
  54. }
  55. if (strcmp(name, "info") == 0)
  56. {
  57. return &I_icon_info;
  58. }
  59. if (strcmp(name, "man") == 0)
  60. {
  61. return &I_icon_man;
  62. }
  63. if (strcmp(name, "plant") == 0)
  64. {
  65. return &I_icon_plant;
  66. }
  67. if (strcmp(name, "tree") == 0)
  68. {
  69. return &I_icon_tree;
  70. }
  71. if (strcmp(name, "woman") == 0)
  72. {
  73. return &I_icon_woman;
  74. }
  75. return NULL;
  76. }