123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #ifndef _GAME_PLAYER_H_
- #define _GAME_PLAYER_H_
- #include "SDL2/SDL.h"
- /* states a player can have
- * depending on them, movement, casting
- * or other actions may be disabled
- */
- enum PLAYER_STATES {
- IDLE,
- JUMP,
- FALL,
- CAST,
- ATTACK,
- DROWN,
- };
- /* game player
- * the player can:
- ** move left/right
- ** jump/fall (gravity)
- ** activate skill (not implemented)
- ** attack (not implemented)
- */
- struct game_player {
- // player's texture and rect
- SDL_Texture *tex;
- SDL_Rect tex_rect;
- SDL_Rect rect;
- // size of player
- int tex_size;
- // animation and states
- enum PLAYER_STATES state;
- int anim_count;
- enum {LOOKING_LEFT = -1, LOOKING_RIGHT = 1} looking_side;
- // left/right movement
- enum {MOVE_LEFT = -1, MOVE_NONE, MOVE_RIGHT} move;
- float speed_max;
- float velocity_x;
- float velocity_y;
- /* reference to map
- * needed when casting skills that affect the map,
- * or walking on it, platform_id defines the id of the platform
- * the player walks on
- */
- struct game_map *map;
- int platform_id;
- /* reference to players
- * the players on the map so that this player can interact with them
- * or move around them
- */
- struct game_player *players;
- /* ai players have a target they keep following
- */
- int map_target;
- // casting skill variables
- int casting_cooldown;
- // player level
- int level;
- }; // game_player
- /* basic interaction
- */
- void game_player_init(struct game_player *, struct game_map *);
- void game_player_update(struct game_player*);
- void game_player_draw(struct game_player*);
- /* movement commands
- * any movement will remain active until cancelled
- */
- void game_player_moveleft(struct game_player *);
- void game_player_moveright(struct game_player *);
- void game_player_movestop(struct game_player *);
- // jumping is one-off
- void game_player_jump(struct game_player *);
- // player's special skill
- void game_player_useskill(struct game_player *);
- // player's attack
- void game_player_attack(struct game_player *);
- // ai
- void game_player_ai(struct game_player *);
- // use to bump a player away, from given direction
- void game_player_bump(struct game_player *, struct game_player *p);
- // collision data
- int game_player_left(struct game_player *);
- int game_player_top(struct game_player *);
- int game_player_right(struct game_player *);
- int game_player_bottom(struct game_player *);
- int game_player_centerx(struct game_player *);
- int game_player_centery(struct game_player *);
- void game_player_offset(struct game_player *, int, int);
- // getters
- int game_player_get_state(struct game_player *);
- #endif
|