items.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "dolphin_scene/items_i.h"
  2. #include <gui/elements.h>
  3. #include "applications.h"
  4. const Item TV = {
  5. .layer = 7,
  6. .timeout = 10,
  7. .x = 160,
  8. .y = 34,
  9. .icon = I_TV_20x24,
  10. .action_name = "Use",
  11. .draw = draw_tv,
  12. .callback = smash_tv};
  13. const Item Painting = {
  14. .layer = 3,
  15. .timeout = 20,
  16. .x = 160,
  17. .y = 10,
  18. .icon = I_Home_painting_17x20,
  19. .action_name = "Inspect",
  20. .draw = NULL,
  21. .callback = inspect_painting};
  22. const Item Sofa = {
  23. .layer = 4,
  24. .timeout = 100,
  25. .x = 250,
  26. .y = 34,
  27. .icon = I_Sofa_40x13,
  28. .action_name = "Sit",
  29. .draw = NULL,
  30. .callback = sofa_sit};
  31. const Item PC = {
  32. .layer = 4,
  33. .timeout = 100,
  34. .x = 400,
  35. .y = 10,
  36. .icon = I_PC_22x29,
  37. .action_name = "Use",
  38. .draw = NULL,
  39. .callback = pc_callback};
  40. const Item* Home[ITEMS_NUM] = {&TV, &Sofa, &Painting, &PC};
  41. const Item** Scenes[1] = {*&Home};
  42. const Item** get_scene(SceneState* state) {
  43. return Scenes[state->scene_id];
  44. }
  45. static void dolphin_scene_start_app(SceneState* state, const FlipperApplication* flipper_app) {
  46. furi_assert(state);
  47. furi_assert(flipper_app);
  48. state->scene_app_thread = furi_thread_alloc();
  49. furi_assert(flipper_app->app);
  50. furi_assert(flipper_app->name);
  51. furi_thread_set_name(state->scene_app_thread, flipper_app->name);
  52. furi_thread_set_stack_size(state->scene_app_thread, flipper_app->stack_size);
  53. furi_thread_set_callback(state->scene_app_thread, flipper_app->app);
  54. furi_thread_start(state->scene_app_thread);
  55. }
  56. const Item* is_nearby(SceneState* state) {
  57. furi_assert(state);
  58. uint8_t item = 0;
  59. bool found = false;
  60. const Item** current = get_scene(state);
  61. while(item < ITEMS_NUM) {
  62. int32_t rel =
  63. (DOLPHIN_CENTER + DOLPHIN_WIDTH / 2 -
  64. (current[item]->x - state->player_global.x) * PARALLAX(current[item]->layer));
  65. if(abs(rel) <= DOLPHIN_WIDTH / 2) {
  66. found = !found;
  67. break;
  68. }
  69. ++item;
  70. }
  71. return found ? current[item] : NULL;
  72. }
  73. void draw_tv(Canvas* canvas, void* state) {
  74. furi_assert(state);
  75. SceneState* s = state;
  76. canvas_set_color(canvas, ColorWhite);
  77. canvas_draw_box(
  78. canvas, (TV.x + 3 - s->player_global.x) * PARALLAX(TV.layer), TV.y + 4, 16, 20);
  79. canvas_set_color(canvas, ColorBlack);
  80. canvas_set_bitmap_mode(canvas, true);
  81. }
  82. void smash_tv(Canvas* canvas, void* state) {
  83. furi_assert(state);
  84. SceneState* s = state;
  85. s->player_flipped = true;
  86. canvas_set_bitmap_mode(canvas, true);
  87. canvas_draw_icon_name(
  88. canvas, ((TV.x - 5) - s->player_global.x) * PARALLAX(TV.layer), TV.y - 2, I_FX_Bang_32x6);
  89. canvas_set_bitmap_mode(canvas, false);
  90. if(s->action_timeout < TV.timeout - 2) {
  91. elements_multiline_text_framed(canvas, 80, 24, "Bang!");
  92. }
  93. }
  94. void sofa_sit(Canvas* canvas, void* state) {
  95. furi_assert(state);
  96. SceneState* s = state;
  97. // temp fix pos
  98. s->player_global.x = 154;
  99. s->dolphin_gfx = A_FX_Sitting_40x27;
  100. s->dolphin_gfx_b = I_FX_SittingB_40x27;
  101. }
  102. void inspect_painting(Canvas* canvas, void* state) {
  103. furi_assert(state);
  104. SceneState* s = state;
  105. if(s->use_pending) {
  106. dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[0]);
  107. }
  108. }
  109. void pc_callback(Canvas* canvas, void* state) {
  110. furi_assert(state);
  111. SceneState* s = state;
  112. if(s->use_pending) {
  113. dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[1]);
  114. }
  115. }