scene.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/gui_i.h>
  4. #include <u8g2/u8g2.h>
  5. #ifndef ARRSIZE
  6. #define ARRSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
  7. #endif
  8. #ifndef MAX
  9. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  10. #endif
  11. #ifndef MIN
  12. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  13. #endif
  14. #ifndef CLAMP
  15. #define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower)))
  16. #endif
  17. // global
  18. #define SCALE 32
  19. // screen
  20. #define SCREEN_WIDTH GUI_DISPLAY_WIDTH
  21. #define SCREEN_HEIGHT GUI_DISPLAY_HEIGHT
  22. #define BONDARIES_X_LEFT 40
  23. #define BONDARIES_X_RIGHT 88
  24. // player
  25. #define DOLPHIN_WIDTH 32
  26. #define DOLPHIN_HEIGHT 32
  27. #define DOLPHIN_CENTER (SCREEN_WIDTH / 2 - DOLPHIN_WIDTH / 2)
  28. #define SPEED_X 2
  29. #define ACTIONS_NUM 5
  30. #define DOLPHIN_DEFAULT_Y 20
  31. // world
  32. #define WORLD_WIDTH 2048
  33. #define WORLD_HEIGHT 64
  34. #define LAYERS 8
  35. #define SCENE_ZOOM 9
  36. #define DOLPHIN_LAYER 6
  37. #define PARALLAX_MOD 7
  38. #define PARALLAX(layer) layer / PARALLAX_MOD - layer
  39. #define DIALOG_PROGRESS 250
  40. enum Actions { SLEEP = 0, IDLE, WALK, EMOTE, INTERACT, MINDCONTROL };
  41. static const uint16_t default_timeout[] =
  42. {[SLEEP] = 300, [IDLE] = 100, [WALK] = 100, [EMOTE] = 50, [INTERACT] = 10, [MINDCONTROL] = 50};
  43. typedef enum {
  44. EventTypeTick,
  45. EventTypeKey,
  46. } EventType;
  47. typedef struct {
  48. union {
  49. InputEvent input;
  50. } value;
  51. EventType type;
  52. } AppEvent;
  53. typedef struct {
  54. int32_t x;
  55. int32_t y;
  56. } Vec2;
  57. typedef struct {
  58. osMessageQueueId_t mqueue;
  59. Gui* gui;
  60. ViewPort* view_port;
  61. osTimerId_t* timer;
  62. } SceneAppGui;
  63. typedef struct {
  64. uint8_t layer;
  65. uint16_t timeout;
  66. int32_t x;
  67. int32_t y;
  68. IconName icon;
  69. char action_name[16];
  70. void (*draw)(Canvas* canvas, void* model);
  71. void (*callback)(Canvas* canvas, void* model);
  72. } Item;
  73. typedef struct {
  74. ///
  75. Vec2 player;
  76. Vec2 player_global;
  77. Vec2 player_v;
  78. Vec2 screen;
  79. IconName dolphin_gfx;
  80. IconName dolphin_gfx_b; // temp
  81. bool player_flipped;
  82. bool use_pending;
  83. // dolphin_scene_debug
  84. bool debug;
  85. uint8_t player_anim;
  86. uint8_t scene_id;
  87. uint8_t emote_id;
  88. uint8_t previous_emote;
  89. uint8_t dialogue_id;
  90. uint8_t previous_dialogue;
  91. uint32_t action_timeout;
  92. uint8_t poi;
  93. uint8_t action;
  94. uint8_t next_action;
  95. uint8_t prev_action;
  96. int8_t zoom_v;
  97. uint8_t scene_zoom;
  98. uint8_t dialog_progress;
  99. FuriThread* scene_app_thread;
  100. } SceneState;
  101. void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t);
  102. void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas);
  103. void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input);
  104. void dolphin_scene_coordinates(SceneState* state, uint32_t dt);
  105. void dolphin_scene_render_state(SceneState* state, Canvas* canvas);
  106. void dolphin_scene_update_state(SceneState* state, uint32_t t, uint32_t dt);
  107. void dolphin_scene_redraw(Canvas* canvas, void* ctx);
  108. void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt);
  109. void dolphin_scene_handle_input(SceneState* state, InputEvent* input);