player.h 2.0 KB

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