player.h 2.4 KB

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