world.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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, FuriString *json_data)
  9. {
  10. for (int i = 0; i < MAX_WORLD_OBJECTS; i++)
  11. {
  12. char *data = get_json_array_value("json_data", i, (char *)furi_string_get_cstr(json_data), MAX_WORLD_TOKENS);
  13. if (data == NULL)
  14. {
  15. break;
  16. }
  17. char *icon = get_json_value("icon", data, 64);
  18. char *x = get_json_value("x", data, 64);
  19. char *y = get_json_value("y", data, 64);
  20. char *width = get_json_value("width", data, 64);
  21. char *height = get_json_value("height", data, 64);
  22. char *amount = get_json_value("amount", data, 64);
  23. char *horizontal = get_json_value("horizontal", data, 64);
  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. void draw_example_world(Level *level)
  55. {
  56. spawn_icon(level, &I_icon_earth, 112, 56, 15, 16);
  57. spawn_icon(level, &I_icon_home, 128, 24, 15, 16);
  58. spawn_icon(level, &I_icon_info, 144, 24, 15, 16);
  59. spawn_icon(level, &I_icon_man, 160, 56, 7, 16);
  60. spawn_icon(level, &I_icon_woman, 168, 56, 9, 16);
  61. spawn_icon(level, &I_icon_plant, 168, 32, 16, 16);
  62. }
  63. /* JSON of the draw_example_world with fields icon, x, y, width, height
  64. {
  65. "name": "Example World",
  66. "author": "JBlanked",
  67. "json_data": [
  68. {
  69. "icon": "earth",
  70. "x": 112,
  71. "y": 56,
  72. "width": 15,
  73. "height": 16,
  74. "amount": 1,
  75. "horizontal": true
  76. },
  77. {
  78. "icon": "home",
  79. "x": 128,
  80. "y": 24,
  81. "width": 15,
  82. "height": 16,
  83. "amount": 1,
  84. "horizontal": true
  85. },
  86. {
  87. "icon": "info",
  88. "x": 144,
  89. "y": 24,
  90. "width": 15,
  91. "height": 16,
  92. "amount": 1,
  93. "horizontal": true
  94. },
  95. {
  96. "icon": "man",
  97. "x": 160,
  98. "y": 56,
  99. "width": 7,
  100. "height": 16,
  101. "amount": 1,
  102. "horizontal": true
  103. },
  104. {
  105. "icon": "woman",
  106. "x": 168,
  107. "y": 56,
  108. "width": 9,
  109. "height": 16,
  110. "amount": 1,
  111. "horizontal": true
  112. },
  113. {
  114. "icon": "plant",
  115. "x": 168,
  116. "y": 32,
  117. "width": 16,
  118. "height": 16,
  119. "amount": 1,
  120. "horizontal": true
  121. }
  122. ]
  123. }
  124. */
  125. void draw_tree_world(Level *level)
  126. {
  127. // Spawn two full left/up tree lines
  128. for (int i = 0; i < 2; i++)
  129. {
  130. // Horizontal line of 22 icons
  131. spawn_icon_line(level, &I_icon_tree, 5, 2 + i * 17, 16, 16, 22, true);
  132. // Vertical line of 11 icons
  133. spawn_icon_line(level, &I_icon_tree, 5 + i * 17, 2, 16, 16, 11, false);
  134. }
  135. // Spawn two full down tree lines
  136. for (int i = 9; i < 11; i++)
  137. {
  138. // Horizontal line of 22 icons
  139. spawn_icon_line(level, &I_icon_tree, 5, 2 + i * 17, 16, 16, 22, true);
  140. }
  141. // Spawn two full right tree lines
  142. for (int i = 20; i < 22; i++)
  143. {
  144. // Vertical line of 8 icons starting further down (y=50)
  145. spawn_icon_line(level, &I_icon_tree, 5 + i * 17, 50, 16, 16, 8, false);
  146. }
  147. // Labyrinth lines
  148. // Third line (14 left, then a gap, then 3 middle)
  149. spawn_icon_line(level, &I_icon_tree, 5, 2 + 2 * 17, 16, 16, 14, true);
  150. spawn_icon_line(level, &I_icon_tree, 5 + 16 * 17, 2 + 2 * 17, 16, 16, 3, true);
  151. // Fourth line (3 left, 6 middle, 4 right)
  152. spawn_icon_line(level, &I_icon_tree, 5, 2 + 3 * 17, 16, 16, 3, true); // 3 left
  153. spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 3 * 17, 16, 16, 6, true); // 6 middle
  154. spawn_icon_line(level, &I_icon_tree, 5 + 15 * 17, 2 + 3 * 17, 16, 16, 4, true); // 4 right
  155. // Fifth line (6 left, 7 middle)
  156. spawn_icon_line(level, &I_icon_tree, 5, 2 + 4 * 17, 16, 16, 6, true);
  157. spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 4 * 17, 16, 16, 7, true);
  158. // Sixth line (5 left, 3 middle, 7 right)
  159. spawn_icon_line(level, &I_icon_tree, 5, 2 + 5 * 17, 16, 16, 5, true); // 5 left
  160. spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 5 * 17, 16, 16, 3, true); // 3 middle
  161. spawn_icon_line(level, &I_icon_tree, 5 + 15 * 17, 2 + 5 * 17, 16, 16, 7, true); // 7 right
  162. // Seventh line (0 left, 7 middle, 4 right)
  163. spawn_icon_line(level, &I_icon_tree, 5 + 6 * 17, 2 + 6 * 17, 16, 16, 7, true); // 7 middle
  164. spawn_icon_line(level, &I_icon_tree, 5 + 14 * 17, 2 + 6 * 17, 16, 16, 4, true); // 4 right
  165. // Eighth line (4 left, 3 middle, 4 right)
  166. spawn_icon_line(level, &I_icon_tree, 5, 2 + 7 * 17, 16, 16, 4, true); // 4 left
  167. spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 7 * 17, 16, 16, 3, true); // 3 middle
  168. spawn_icon_line(level, &I_icon_tree, 5 + 15 * 17, 2 + 7 * 17, 16, 16, 4, true); // 4 right
  169. // Ninth line (3 left, 1 middle, 3 right)
  170. spawn_icon_line(level, &I_icon_tree, 5, 2 + 8 * 17, 16, 16, 3, true); // 3 left
  171. spawn_icon_line(level, &I_icon_tree, 5 + 5 * 17, 2 + 8 * 17, 16, 16, 1, true); // 1 middle
  172. spawn_icon_line(level, &I_icon_tree, 5 + 11 * 17, 2 + 8 * 17, 16, 16, 3, true); // 3 right
  173. }
  174. /* JSON of the draw_tree_world
  175. {
  176. "name" : "tree_world",
  177. "author" : "JBlanked",
  178. "json_data" : [
  179. {"icon" : "tree", "x" : 5, "y" : 2, "width" : 16, "height" : 16, "amount" : 22, "horizontal" : true},
  180. {"icon" : "tree", "x" : 5, "y" : 2, "width" : 16, "height" : 16, "amount" : 11, "horizontal" : false},
  181. {"icon" : "tree", "x" : 22, "y" : 2, "width" : 16, "height" : 16, "amount" : 22, "horizontal" : true},
  182. {"icon" : "tree", "x" : 22, "y" : 2, "width" : 16, "height" : 16, "amount" : 11, "horizontal" : false},
  183. {"icon" : "tree", "x" : 5, "y" : 155, "width" : 16, "height" : 16, "amount" : 22, "horizontal" : true},
  184. {"icon" : "tree", "x" : 5, "y" : 172, "width" : 16, "height" : 16, "amount" : 22, "horizontal" : true},
  185. {"icon" : "tree", "x" : 345, "y" : 50, "width" : 16, "height" : 16, "amount" : 8, "horizontal" : false},
  186. {"icon" : "tree", "x" : 362, "y" : 50, "width" : 16, "height" : 16, "amount" : 8, "horizontal" : false},
  187. {"icon" : "tree", "x" : 5, "y" : 36, "width" : 16, "height" : 16, "amount" : 14, "horizontal" : true},
  188. {"icon" : "tree", "x" : 277, "y" : 36, "width" : 16, "height" : 16, "amount" : 3, "horizontal" : true},
  189. {"icon" : "tree", "x" : 5, "y" : 53, "width" : 16, "height" : 16, "amount" : 3, "horizontal" : true},
  190. {"icon" : "tree", "x" : 124, "y" : 53, "width" : 16, "height" : 16, "amount" : 6, "horizontal" : true},
  191. {"icon" : "tree", "x" : 260, "y" : 53, "width" : 16, "height" : 16, "amount" : 4, "horizontal" : true},
  192. {"icon" : "tree", "x" : 5, "y" : 70, "width" : 16, "height" : 16, "amount" : 6, "horizontal" : true},
  193. {"icon" : "tree", "x" : 124, "y" : 70, "width" : 16, "height" : 16, "amount" : 7, "horizontal" : true},
  194. {"icon" : "tree", "x" : 5, "y" : 87, "width" : 16, "height" : 16, "amount" : 5, "horizontal" : true},
  195. {"icon" : "tree", "x" : 124, "y" : 87, "width" : 16, "height" : 16, "amount" : 3, "horizontal" : true},
  196. {"icon" : "tree", "x" : 260, "y" : 87, "width" : 16, "height" : 16, "amount" : 7, "horizontal" : true},
  197. {"icon" : "tree", "x" : 107, "y" : 104, "width" : 16, "height" : 16, "amount" : 7, "horizontal" : true},
  198. {"icon" : "tree", "x" : 243, "y" : 104, "width" : 16, "height" : 16, "amount" : 4, "horizontal" : true},
  199. {"icon" : "tree", "x" : 5, "y" : 121, "width" : 16, "height" : 16, "amount" : 4, "horizontal" : true},
  200. {"icon" : "tree", "x" : 124, "y" : 121, "width" : 16, "height" : 16, "amount" : 3, "horizontal" : true},
  201. {"icon" : "tree", "x" : 260, "y" : 121, "width" : 16, "height" : 16, "amount" : 4, "horizontal" : true},
  202. {"icon" : "tree", "x" : 5, "y" : 138, "width" : 16, "height" : 16, "amount" : 3, "horizontal" : true},
  203. {"icon" : "tree", "x" : 90, "y" : 138, "width" : 16, "height" : 16, "amount" : 1, "horizontal" : true},
  204. {"icon" : "tree", "x" : 192, "y" : 138, "width" : 16, "height" : 16, "amount" : 3, "horizontal" : true}
  205. ]
  206. }
  207. */