player.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 12
  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. // game ending reasons
  83. typedef enum
  84. {
  85. GAME_END_MEMORY = 0, // ran out of memory
  86. GAME_END_TUTORIAL_INCOMPLETE = 1, // tutorial incomplete
  87. GAME_END_PVP_REQUIREMENT = 2, // player level too low for pvp
  88. GAME_END_PVP_ENEMY_DEAD = 3, // enemy dead
  89. GAME_END_PVP_PLAYER_DEAD = 4, // player dead
  90. GAME_END_NETWORK = 5, // network error
  91. GAME_END_APP = 6, // app issue
  92. } GameEndReason;
  93. typedef struct
  94. {
  95. Level *levels[MAX_LEVELS];
  96. Entity *enemies[MAX_ENEMIES];
  97. Entity *npcs[MAX_NPCS];
  98. Entity *player;
  99. //
  100. float fps;
  101. int8_t level_count;
  102. int8_t enemy_count;
  103. int8_t npc_count;
  104. int8_t current_level;
  105. bool ended_early;
  106. Imu *imu;
  107. bool imu_present;
  108. //
  109. bool is_switching_level;
  110. bool is_menu_open;
  111. //
  112. uint16_t elapsed_button_timer;
  113. uint8_t last_button;
  114. //
  115. GameMenuScreen menu_screen;
  116. uint8_t menu_selection;
  117. //
  118. GameMode game_mode;
  119. GameEndReason end_reason;
  120. //
  121. uint32_t icon_count;
  122. uint16_t icon_offset;
  123. //
  124. char message[64];
  125. //
  126. uint32_t story_step;
  127. //
  128. FlipperHTTP *fhttp;
  129. //
  130. } GameContext;
  131. typedef struct
  132. {
  133. SpriteID id;
  134. char left_file_name[33];
  135. char right_file_name[33];
  136. uint8_t width;
  137. uint8_t height;
  138. } SpriteContext;
  139. extern const EntityDescription player_desc;
  140. void player_spawn(Level *level, GameManager *manager);
  141. SpriteContext *sprite_context_get(const char *name);
  142. int player_level_iterative_get(uint32_t xp);