player.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #include "engine/engine.h"
  3. #include <flip_world.h>
  4. #include <game/game.h>
  5. #include "engine/sensors/imu.h"
  6. // Maximum enemies
  7. #define MAX_ENEMIES 10
  8. #define MAX_LEVELS 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. Vector old_position; // previous position of the player
  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. bool left; // track player sprite direction
  45. } PlayerContext;
  46. // two screens for the game menu
  47. typedef enum
  48. {
  49. GAME_MENU_INFO, // level, health, xp, etc.
  50. GAME_MENU_MORE, // more settings
  51. } GameMenuScreen;
  52. typedef struct
  53. {
  54. PlayerContext *player_context;
  55. Level *levels[MAX_LEVELS];
  56. Entity *enemies[MAX_ENEMIES];
  57. Entity *player;
  58. float fps;
  59. int level_count;
  60. int enemy_count;
  61. int current_level;
  62. bool ended_early;
  63. Imu *imu;
  64. bool imu_present;
  65. //
  66. bool is_switching_level;
  67. bool is_menu_open;
  68. //
  69. uint32_t elapsed_button_timer;
  70. uint32_t last_button;
  71. //
  72. GameMenuScreen menu_screen;
  73. uint8_t menu_selection;
  74. //
  75. int icon_count;
  76. int icon_offset;
  77. } GameContext;
  78. typedef struct
  79. {
  80. char id[16];
  81. char left_file_name[64];
  82. char right_file_name[64];
  83. uint8_t width;
  84. uint8_t height;
  85. } SpriteContext;
  86. extern const EntityDescription player_desc;
  87. void player_spawn(Level *level, GameManager *manager);
  88. SpriteContext *get_sprite_context(const char *name);