player.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 10
  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[MAX_ENEMIES];
  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. typedef struct
  55. {
  56. char id[16];
  57. char left_file_name[64];
  58. char right_file_name[64];
  59. uint8_t width;
  60. uint8_t height;
  61. } SpriteContext;
  62. extern const EntityDescription player_desc;
  63. void player_spawn(Level *level, GameManager *manager);
  64. SpriteContext *get_sprite_context(const char *name);