game.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include "engine/engine.h"
  3. #include <game/world.h>
  4. #include <game/level.h>
  5. #include <game/enemy.h>
  6. #include "flip_world.h"
  7. #include "flip_storage/storage.h"
  8. #define PLAYER_COLLISION_VERTICAL 5
  9. #define PLAYER_COLLISION_HORIZONTAL 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 health; // player health
  37. uint32_t strength; // player strength
  38. float attack_timer; // Cooldown duration between attacks
  39. float elapsed_attack_timer; // Time elapsed since the last attack
  40. } PlayerContext;
  41. typedef struct
  42. {
  43. PlayerContext *player_context;
  44. Level *levels[10];
  45. Entity *enemies[2];
  46. Entity *players[1];
  47. GameKey user_input;
  48. float fps;
  49. int level_count;
  50. int enemy_count;
  51. int current_level;
  52. } GameContext;
  53. extern const EntityDescription player_desc;
  54. void player_spawn(Level *level, GameManager *manager);
  55. // Get game context: GameContext* game_context = game_manager_game_context_get(manager);