world.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include <game/world.h>
  2. void draw_bounds(Canvas *canvas)
  3. {
  4. // Draw the outer bounds adjusted by camera offset
  5. // we draw this last to ensure users can see the bounds
  6. canvas_draw_frame(canvas, -camera_x, -camera_y, WORLD_WIDTH, WORLD_HEIGHT);
  7. }
  8. bool draw_json_world(Level *level, const char *json_data)
  9. {
  10. for (int i = 0; i < MAX_WORLD_OBJECTS; i++)
  11. {
  12. char *data = get_json_array_value("json_data", i, json_data);
  13. if (data == NULL)
  14. {
  15. break;
  16. }
  17. char *icon = get_json_value("icon", data);
  18. char *x = get_json_value("x", data);
  19. char *y = get_json_value("y", data);
  20. char *width = get_json_value("width", data);
  21. char *height = get_json_value("height", data);
  22. char *amount = get_json_value("amount", data);
  23. char *horizontal = get_json_value("horizontal", data);
  24. if (icon == NULL || x == NULL || y == NULL || width == NULL || height == NULL || amount == NULL || horizontal == NULL)
  25. {
  26. return false;
  27. }
  28. // if amount is less than 2, we spawn a single icon
  29. if (atoi(amount) < 2)
  30. {
  31. spawn_icon(level, get_icon(icon), atoi(x), atoi(y), atoi(width), atoi(height));
  32. free(data);
  33. free(icon);
  34. free(x);
  35. free(y);
  36. free(width);
  37. free(height);
  38. free(amount);
  39. free(horizontal);
  40. continue;
  41. }
  42. spawn_icon_line(level, get_icon(icon), atoi(x), atoi(y), atoi(width), atoi(height), atoi(amount), strcmp(horizontal, "true") == 0);
  43. free(data);
  44. free(icon);
  45. free(x);
  46. free(y);
  47. free(width);
  48. free(height);
  49. free(amount);
  50. free(horizontal);
  51. }
  52. return true;
  53. }
  54. bool draw_json_world_furi(Level *level, FuriString *json_data)
  55. {
  56. for (int i = 0; i < MAX_WORLD_OBJECTS; i++)
  57. {
  58. char *data = get_json_array_value("json_data", i, furi_string_get_cstr(json_data));
  59. if (data == NULL)
  60. {
  61. break;
  62. }
  63. char *icon = get_json_value("icon", data);
  64. char *x = get_json_value("x", data);
  65. char *y = get_json_value("y", data);
  66. char *width = get_json_value("width", data);
  67. char *height = get_json_value("height", data);
  68. char *amount = get_json_value("amount", data);
  69. char *horizontal = get_json_value("horizontal", data);
  70. if (icon == NULL || x == NULL || y == NULL || width == NULL || height == NULL || amount == NULL || horizontal == NULL)
  71. {
  72. return false;
  73. }
  74. // if amount is less than 2, we spawn a single icon
  75. if (atoi(amount) < 2)
  76. {
  77. spawn_icon(level, get_icon(icon), atoi(x), atoi(y), atoi(width), atoi(height));
  78. free(data);
  79. free(icon);
  80. free(x);
  81. free(y);
  82. free(width);
  83. free(height);
  84. free(amount);
  85. free(horizontal);
  86. continue;
  87. }
  88. spawn_icon_line(level, get_icon(icon), atoi(x), atoi(y), atoi(width), atoi(height), atoi(amount), strcmp(horizontal, "true") == 0);
  89. free(data);
  90. free(icon);
  91. free(x);
  92. free(y);
  93. free(width);
  94. free(height);
  95. free(amount);
  96. free(horizontal);
  97. }
  98. return true;
  99. }
  100. void draw_example_world(Level *level)
  101. {
  102. spawn_icon(level, get_icon("earth"), 112, 56, 15, 16);
  103. spawn_icon(level, get_icon("home"), 128, 24, 15, 16);
  104. spawn_icon(level, get_icon("info"), 144, 24, 15, 16);
  105. spawn_icon(level, get_icon("man"), 160, 56, 7, 16);
  106. spawn_icon(level, get_icon("woman"), 168, 56, 9, 16);
  107. spawn_icon(level, get_icon("plant"), 168, 32, 16, 16);
  108. }
  109. void draw_tree_world(Level *level)
  110. {
  111. // Spawn two full left/up tree lines
  112. for (int i = 0; i < 2; i++)
  113. {
  114. // Horizontal line of 22 icons
  115. spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 22, true);
  116. // Vertical line of 11 icons
  117. spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 2, 16, 16, 11, false);
  118. }
  119. // Spawn two full down tree lines
  120. for (int i = 9; i < 11; i++)
  121. {
  122. // Horizontal line of 22 icons
  123. spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 22, true);
  124. }
  125. // Spawn two full right tree lines
  126. for (int i = 20; i < 22; i++)
  127. {
  128. // Vertical line of 8 icons starting further down (y=50)
  129. spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 50, 16, 16, 8, false);
  130. }
  131. // Labyrinth lines
  132. // Third line (14 left, then a gap, then 3 middle)
  133. spawn_icon_line(level, get_icon("tree"), 5, 2 + 2 * 17, 16, 16, 14, true);
  134. spawn_icon_line(level, get_icon("tree"), 5 + 16 * 17, 2 + 2 * 17, 16, 16, 3, true);
  135. // Fourth line (3 left, 6 middle, 4 right)
  136. spawn_icon_line(level, get_icon("tree"), 5, 2 + 3 * 17, 16, 16, 3, true); // 3 left
  137. spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 3 * 17, 16, 16, 6, true); // 6 middle
  138. spawn_icon_line(level, get_icon("tree"), 5 + 15 * 17, 2 + 3 * 17, 16, 16, 4, true); // 4 right
  139. // Fifth line (6 left, 7 middle)
  140. spawn_icon_line(level, get_icon("tree"), 5, 2 + 4 * 17, 16, 16, 6, true);
  141. spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 4 * 17, 16, 16, 7, true);
  142. // Sixth line (5 left, 3 middle, 7 right)
  143. spawn_icon_line(level, get_icon("tree"), 5, 2 + 5 * 17, 16, 16, 5, true); // 5 left
  144. spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 5 * 17, 16, 16, 3, true); // 3 middle
  145. spawn_icon_line(level, get_icon("tree"), 5 + 15 * 17, 2 + 5 * 17, 16, 16, 7, true); // 7 right
  146. // Seventh line (0 left, 7 middle, 4 right)
  147. spawn_icon_line(level, get_icon("tree"), 5 + 6 * 17, 2 + 6 * 17, 16, 16, 7, true); // 7 middle
  148. spawn_icon_line(level, get_icon("tree"), 5 + 14 * 17, 2 + 6 * 17, 16, 16, 4, true); // 4 right
  149. // Eighth line (4 left, 3 middle, 4 right)
  150. spawn_icon_line(level, get_icon("tree"), 5, 2 + 7 * 17, 16, 16, 4, true); // 4 left
  151. spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 7 * 17, 16, 16, 3, true); // 3 middle
  152. spawn_icon_line(level, get_icon("tree"), 5 + 15 * 17, 2 + 7 * 17, 16, 16, 4, true); // 4 right
  153. // Ninth line (3 left, 1 middle, 3 right)
  154. spawn_icon_line(level, get_icon("tree"), 5, 2 + 8 * 17, 16, 16, 3, true); // 3 left
  155. spawn_icon_line(level, get_icon("tree"), 5 + 5 * 17, 2 + 8 * 17, 16, 16, 1, true); // 1 middle
  156. spawn_icon_line(level, get_icon("tree"), 5 + 11 * 17, 2 + 8 * 17, 16, 16, 3, true); // 3 right
  157. }