draw.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }