player.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. } EntityContext;
  44. typedef struct
  45. {
  46. Vector old_position; // previous position of the player
  47. EntityDirection direction; // direction the player is facing
  48. EntityState state; // current state of the player
  49. Vector start_position; // starting position of the player
  50. Sprite *sprite_right; // player sprite looking right
  51. Sprite *sprite_left; // player sprite looking left
  52. int8_t dx; // x direction
  53. int8_t dy; // y direction
  54. uint32_t xp; // experience points
  55. uint32_t level; // player level
  56. uint32_t strength; // player strength
  57. uint32_t health; // player health
  58. uint32_t max_health; // player maximum health
  59. uint8_t health_regen; // player health regeneration rate per second/frame
  60. float elapsed_health_regen; // time elapsed since last health regeneration
  61. float attack_timer; // Cooldown duration between attacks
  62. float elapsed_attack_timer; // Time elapsed since the last attack
  63. char username[32]; // player username
  64. bool left; // track player sprite direction
  65. } PlayerContext;
  66. // two screens for the game menu
  67. typedef enum
  68. {
  69. GAME_MENU_INFO, // level, health, xp, etc.
  70. GAME_MENU_MORE, // more settings
  71. GAME_MENU_NPC, // NPC dialog
  72. } GameMenuScreen;
  73. // game modes
  74. typedef enum
  75. {
  76. GAME_MODE_PVE = 0, // player(s) vs everyone
  77. GAME_MODE_PVP = 1, // player vs player
  78. GAME_MODE_STORY = 2, // story mode
  79. } GameMode;
  80. typedef struct
  81. {
  82. Level *levels[MAX_LEVELS];
  83. Entity *enemies[MAX_ENEMIES];
  84. Entity *npcs[MAX_NPCS];
  85. Entity *player;
  86. //
  87. float fps;
  88. int8_t level_count;
  89. int8_t enemy_count;
  90. int8_t npc_count;
  91. int8_t current_level;
  92. bool ended_early;
  93. Imu *imu;
  94. bool imu_present;
  95. //
  96. bool is_switching_level;
  97. bool is_menu_open;
  98. //
  99. uint16_t elapsed_button_timer;
  100. uint8_t last_button;
  101. //
  102. GameMenuScreen menu_screen;
  103. uint8_t menu_selection;
  104. //
  105. GameMode game_mode;
  106. //
  107. uint32_t icon_count;
  108. uint16_t icon_offset;
  109. //
  110. char message[64];
  111. //
  112. uint8_t tutorial_step;
  113. //
  114. FlipperHTTP *fhttp;
  115. } GameContext;
  116. typedef struct
  117. {
  118. SpriteID id;
  119. char left_file_name[33];
  120. char right_file_name[33];
  121. uint8_t width;
  122. uint8_t height;
  123. } SpriteContext;
  124. extern const EntityDescription player_desc;
  125. void player_spawn(Level *level, GameManager *manager);
  126. SpriteContext *sprite_context_get(const char *name);