2024-07-21 19:43:49 -03:00
|
|
|
#ifndef PLAYER_H
|
|
|
|
#define PLAYER_H
|
|
|
|
|
|
|
|
#include "chara.h"
|
|
|
|
#include <psxgte.h>
|
2024-08-04 18:36:59 -03:00
|
|
|
#include "level.h"
|
2024-08-16 01:11:53 -03:00
|
|
|
#include "collision.h"
|
2024-11-23 01:00:17 -03:00
|
|
|
#include "input.h"
|
2024-12-21 21:57:40 -03:00
|
|
|
#include "player_constants.h"
|
2024-07-21 19:43:49 -03:00
|
|
|
|
2024-08-25 14:28:00 -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
|
2025-01-07 12:42:31 -03:00
|
|
|
#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
|
|
|
|
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
|
|
|
|
2024-08-19 01:05:12 -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,
|
2024-08-26 23:42:07 -03:00
|
|
|
ACTION_ROLLING,
|
2024-09-08 17:05:05 -03:00
|
|
|
ACTION_SPINDASH,
|
2025-02-18 13:43:04 -03:00
|
|
|
ACTION_PEELOUT,
|
2024-11-03 01:46:09 -03:00
|
|
|
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-09 00:19:23 -03:00
|
|
|
ACTION_FLY,
|
2024-08-19 01:05:12 -03:00
|
|
|
} PlayerAction;
|
|
|
|
|
2024-11-28 01:36:09 -03:00
|
|
|
// 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 {
|
2024-12-21 21:57:40 -03:00
|
|
|
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;
|
2024-08-02 21:10:58 -03:00
|
|
|
VECTOR vel; // vel.vz = ground speed
|
2024-08-05 00:12:44 -03:00
|
|
|
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;
|
2024-08-17 13:19:27 -03:00
|
|
|
uint8_t loopback_frame;
|
2024-07-21 19:43:49 -03:00
|
|
|
int8_t anim_dir;
|
|
|
|
uint8_t idle_timer;
|
|
|
|
uint8_t grnd;
|
2025-04-08 22:54:13 -03:00
|
|
|
uint8_t ceil;
|
2024-08-05 00:12:44 -03:00
|
|
|
uint8_t push;
|
2025-04-09 00:19:23 -03:00
|
|
|
uint32_t spinrev; // Also used as flight and glide direction toggle
|
2024-08-27 02:01:33 -03:00
|
|
|
uint8_t ctrllock;
|
2024-11-03 01:46:09 -03:00
|
|
|
uint8_t airdirlock;
|
2025-04-09 00:19:23 -03:00
|
|
|
uint16_t framecount;
|
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;
|
2024-08-04 18:36:59 -03:00
|
|
|
|
2024-12-19 01:50:49 -03:00
|
|
|
// TODO: Change this to player value modes.
|
|
|
|
// For now we're only storing info on whether
|
|
|
|
// player is underwater
|
2024-12-21 01:15:11 -03:00
|
|
|
uint8_t underwater;
|
|
|
|
uint16_t remaining_air_frames;
|
2024-12-19 01:50:49 -03:00
|
|
|
|
2024-11-28 01:36:09 -03:00
|
|
|
// Collision modes
|
|
|
|
CollMode gsmode;
|
|
|
|
CollMode psmode;
|
|
|
|
|
2024-08-19 01:05:12 -03:00
|
|
|
PlayerAction action;
|
|
|
|
|
2025-01-07 11:27:45 -03:00
|
|
|
uint8_t col_ledge;
|
2024-08-04 18:36:59 -03:00
|
|
|
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
|
|
|
|
|
|
|
VECTOR startpos;
|
2025-01-07 23:58:52 -03:00
|
|
|
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);
|
2024-08-17 11:01:01 -03:00
|
|
|
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);
|
2025-02-09 16:13:34 -03:00
|
|
|
void player_set_action(Player *player, PlayerAction action);
|
2024-07-21 19:43:49 -03:00
|
|
|
|
|
|
|
void player_update(Player *player);
|
2024-08-02 21:10:58 -03:00
|
|
|
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
|