player.h 2.1 KB

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