player.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Maximum enemies
  7. #define MAX_ENEMIES 2
  8. #define MAX_LEVELS 10
  9. typedef enum
  10. {
  11. PLAYER_IDLE,
  12. PLAYER_MOVING,
  13. PLAYER_ATTACKING,
  14. PLAYER_ATTACKED,
  15. PLAYER_DEAD,
  16. } PlayerState;
  17. typedef enum
  18. {
  19. PLAYER_UP,
  20. PLAYER_DOWN,
  21. PLAYER_LEFT,
  22. PLAYER_RIGHT
  23. } PlayerDirection;
  24. typedef struct
  25. {
  26. PlayerDirection direction; // direction the player is facing
  27. PlayerState state; // current state of the player
  28. Vector start_position; // starting position of the player
  29. Sprite *sprite_right; // player sprite looking right
  30. Sprite *sprite_left; // player sprite looking left
  31. int8_t dx; // x direction
  32. int8_t dy; // y direction
  33. uint32_t xp; // experience points
  34. uint32_t level; // player level
  35. uint32_t strength; // player strength
  36. uint32_t health; // player health
  37. uint32_t max_health; // player maximum health
  38. uint32_t health_regen; // player health regeneration rate per second/frame
  39. float elapsed_health_regen; // time elapsed since last health regeneration
  40. float attack_timer; // Cooldown duration between attacks
  41. float elapsed_attack_timer; // Time elapsed since the last attack
  42. char username[32]; // player username
  43. } PlayerContext;
  44. typedef struct
  45. {
  46. PlayerContext *player_context;
  47. Level *levels[MAX_LEVELS];
  48. Entity *enemies[MAX_ENEMIES];
  49. Entity *player;
  50. GameKey user_input;
  51. float fps;
  52. int level_count;
  53. int enemy_count;
  54. int current_level;
  55. bool ended_early;
  56. Imu *imu;
  57. bool imu_present;
  58. } GameContext;
  59. typedef struct
  60. {
  61. char id[16];
  62. char left_file_name[64];
  63. char right_file_name[64];
  64. uint8_t width;
  65. uint8_t height;
  66. } SpriteContext;
  67. extern const EntityDescription player_desc;
  68. void player_spawn(Level *level, GameManager *manager);
  69. SpriteContext *get_sprite_context(const char *name);