player.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include "engine/engine.h"
  3. #include <flip_world.h>
  4. #include <game/game.h>
  5. #include "engine/sensors/imu.h"
  6. #define MAX_ENEMIES 5
  7. #define MAX_LEVELS 5
  8. #define MAX_NPCS 1
  9. typedef enum
  10. {
  11. SPRITE_ID_AXE,
  12. SPRITE_ID_BOW,
  13. SPRITE_ID_NAKED,
  14. SPRITE_ID_SWORD,
  15. SPRITE_ID_CYCLOPS,
  16. SPRITE_ID_GHOST,
  17. SPRITE_ID_OGRE,
  18. SPRITE_ID_FUNNY
  19. } SpriteID;
  20. // EntityContext definition
  21. typedef struct
  22. {
  23. SpriteID id; // Unique ID for the entity type
  24. uint8_t index; // Index for the specific entity instance
  25. Vector size; // Size of the entity
  26. Sprite *sprite_right; // Entity sprite when looking right
  27. Sprite *sprite_left; // Entity sprite when looking left
  28. EntityDirection direction; // Direction the entity is facing
  29. EntityState state; // Current state of the entity
  30. Vector start_position; // Start position of the entity
  31. Vector end_position; // End position of the entity
  32. float move_timer; // Timer for the entity movement
  33. float elapsed_move_timer; // Elapsed time for the entity movement
  34. float radius; // Collision radius for the entity
  35. float speed; // Speed of the entity
  36. float attack_timer; // Cooldown duration between attacks
  37. float elapsed_attack_timer; // Time elapsed since the last attack
  38. uint32_t strength; // Damage the entity deals
  39. float health; // Health of the entity
  40. char message[64]; // Message to display when interacting with the entity
  41. bool is_user; // Flag to indicate if the entity is a live player or not
  42. char username[32]; // entity username
  43. uint32_t xp; // experience points
  44. uint32_t level; // entity level
  45. } EntityContext;
  46. typedef struct
  47. {
  48. Vector old_position; // previous position of the player
  49. EntityDirection direction; // direction the player is facing
  50. EntityState state; // current state of the player
  51. Vector start_position; // starting position of the player
  52. Sprite *sprite_right; // player sprite looking right
  53. Sprite *sprite_left; // player sprite looking left
  54. int8_t dx; // x direction
  55. int8_t dy; // y direction
  56. uint32_t xp; // experience points
  57. uint32_t level; // player level
  58. uint32_t strength; // player strength
  59. uint32_t health; // player health
  60. uint32_t max_health; // player maximum health
  61. uint8_t health_regen; // player health regeneration rate per second/frame
  62. float elapsed_health_regen; // time elapsed since last health regeneration
  63. float attack_timer; // Cooldown duration between attacks
  64. float elapsed_attack_timer; // Time elapsed since the last attack
  65. char username[32]; // player username
  66. bool left; // track player sprite direction
  67. } PlayerContext;
  68. // two screens for the game menu
  69. typedef enum
  70. {
  71. GAME_MENU_INFO, // level, health, xp, etc.
  72. GAME_MENU_MORE, // more settings
  73. GAME_MENU_NPC, // NPC dialog
  74. } GameMenuScreen;
  75. // game modes
  76. typedef enum
  77. {
  78. GAME_MODE_PVE = 0, // player(s) vs everyone
  79. GAME_MODE_PVP = 1, // player vs player
  80. GAME_MODE_STORY = 2, // story mode
  81. } GameMode;
  82. typedef struct
  83. {
  84. Level *levels[MAX_LEVELS];
  85. Entity *enemies[MAX_ENEMIES];
  86. Entity *npcs[MAX_NPCS];
  87. Entity *player;
  88. //
  89. float fps;
  90. int8_t level_count;
  91. int8_t enemy_count;
  92. int8_t npc_count;
  93. int8_t current_level;
  94. bool ended_early;
  95. Imu *imu;
  96. bool imu_present;
  97. //
  98. bool is_switching_level;
  99. bool is_menu_open;
  100. //
  101. uint16_t elapsed_button_timer;
  102. uint8_t last_button;
  103. //
  104. GameMenuScreen menu_screen;
  105. uint8_t menu_selection;
  106. //
  107. GameMode game_mode;
  108. //
  109. uint32_t icon_count;
  110. uint16_t icon_offset;
  111. //
  112. char message[64];
  113. //
  114. uint8_t tutorial_step;
  115. //
  116. FlipperHTTP *fhttp;
  117. //
  118. FuriString *ws_info;
  119. } GameContext;
  120. typedef struct
  121. {
  122. SpriteID id;
  123. char left_file_name[33];
  124. char right_file_name[33];
  125. uint8_t width;
  126. uint8_t height;
  127. } SpriteContext;
  128. extern const EntityDescription player_desc;
  129. void player_spawn(Level *level, GameManager *manager);
  130. SpriteContext *sprite_context_get(const char *name);
  131. int player_level_iterative_get(uint32_t xp);