player.h 1.8 KB

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