player.h 2.1 KB

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