player.h 2.0 KB

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