game_player.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef _GAME_PLAYER_H_
  2. #define _GAME_PLAYER_H_
  3. #include "SDL2/SDL.h"
  4. /* states a player can have
  5. * depending on them, movement, casting
  6. * or other actions may be disabled
  7. */
  8. enum PLAYER_STATES {
  9. IDLE,
  10. JUMP,
  11. FALL,
  12. CAST,
  13. ATTACK,
  14. DROWN,
  15. };
  16. /* game player
  17. * the player can:
  18. ** move left/right
  19. ** jump/fall (gravity)
  20. ** activate skill (not implemented)
  21. ** attack (not implemented)
  22. */
  23. struct game_player {
  24. // player's texture and rect
  25. SDL_Texture *tex;
  26. SDL_Rect tex_rect;
  27. SDL_Rect rect;
  28. // size of player
  29. int tex_size;
  30. // animation and states
  31. enum PLAYER_STATES state;
  32. int anim_count;
  33. enum {LOOKING_LEFT = -1, LOOKING_RIGHT = 1} looking_side;
  34. // left/right movement
  35. enum {MOVE_LEFT = -1, MOVE_NONE, MOVE_RIGHT} move;
  36. float speed_max;
  37. float velocity_x;
  38. float velocity_y;
  39. /* reference to map
  40. * needed when casting skills that affect the map,
  41. * or walking on it, platform_id defines the id of the platform
  42. * the player walks on
  43. */
  44. struct game_map *map;
  45. int platform_id;
  46. /* reference to players
  47. * the players on the map so that this player can interact with them
  48. * or move around them
  49. */
  50. struct game_player *players;
  51. /* ai players have a target they keep following
  52. */
  53. int map_target;
  54. // casting skill variables
  55. int casting_cooldown;
  56. // player level
  57. int level;
  58. }; // game_player
  59. /* basic interaction
  60. */
  61. void game_player_init(struct game_player *, struct game_map *);
  62. void game_player_update(struct game_player*);
  63. void game_player_draw(struct game_player*);
  64. /* movement commands
  65. * any movement will remain active until cancelled
  66. */
  67. void game_player_moveleft(struct game_player *);
  68. void game_player_moveright(struct game_player *);
  69. void game_player_movestop(struct game_player *);
  70. // jumping is one-off
  71. void game_player_jump(struct game_player *);
  72. // player's special skill
  73. void game_player_useskill(struct game_player *);
  74. // player's attack
  75. void game_player_attack(struct game_player *);
  76. // ai
  77. void game_player_ai(struct game_player *);
  78. // use to bump a player away, from given direction
  79. void game_player_bump(struct game_player *, struct game_player *p);
  80. // collision data
  81. int game_player_left(struct game_player *);
  82. int game_player_top(struct game_player *);
  83. int game_player_right(struct game_player *);
  84. int game_player_bottom(struct game_player *);
  85. int game_player_centerx(struct game_player *);
  86. int game_player_centery(struct game_player *);
  87. void game_player_offset(struct game_player *, int, int);
  88. // getters
  89. int game_player_get_state(struct game_player *);
  90. #endif