scene_gfx.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include <furi.h>
  2. #include "scene.h"
  3. #include "assets/emotes.h"
  4. #include "assets/items.h"
  5. #include <gui/elements.h>
  6. const char* action_str[] = {"Sleep", "Idle", "Walk", "Emote", "Use", "MC"};
  7. static void scene_draw_hint(SceneState* state, Canvas* canvas, bool glitching) {
  8. furi_assert(state);
  9. furi_assert(canvas);
  10. char buf[32];
  11. const Item* near = is_nearby(state);
  12. if(near) {
  13. int32_t hint_pos_x = (near->x - state->player_global.x) * PARALLAX(near->layer) + 25;
  14. int8_t hint_pos_y = near->y < 15 ? near->y + 4 : near->y - 16;
  15. strcpy(buf, near->action_name);
  16. if(glitching) {
  17. for(size_t g = 0; g != state->action_timeout; g++) {
  18. buf[(g * 23) % strlen(buf)] = ' ' + (random() % g * 17) % ('z' - ' ');
  19. }
  20. }
  21. canvas_draw_str(canvas, hint_pos_x, hint_pos_y, buf);
  22. }
  23. }
  24. static void scene_draw_current_emote(SceneState* state, Canvas* canvas) {
  25. furi_assert(state);
  26. furi_assert(canvas);
  27. elements_multiline_text_framed(canvas, 80, 20, (char*)emotes_list[state->emote_id]);
  28. }
  29. static void scene_draw_sleep_emote(SceneState* state, Canvas* canvas) {
  30. furi_assert(state);
  31. furi_assert(canvas);
  32. char dialog_str[] = "zZzZ..";
  33. // 2do - sofa x pos getter
  34. if(state->player_global.x == 154 && state->action_timeout % 100 < 50) {
  35. if(state->dialog_progress < strlen(dialog_str)) {
  36. if(state->action_timeout % 10 == 0) state->dialog_progress++;
  37. dialog_str[state->dialog_progress + 1] = '\0';
  38. canvas_draw_str(canvas, 80, 20, dialog_str);
  39. }
  40. } else {
  41. state->dialog_progress = 0;
  42. }
  43. }
  44. static void scene_draw_dialog(SceneState* state, Canvas* canvas) {
  45. furi_assert(state);
  46. furi_assert(canvas);
  47. char dialog_str[64];
  48. char buf[64];
  49. strcpy(dialog_str, (char*)dialogues_list[state->dialogue_id]);
  50. if(state->dialog_progress <= strlen(dialog_str)) {
  51. if(state->action_timeout % 2 == 0) state->dialog_progress++;
  52. dialog_str[state->dialog_progress] = '\0';
  53. snprintf(buf, state->dialog_progress, dialog_str);
  54. } else {
  55. snprintf(buf, 64, dialog_str);
  56. }
  57. elements_multiline_text_framed(canvas, 68, 16, buf);
  58. }
  59. /*
  60. static void draw_idle_emote(SceneState* state, Canvas* canvas){
  61. if(state->action_timeout % 50 < 40 && state->prev_action == MINDCONTROL){
  62. elements_multiline_text_framed(canvas, 68, 16, "WUT?!");
  63. }
  64. }
  65. */
  66. static void draw_idle_emote(SceneState* state, Canvas* canvas) {
  67. furi_assert(state);
  68. furi_assert(canvas);
  69. char dialog_str[] = "...";
  70. if(state->action_timeout % 100 < 50) {
  71. if(state->dialog_progress < strlen(dialog_str)) {
  72. if(state->action_timeout % 10 == 0) state->dialog_progress++;
  73. dialog_str[state->dialog_progress + 1] = '\0';
  74. canvas_draw_str(canvas, 70, 15, dialog_str);
  75. }
  76. } else {
  77. state->dialog_progress = 0;
  78. }
  79. }
  80. void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas) {
  81. furi_assert(state);
  82. furi_assert(canvas);
  83. if(state->scene_zoom == SCENE_ZOOM) {
  84. state->dolphin_gfx = &I_DolphinExcited_64x63;
  85. } else if(state->action == SLEEP && state->player_global.x == 154) { // 2do - sofa x pos getter
  86. state->dolphin_gfx = &A_FX_Sitting_40x27;
  87. state->dolphin_gfx_b = &I_FX_SittingB_40x27;
  88. } else if(state->action != INTERACT) {
  89. if(state->player_v.x < 0 || state->player_flipped) {
  90. if(state->player_anim == 0) {
  91. state->dolphin_gfx = &I_WalkL1_32x32;
  92. state->dolphin_gfx_b = &I_WalkLB1_32x32;
  93. } else {
  94. state->dolphin_gfx = &I_WalkL2_32x32;
  95. state->dolphin_gfx_b = &I_WalkLB2_32x32;
  96. }
  97. } else if(state->player_v.x > 0 || !state->player_flipped) {
  98. if(state->player_anim == 0) {
  99. state->dolphin_gfx = &I_WalkR1_32x32;
  100. state->dolphin_gfx_b = &I_WalkRB1_32x32;
  101. } else {
  102. state->dolphin_gfx = &I_WalkR2_32x32;
  103. state->dolphin_gfx_b = &I_WalkRB2_32x32;
  104. }
  105. }
  106. }
  107. canvas_set_bitmap_mode(canvas, true);
  108. canvas_set_color(canvas, ColorWhite);
  109. canvas_draw_icon(canvas, state->player.x, state->player.y, state->dolphin_gfx_b);
  110. canvas_set_color(canvas, ColorBlack);
  111. canvas_draw_icon(canvas, state->player.x, state->player.y, state->dolphin_gfx);
  112. canvas_set_bitmap_mode(canvas, false);
  113. }
  114. static bool item_screen_bounds(int32_t pos) {
  115. return pos > -SCREEN_WIDTH && pos < (SCREEN_WIDTH * 2);
  116. }
  117. void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t) {
  118. furi_assert(state);
  119. furi_assert(canvas);
  120. canvas_set_font(canvas, FontSecondary);
  121. canvas_set_color(canvas, ColorBlack);
  122. const Item** current_scene = get_scene(state);
  123. for(uint8_t l = 0; l < LAYERS; l++) {
  124. if(state->scene_zoom < SCENE_ZOOM) {
  125. for(uint8_t i = 0; i < ITEMS_NUM; i++) {
  126. int32_t item_pos = (current_scene[i]->x - state->player_global.x);
  127. if(item_screen_bounds(item_pos)) {
  128. if(current_scene[i]->draw) current_scene[i]->draw(canvas, state);
  129. if(l == current_scene[i]->layer) {
  130. canvas_draw_icon(
  131. canvas,
  132. item_pos * PARALLAX(l),
  133. current_scene[i]->y,
  134. current_scene[i]->icon);
  135. canvas_set_bitmap_mode(canvas, false);
  136. }
  137. }
  138. }
  139. if(l == 0) canvas_draw_line(canvas, 0, 42, 128, 42);
  140. }
  141. if(l == DOLPHIN_LAYER) dolphin_scene_render_dolphin(state, canvas);
  142. }
  143. }
  144. void dolphin_scene_render_state(SceneState* state, Canvas* canvas) {
  145. furi_assert(state);
  146. furi_assert(canvas);
  147. char buf[64];
  148. canvas_set_font(canvas, FontSecondary);
  149. canvas_set_color(canvas, ColorBlack);
  150. // dolphin_scene_debug
  151. if(state->debug) {
  152. sprintf(
  153. buf,
  154. "x:%ld>%d %ld %s",
  155. state->player_global.x,
  156. state->poi,
  157. state->action_timeout,
  158. action_str[state->action]);
  159. canvas_draw_str(canvas, 0, 13, buf);
  160. }
  161. if(state->scene_zoom == SCENE_ZOOM)
  162. scene_draw_dialog(state, canvas);
  163. else if(state->action == EMOTE)
  164. scene_draw_current_emote(state, canvas);
  165. else if(state->action == MINDCONTROL)
  166. scene_draw_hint(state, canvas, state->action_timeout > 45);
  167. else if(state->action == INTERACT)
  168. scene_activate_item_callback(state, canvas);
  169. else if(state->action == SLEEP)
  170. scene_draw_sleep_emote(state, canvas);
  171. else if(state->action == IDLE)
  172. draw_idle_emote(state, canvas);
  173. }