engine-psx/include/player.h

145 lines
3.7 KiB
C
Raw Normal View History

2024-07-21 19:43:49 -03:00
#ifndef PLAYER_H
#define PLAYER_H
#include "chara.h"
#include <psxgte.h>
#include "level.h"
#include "collision.h"
2024-11-23 01:00:17 -03:00
#include "input.h"
#include "player_constants.h"
2024-07-21 19:43:49 -03:00
// Constants for adjusting hitbox and sensors
2024-12-04 00:04:24 -03:00
#define WIDTH_RADIUS_NORMAL 9
2024-08-20 02:15:31 -03:00
#define HEIGHT_RADIUS_NORMAL 19
#define LEDGE_SENSOR_MAGNITUDE 26
2024-08-20 02:15:31 -03:00
#define WIDTH_RADIUS_ROLLING 7
#define HEIGHT_RADIUS_ROLLING 14
2024-12-04 00:04:24 -03:00
#define PUSH_RADIUS 10
2024-08-20 02:15:31 -03:00
2025-04-14 20:33:31 -03:00
#define HEIGHT_RADIUS_CLIMB 10
2024-11-03 17:23:11 -03:00
#define PLAYER_HURT_IFRAMES 120
2025-04-09 00:19:23 -03:00
#define PLAYER_FLY_MAXFRAMES 480
2024-11-03 17:23:11 -03:00
2025-04-07 18:50:55 -03:00
typedef enum {
CHARA_SONIC = 0,
CHARA_MILES = 1,
2025-04-08 01:46:50 -03:00
CHARA_KNUCKLES = 2,
2025-04-07 18:50:55 -03:00
} PlayerCharacter;
2025-04-08 01:46:50 -03:00
#define CHARA_MAX CHARA_KNUCKLES
2025-04-07 19:07:30 -03:00
typedef enum {
ACTION_NONE,
ACTION_SKIDDING,
ACTION_LOOKUP,
2024-08-20 02:15:31 -03:00
ACTION_CROUCHDOWN,
2024-08-25 22:11:33 -03:00
ACTION_JUMPING,
ACTION_ROLLING,
2024-09-08 17:05:05 -03:00
ACTION_SPINDASH,
2025-02-18 13:43:04 -03:00
ACTION_PEELOUT,
ACTION_DROPDASH,
ACTION_SPRING,
2024-11-03 17:23:11 -03:00
ACTION_HURT,
2025-03-11 22:50:26 -03:00
ACTION_GASP,
2025-04-10 00:04:59 -03:00
// Miles actions
2025-04-09 00:19:23 -03:00
ACTION_FLY,
2025-04-10 00:04:59 -03:00
// Knuckles actions
2025-04-09 21:06:01 -03:00
ACTION_GLIDE,
ACTION_GLIDERECOVER,
2025-04-09 21:06:01 -03:00
ACTION_DROP,
ACTION_DROPRECOVER,
2025-04-10 00:04:59 -03:00
ACTION_CLIMB,
2025-04-14 20:33:31 -03:00
ACTION_CLAMBER,
} PlayerAction;
// Alias to make things look less weird
typedef LinecastDirection CollMode;
2025-04-08 20:04:01 -03:00
typedef enum {
PC_DEFAULT,
PC_UNDERWATER,
PC_SPEEDSHOES,
} PlayerConstantType;
// declared in player_constants.c
PlayerConstants *getconstants(PlayerCharacter, PlayerConstantType);
2024-07-21 19:43:49 -03:00
typedef struct {
InputState input;
PlayerConstants *cnst;
Chara chara;
2025-04-07 18:50:55 -03:00
PlayerCharacter character;
2024-07-21 19:43:49 -03:00
CharaAnim *cur_anim;
2025-04-07 18:50:55 -03:00
CharaAnim *tail_cur_anim;
2024-07-21 19:43:49 -03:00
VECTOR pos;
VECTOR vel; // vel.vz = ground speed
int32_t angle;
2024-07-21 19:43:49 -03:00
uint8_t anim_frame;
uint8_t anim_timer;
2025-04-07 18:50:55 -03:00
uint8_t tail_anim_frame;
uint8_t tail_anim_timer;
2024-08-17 13:12:56 -03:00
uint8_t frame_duration;
uint8_t loopback_frame;
2024-07-21 19:43:49 -03:00
int8_t anim_dir;
uint8_t idle_timer;
uint8_t grnd;
uint8_t ceil;
uint8_t push;
2025-04-09 00:19:23 -03:00
uint32_t spinrev; // Also used as flight and glide direction toggle
uint8_t ctrllock;
uint8_t airdirlock;
2025-04-09 21:06:01 -03:00
uint16_t framecount; // Used for many purposes incl. flight and glide
2024-09-08 17:05:05 -03:00
uint8_t holding_jump;
2024-11-03 17:23:11 -03:00
uint16_t iframes;
2024-11-12 19:34:17 -03:00
uint8_t shield;
2024-12-22 01:47:02 -03:00
int32_t speedshoes_frames;
2025-04-09 21:06:01 -03:00
uint8_t underwater;
uint16_t remaining_air_frames;
int8_t glide_turn_dir;
2025-04-10 00:04:59 -03:00
uint8_t sliding;
// Collision modes
CollMode gsmode;
CollMode psmode;
PlayerAction action;
2025-01-07 11:27:45 -03:00
uint8_t col_ledge;
CollisionEvent ev_grnd1;
CollisionEvent ev_grnd2;
CollisionEvent ev_left;
CollisionEvent ev_right;
CollisionEvent ev_ceil1;
CollisionEvent ev_ceil2;
2024-10-11 22:12:58 -03:00
2025-04-14 20:33:31 -03:00
// Collision detectors for Knuckles.
// Used for dropping of the bottom of a wall
// or clambering it up.
CollisionEvent ev_climbdrop;
CollisionEvent ev_clamber;
2024-10-11 22:12:58 -03:00
VECTOR startpos;
VECTOR respawnpos;
2024-07-21 19:43:49 -03:00
} Player;
2025-04-07 18:50:55 -03:00
void load_player(Player *player, PlayerCharacter character, const char *chara_filename, TIM_IMAGE *sprites);
2024-07-21 19:43:49 -03:00
void free_player(Player *player);
void player_set_animation(Player *player, const char *name);
void player_set_animation_precise(Player *player, const char *name);
void player_set_animation_direct(Player *player, uint32_t sum);
2024-08-17 13:12:56 -03:00
void player_set_frame_duration(Player *player, uint8_t duration);
uint32_t player_get_current_animation_hash(Player *player);
2024-07-21 19:43:49 -03:00
CharaAnim *player_get_animation(Player *player, uint32_t sum);
CharaAnim *player_get_animation_by_name(Player *player, const char *name);
void player_set_action(Player *player, PlayerAction action);
2024-07-21 19:43:49 -03:00
void player_update(Player *player);
void player_draw(Player *player, VECTOR *screen_pos);
2024-07-21 19:43:49 -03:00
2024-11-12 19:34:17 -03:00
void player_do_damage(Player *player, int32_t hazard_x);
2024-11-03 17:23:11 -03:00
2024-07-21 19:43:49 -03:00
#endif