scene.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/gui_i.h>
  4. #include <u8g2/u8g2.h>
  5. // global
  6. #define SCALE 32
  7. // screen
  8. #define SCREEN_WIDTH GUI_DISPLAY_WIDTH
  9. #define SCREEN_HEIGHT GUI_DISPLAY_HEIGHT
  10. #define BONDARIES_X_LEFT 40
  11. #define BONDARIES_X_RIGHT 88
  12. // player
  13. #define DOLPHIN_WIDTH 32
  14. #define DOLPHIN_HEIGHT 32
  15. #define DOLPHIN_CENTER (SCREEN_WIDTH / 2 - DOLPHIN_WIDTH)
  16. #define SPEED_X 4
  17. #define SPEED_Y 4
  18. #define ACTIONS_NUM 4
  19. #define DOLPHIN_DEFAULT_Y 2
  20. #define MAX_FRAMES 3
  21. // world
  22. #define WORLD_WIDTH 256
  23. #define WORLD_HEIGHT 192
  24. #define LAYERS 8
  25. #define DOLPHIN_LAYER 6
  26. #define PARALLAX_MOD 7
  27. #define PARALLAX(layer) layer / PARALLAX_MOD - layer
  28. #define DIALOG_PROGRESS 250
  29. enum Actions { IDLE = 0, EMOTE, INTERACT, MINDCONTROL };
  30. static const uint16_t default_timeout[] =
  31. {[IDLE] = 100, [EMOTE] = 50, [INTERACT] = 10, [MINDCONTROL] = 50};
  32. typedef enum {
  33. EventTypeTick,
  34. EventTypeKey,
  35. } EventType;
  36. typedef struct {
  37. union {
  38. InputEvent input;
  39. } value;
  40. EventType type;
  41. } AppEvent;
  42. typedef struct {
  43. int32_t x;
  44. int32_t y;
  45. } Vec2;
  46. typedef struct {
  47. osMessageQueueId_t mqueue;
  48. Gui* gui;
  49. ViewPort* view_port;
  50. osTimerId_t* timer;
  51. } SceneAppGui;
  52. typedef struct {
  53. uint8_t layer;
  54. uint16_t timeout;
  55. Vec2 pos;
  56. uint8_t width;
  57. uint8_t height;
  58. void (*draw)(Canvas* canvas, void* model);
  59. void (*callback)(Canvas* canvas, void* model);
  60. } Item;
  61. typedef enum {
  62. DirUp = 0,
  63. DirRight,
  64. DirDown,
  65. DirLeft,
  66. } FrameDirectionEnum;
  67. typedef struct {
  68. const Icon* f;
  69. const Icon* b;
  70. } DolphinGfxAsset;
  71. typedef struct {
  72. const DolphinGfxAsset frames[MAX_FRAMES];
  73. const uint8_t total;
  74. } DolphinFrame;
  75. typedef struct {
  76. Vec2 player;
  77. Vec2 player_global;
  78. Vec2 player_v;
  79. Vec2 screen;
  80. FrameDirectionEnum frame_group;
  81. FrameDirectionEnum last_group;
  82. FrameDirectionEnum frame_pending;
  83. FrameDirectionEnum frame_type;
  84. const DolphinFrame* current_frame;
  85. bool transition;
  86. bool transition_pending;
  87. bool use_pending;
  88. bool debug;
  89. uint8_t player_anim;
  90. uint8_t frame_idx;
  91. uint8_t scene_id;
  92. uint8_t emote_id;
  93. uint8_t previous_emote;
  94. uint8_t action;
  95. uint8_t prev_action;
  96. uint8_t action_timeout;
  97. uint8_t dialog_progress;
  98. FuriThread* scene_app_thread;
  99. } SceneState;
  100. void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t);
  101. void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas);
  102. void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input);
  103. void dolphin_scene_coordinates(SceneState* state, uint32_t dt);
  104. void dolphin_scene_render_state(SceneState* state, Canvas* canvas);
  105. void dolphin_scene_update_state(SceneState* state, uint32_t t, uint32_t dt);
  106. void dolphin_scene_redraw(Canvas* canvas, void* ctx);
  107. void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt);
  108. void dolphin_scene_handle_input(SceneState* state, InputEvent* input);