player.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #define MAX_ENEMIES 10
  7. #define MAX_LEVELS 10
  8. #define MAX_NPCS 10
  9. typedef struct
  10. {
  11. Vector old_position; // previous position of the player
  12. EntityDirection direction; // direction the player is facing
  13. EntityState state; // current state of the player
  14. Vector start_position; // starting position of the player
  15. Sprite *sprite_right; // player sprite looking right
  16. Sprite *sprite_left; // player sprite looking left
  17. int8_t dx; // x direction
  18. int8_t dy; // y direction
  19. uint32_t xp; // experience points
  20. uint32_t level; // player level
  21. uint32_t strength; // player strength
  22. uint32_t health; // player health
  23. uint32_t max_health; // player maximum health
  24. uint32_t health_regen; // player health regeneration rate per second/frame
  25. float elapsed_health_regen; // time elapsed since last health regeneration
  26. float attack_timer; // Cooldown duration between attacks
  27. float elapsed_attack_timer; // Time elapsed since the last attack
  28. char username[32]; // player username
  29. bool left; // track player sprite direction
  30. } PlayerContext;
  31. // two screens for the game menu
  32. typedef enum
  33. {
  34. GAME_MENU_INFO, // level, health, xp, etc.
  35. GAME_MENU_MORE, // more settings
  36. } GameMenuScreen;
  37. typedef struct
  38. {
  39. PlayerContext *player_context;
  40. Level *levels[MAX_LEVELS];
  41. Entity *enemies[MAX_ENEMIES];
  42. Entity *npcs[MAX_NPCS];
  43. Entity *player;
  44. float fps;
  45. int level_count;
  46. int enemy_count;
  47. int npc_count;
  48. int current_level;
  49. bool ended_early;
  50. Imu *imu;
  51. bool imu_present;
  52. //
  53. bool is_switching_level;
  54. bool is_menu_open;
  55. //
  56. uint32_t elapsed_button_timer;
  57. uint32_t last_button;
  58. //
  59. GameMenuScreen menu_screen;
  60. uint8_t menu_selection;
  61. //
  62. int icon_count;
  63. int icon_offset;
  64. } GameContext;
  65. typedef struct
  66. {
  67. char id[16];
  68. char left_file_name[64];
  69. char right_file_name[64];
  70. uint8_t width;
  71. uint8_t height;
  72. } SpriteContext;
  73. extern const EntityDescription player_desc;
  74. void player_spawn(Level *level, GameManager *manager);
  75. SpriteContext *get_sprite_context(const char *name);