player.h 4.0 KB

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