icon.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #include "game/icon.h"
  2. // Icon entity description
  3. static void icon_collision(Entity *self, Entity *other, GameManager *manager, void *context)
  4. {
  5. UNUSED(manager);
  6. UNUSED(self);
  7. IconContext *icon = (IconContext *)context;
  8. UNUSED(icon);
  9. if (entity_description_get(other) == &player_desc)
  10. {
  11. PlayerContext *player = (PlayerContext *)entity_context_get(other);
  12. if (player)
  13. {
  14. Vector pos = entity_pos_get(other);
  15. // Bounce the player back by 2 units opposite their last movement direction
  16. pos.x -= player->dx * 2;
  17. pos.y -= player->dy * 2;
  18. entity_pos_set(other, pos);
  19. // Reset player's movement direction to prevent immediate re-collision
  20. player->dx = 0;
  21. player->dy = 0;
  22. }
  23. }
  24. }
  25. static void icon_render(Entity *self, GameManager *manager, Canvas *canvas, void *context)
  26. {
  27. UNUSED(manager);
  28. IconContext *icon_ctx = (IconContext *)context;
  29. Vector pos = entity_pos_get(self);
  30. canvas_draw_icon(canvas, pos.x - camera_x - icon_ctx->width / 2, pos.y - camera_y - icon_ctx->height / 2, icon_ctx->icon);
  31. }
  32. static void icon_start(Entity *self, GameManager *manager, void *context)
  33. {
  34. UNUSED(manager);
  35. IconContext *icon_ctx = (IconContext *)context;
  36. // Just add the collision rectangle for 16x16 icon
  37. entity_collider_add_rect(self, icon_ctx->width + COLLISION_BOX_PADDING_HORIZONTAL, icon_ctx->height + COLLISION_BOX_PADDING_VERTICAL);
  38. }
  39. const EntityDescription icon_desc = {
  40. .start = icon_start,
  41. .stop = NULL,
  42. .update = NULL,
  43. .render = icon_render,
  44. .collision = icon_collision,
  45. .event = NULL,
  46. .context_size = sizeof(IconContext),
  47. };
  48. const Icon *get_icon(char *name)
  49. {
  50. if (strcmp(name, "earth") == 0)
  51. {
  52. return &I_icon_earth_15x16;
  53. }
  54. if (strcmp(name, "home") == 0)
  55. {
  56. return &I_icon_home_15x16;
  57. }
  58. if (strcmp(name, "house") == 0)
  59. {
  60. return &I_icon_house_48x32px;
  61. }
  62. if (strcmp(name, "house_3d") == 0)
  63. {
  64. return &I_icon_house_3d_34x45px;
  65. }
  66. if (strcmp(name, "info") == 0)
  67. {
  68. return &I_icon_info_15x16;
  69. }
  70. if (strcmp(name, "man") == 0)
  71. {
  72. return &I_icon_man_7x16;
  73. }
  74. if (strcmp(name, "plant") == 0)
  75. {
  76. return &I_icon_plant_16x16;
  77. }
  78. if (strcmp(name, "plant_fern") == 0)
  79. {
  80. return &I_icon_plant_fern_18x16px;
  81. }
  82. if (strcmp(name, "plant_pointy") == 0)
  83. {
  84. return &I_icon_plant_pointy_13x16px;
  85. }
  86. if (strcmp(name, "tree") == 0)
  87. {
  88. return &I_icon_tree_16x16;
  89. }
  90. if (strcmp(name, "tree_29x30") == 0)
  91. {
  92. return &I_icon_tree_29x30px;
  93. }
  94. if (strcmp(name, "tree_48x48") == 0)
  95. {
  96. return &I_icon_tree_48x48px;
  97. }
  98. if (strcmp(name, "woman") == 0)
  99. {
  100. return &I_icon_woman_9x16;
  101. }
  102. if (strcmp(name, "chest_closed") == 0)
  103. {
  104. return &I_icon_chest_closed_16x13px;
  105. }
  106. if (strcmp(name, "chest_open") == 0)
  107. {
  108. return &I_icon_chest_open_16x16px;
  109. }
  110. if (strcmp(name, "fence") == 0)
  111. {
  112. return &I_icon_fence_16x8px;
  113. }
  114. if (strcmp(name, "fence_end") == 0)
  115. {
  116. return &I_icon_fence_end_16x8px;
  117. }
  118. if (strcmp(name, "fence_vertical_end") == 0)
  119. {
  120. return &I_icon_fence_vertical_end_6x8px;
  121. }
  122. if (strcmp(name, "fence_vertical_start") == 0)
  123. {
  124. return &I_icon_fence_vertical_start_6x15px;
  125. }
  126. if (strcmp(name, "flower") == 0)
  127. {
  128. return &I_icon_flower_16x16;
  129. }
  130. if (strcmp(name, "lake_bottom") == 0)
  131. {
  132. return &I_icon_lake_bottom_31x12px;
  133. }
  134. if (strcmp(name, "lake_bottom_left") == 0)
  135. {
  136. return &I_icon_lake_bottom_left_24x22px;
  137. }
  138. if (strcmp(name, "lake_bottom_right") == 0)
  139. {
  140. return &I_icon_lake_bottom_right_24x22px;
  141. }
  142. if (strcmp(name, "lake_left") == 0)
  143. {
  144. return &I_icon_lake_left_11x31;
  145. }
  146. if (strcmp(name, "lake_right") == 0)
  147. {
  148. return &I_icon_lake_right_11x31px;
  149. }
  150. if (strcmp(name, "lake_top") == 0)
  151. {
  152. return &I_icon_lake_top_31x22px;
  153. }
  154. if (strcmp(name, "lake_top_left") == 0)
  155. {
  156. return &I_icon_lake_top_left_24x22px;
  157. }
  158. if (strcmp(name, "lake_top_right") == 0)
  159. {
  160. return &I_icon_lake_top_right_24x22px;
  161. }
  162. if (strcmp(name, "rock_large") == 0)
  163. {
  164. return &I_icon_rock_large_18x19px;
  165. }
  166. if (strcmp(name, "rock_medium") == 0)
  167. {
  168. return &I_icon_rock_medium_16x14px;
  169. }
  170. if (strcmp(name, "rock_small") == 0)
  171. {
  172. return &I_icon_rock_small_10x8px;
  173. }
  174. // If no match is found
  175. return NULL;
  176. }
  177. const Icon *get_icon_furi(FuriString *name)
  178. {
  179. if (furi_string_cmp(name, "earth") == 0)
  180. {
  181. return &I_icon_earth_15x16;
  182. }
  183. if (furi_string_cmp(name, "home") == 0)
  184. {
  185. return &I_icon_home_15x16;
  186. }
  187. if (furi_string_cmp(name, "house") == 0)
  188. {
  189. return &I_icon_house_48x32px;
  190. }
  191. if (furi_string_cmp(name, "house_3d") == 0)
  192. {
  193. return &I_icon_house_3d_34x45px;
  194. }
  195. if (furi_string_cmp(name, "info") == 0)
  196. {
  197. return &I_icon_info_15x16;
  198. }
  199. if (furi_string_cmp(name, "man") == 0)
  200. {
  201. return &I_icon_man_7x16;
  202. }
  203. if (furi_string_cmp(name, "plant") == 0)
  204. {
  205. return &I_icon_plant_16x16;
  206. }
  207. if (furi_string_cmp(name, "plant_fern") == 0)
  208. {
  209. return &I_icon_plant_fern_18x16px;
  210. }
  211. if (furi_string_cmp(name, "plant_pointy") == 0)
  212. {
  213. return &I_icon_plant_pointy_13x16px;
  214. }
  215. if (furi_string_cmp(name, "tree") == 0)
  216. {
  217. return &I_icon_tree_16x16;
  218. }
  219. if (furi_string_cmp(name, "tree_29x30") == 0)
  220. {
  221. return &I_icon_tree_29x30px;
  222. }
  223. if (furi_string_cmp(name, "tree_48x48") == 0)
  224. {
  225. return &I_icon_tree_48x48px;
  226. }
  227. if (furi_string_cmp(name, "woman") == 0)
  228. {
  229. return &I_icon_woman_9x16;
  230. }
  231. if (furi_string_cmp(name, "chest_closed") == 0)
  232. {
  233. return &I_icon_chest_closed_16x13px;
  234. }
  235. if (furi_string_cmp(name, "chest_open") == 0)
  236. {
  237. return &I_icon_chest_open_16x16px;
  238. }
  239. if (furi_string_cmp(name, "fence") == 0)
  240. {
  241. return &I_icon_fence_16x8px;
  242. }
  243. if (furi_string_cmp(name, "fence_end") == 0)
  244. {
  245. return &I_icon_fence_end_16x8px;
  246. }
  247. if (furi_string_cmp(name, "fence_vertical_end") == 0)
  248. {
  249. return &I_icon_fence_vertical_end_6x8px;
  250. }
  251. if (furi_string_cmp(name, "fence_vertical_start") == 0)
  252. {
  253. return &I_icon_fence_vertical_start_6x15px;
  254. }
  255. if (furi_string_cmp(name, "flower") == 0)
  256. {
  257. return &I_icon_flower_16x16;
  258. }
  259. if (furi_string_cmp(name, "lake_bottom") == 0)
  260. {
  261. return &I_icon_lake_bottom_31x12px;
  262. }
  263. if (furi_string_cmp(name, "lake_bottom_left") == 0)
  264. {
  265. return &I_icon_lake_bottom_left_24x22px;
  266. }
  267. if (furi_string_cmp(name, "lake_bottom_right") == 0)
  268. {
  269. return &I_icon_lake_bottom_right_24x22px;
  270. }
  271. if (furi_string_cmp(name, "lake_left") == 0)
  272. {
  273. return &I_icon_lake_left_11x31;
  274. }
  275. if (furi_string_cmp(name, "lake_right") == 0)
  276. {
  277. return &I_icon_lake_right_11x31px;
  278. }
  279. if (furi_string_cmp(name, "lake_top") == 0)
  280. {
  281. return &I_icon_lake_top_31x22px;
  282. }
  283. if (furi_string_cmp(name, "lake_top_left") == 0)
  284. {
  285. return &I_icon_lake_top_left_24x22px;
  286. }
  287. if (furi_string_cmp(name, "lake_top_right") == 0)
  288. {
  289. return &I_icon_lake_top_right_24x22px;
  290. }
  291. if (furi_string_cmp(name, "rock_large") == 0)
  292. {
  293. return &I_icon_rock_large_18x19px;
  294. }
  295. if (furi_string_cmp(name, "rock_medium") == 0)
  296. {
  297. return &I_icon_rock_medium_16x14px;
  298. }
  299. if (furi_string_cmp(name, "rock_small") == 0)
  300. {
  301. return &I_icon_rock_small_10x8px;
  302. }
  303. // If no match is found
  304. return NULL;
  305. }