sprite-animation/player.h

65 lines
1.4 KiB
C

#pragma once
#include "animation_player.h"
#include "state_machine.h"
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_render.h>
#include <stdint.h>
#include <stdbool.h>
enum player_states {
PLAYER_STATE_IDLE,
PLAYER_STATE_WALK,
PLAYER_STATE_DASH,
PLAYER_STATE_JUMP,
PLAYER_STATE_FALL,
COUNT_PLAYER_STATES,
};
enum player_direction {
PLAYER_DIRECTION_LEFT = -1,
PLAYER_DIRECTION_RIGHT = 1,
PLAYER_DIRECTION_UP = -1,
PLAYER_DIRECTION_DOWN = 1,
};
typedef struct player_control PlayerControl;
struct player_control {
bool walk_left;
bool walk_right;
bool space_last;
bool space_pressed;
bool jump;
bool lctrl_last;
bool lctrl_pressed;
bool dash;
bool jump_dash;
};
typedef struct movement Movement;
struct movement {
int32_t x;
int32_t y;
};
typedef struct player Player;
struct player {
uint32_t current_state;
uint32_t velocity;
int32_t base_y;
int32_t x_direction;
Movement movement;
SDL_Rect position;
StateMachine state_machine;
State states[COUNT_PLAYER_STATES];
AnimPlayer animations[COUNT_PLAYER_STATES];
PlayerControl controls;
};
void player_init (Player *player, SDL_Renderer *renderer, SDL_Rect position);
void player_events(Player *player, const SDL_Event *event);
void player_update(Player *player, uint32_t ticks);
void player_draw (const Player *player, SDL_Renderer *renderer);