scene.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 / 2)
  16. #define SPEED_X 2
  17. #define ACTIONS_NUM 5
  18. #define DOLPHIN_DEFAULT_Y 20
  19. // world
  20. #define WORLD_WIDTH 2048
  21. #define WORLD_HEIGHT 64
  22. #define LAYERS 8
  23. #define SCENE_ZOOM 9
  24. #define DOLPHIN_LAYER 6
  25. #define PARALLAX_MOD 7
  26. #define PARALLAX(layer) layer / PARALLAX_MOD - layer
  27. #define DIALOG_PROGRESS 250
  28. enum Actions { SLEEP = 0, IDLE, WALK, EMOTE, INTERACT, MINDCONTROL };
  29. static const uint16_t default_timeout[] =
  30. {[SLEEP] = 300, [IDLE] = 100, [WALK] = 100, [EMOTE] = 50, [INTERACT] = 10, [MINDCONTROL] = 50};
  31. typedef enum {
  32. EventTypeTick,
  33. EventTypeKey,
  34. } EventType;
  35. typedef struct {
  36. union {
  37. InputEvent input;
  38. } value;
  39. EventType type;
  40. } AppEvent;
  41. typedef struct {
  42. int32_t x;
  43. int32_t y;
  44. } Vec2;
  45. typedef struct {
  46. osMessageQueueId_t mqueue;
  47. Gui* gui;
  48. ViewPort* view_port;
  49. osTimerId_t* timer;
  50. } SceneAppGui;
  51. typedef struct {
  52. uint8_t layer;
  53. uint16_t timeout;
  54. int32_t x;
  55. int32_t y;
  56. const Icon* icon;
  57. char action_name[16];
  58. void (*draw)(Canvas* canvas, void* model);
  59. void (*callback)(Canvas* canvas, void* model);
  60. } Item;
  61. typedef struct {
  62. ///
  63. Vec2 player;
  64. Vec2 player_global;
  65. Vec2 player_v;
  66. Vec2 screen;
  67. const Icon* dolphin_gfx;
  68. const Icon* dolphin_gfx_b; // temp
  69. bool player_flipped;
  70. bool use_pending;
  71. // dolphin_scene_debug
  72. bool debug;
  73. uint8_t player_anim;
  74. uint8_t scene_id;
  75. uint8_t emote_id;
  76. uint8_t previous_emote;
  77. uint8_t dialogue_id;
  78. uint8_t previous_dialogue;
  79. uint32_t action_timeout;
  80. uint8_t poi;
  81. uint8_t action;
  82. uint8_t next_action;
  83. uint8_t prev_action;
  84. int8_t zoom_v;
  85. uint8_t scene_zoom;
  86. uint8_t dialog_progress;
  87. FuriThread* scene_app_thread;
  88. } SceneState;
  89. void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t);
  90. void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas);
  91. void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input);
  92. void dolphin_scene_coordinates(SceneState* state, uint32_t dt);
  93. void dolphin_scene_render_state(SceneState* state, Canvas* canvas);
  94. void dolphin_scene_update_state(SceneState* state, uint32_t t, uint32_t dt);
  95. void dolphin_scene_redraw(Canvas* canvas, void* ctx);
  96. void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt);
  97. void dolphin_scene_handle_input(SceneState* state, InputEvent* input);