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 5
  9. // EntityContext definition
  10. typedef struct
  11. {
  12. char id[64]; // Unique ID for the entity type
  13. int 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. float 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. } EntityContext;
  32. typedef struct
  33. {
  34. Vector old_position; // previous position of the player
  35. EntityDirection direction; // direction the player is facing
  36. EntityState state; // current state of the player
  37. Vector start_position; // starting position of the player
  38. Sprite *sprite_right; // player sprite looking right
  39. Sprite *sprite_left; // player sprite looking left
  40. int8_t dx; // x direction
  41. int8_t dy; // y direction
  42. uint32_t xp; // experience points
  43. uint32_t level; // player level
  44. uint32_t strength; // player strength
  45. uint32_t health; // player health
  46. uint32_t max_health; // player maximum health
  47. uint32_t health_regen; // player health regeneration rate per second/frame
  48. float elapsed_health_regen; // time elapsed since last health regeneration
  49. float attack_timer; // Cooldown duration between attacks
  50. float elapsed_attack_timer; // Time elapsed since the last attack
  51. char username[32]; // player username
  52. bool left; // track player sprite direction
  53. } PlayerContext;
  54. // two screens for the game menu
  55. typedef enum
  56. {
  57. GAME_MENU_INFO, // level, health, xp, etc.
  58. GAME_MENU_MORE, // more settings
  59. GAME_MENU_NPC, // NPC dialog
  60. } GameMenuScreen;
  61. // game modes
  62. typedef enum
  63. {
  64. GAME_MODE_PVE = 0, // player(s) vs everyone
  65. GAME_MODE_PVP = 1, // player vs player
  66. GAME_MODE_STORY = 2, // story mode
  67. } GameMode;
  68. typedef struct
  69. {
  70. PlayerContext *player_context;
  71. Level *levels[MAX_LEVELS];
  72. Entity *enemies[MAX_ENEMIES];
  73. Entity *npcs[MAX_NPCS];
  74. Entity *player;
  75. //
  76. float fps;
  77. int level_count;
  78. int enemy_count;
  79. int npc_count;
  80. int 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. uint32_t elapsed_button_timer;
  89. uint32_t last_button;
  90. //
  91. GameMenuScreen menu_screen;
  92. uint8_t menu_selection;
  93. //
  94. GameMode game_mode;
  95. //
  96. int icon_count;
  97. int 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);