player.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 10
  7. #define MAX_LEVELS 10
  8. #define MAX_NPCS 10
  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. } EntityContext;
  31. typedef struct
  32. {
  33. Vector old_position; // previous position of the player
  34. EntityDirection direction; // direction the player is facing
  35. EntityState state; // current state of the player
  36. Vector start_position; // starting position of the player
  37. Sprite *sprite_right; // player sprite looking right
  38. Sprite *sprite_left; // player sprite looking left
  39. int8_t dx; // x direction
  40. int8_t dy; // y direction
  41. uint32_t xp; // experience points
  42. uint32_t level; // player level
  43. uint32_t strength; // player strength
  44. uint32_t health; // player health
  45. uint32_t max_health; // player maximum health
  46. uint32_t health_regen; // player health regeneration rate per second/frame
  47. float elapsed_health_regen; // time elapsed since last health regeneration
  48. float attack_timer; // Cooldown duration between attacks
  49. float elapsed_attack_timer; // Time elapsed since the last attack
  50. char username[32]; // player username
  51. bool left; // track player sprite direction
  52. } PlayerContext;
  53. // two screens for the game menu
  54. typedef enum
  55. {
  56. GAME_MENU_INFO, // level, health, xp, etc.
  57. GAME_MENU_MORE, // more settings
  58. GAME_MENU_NPC, // NPC dialog
  59. } GameMenuScreen;
  60. typedef struct
  61. {
  62. PlayerContext *player_context;
  63. Level *levels[MAX_LEVELS];
  64. Entity *enemies[MAX_ENEMIES];
  65. Entity *npcs[MAX_NPCS];
  66. Entity *player;
  67. float fps;
  68. int level_count;
  69. int enemy_count;
  70. int npc_count;
  71. int current_level;
  72. bool ended_early;
  73. Imu *imu;
  74. bool imu_present;
  75. //
  76. bool is_switching_level;
  77. bool is_menu_open;
  78. //
  79. uint32_t elapsed_button_timer;
  80. uint32_t last_button;
  81. //
  82. GameMenuScreen menu_screen;
  83. uint8_t menu_selection;
  84. //
  85. int icon_count;
  86. int icon_offset;
  87. //
  88. char message[64];
  89. } GameContext;
  90. typedef struct
  91. {
  92. char id[16];
  93. char left_file_name[64];
  94. char right_file_name[64];
  95. uint8_t width;
  96. uint8_t height;
  97. } SpriteContext;
  98. extern const EntityDescription player_desc;
  99. void player_spawn(Level *level, GameManager *manager);
  100. SpriteContext *get_sprite_context(const char *name);