mirror of
https://github.com/luksamuk/engine-psx.git
synced 2025-04-28 13:28:02 +03:00
Add Miles' flight and swim
This commit is contained in:
parent
6271d5e741
commit
135d6fb431
3 changed files with 75 additions and 9 deletions
|
@ -17,6 +17,7 @@
|
||||||
#define PUSH_RADIUS 10
|
#define PUSH_RADIUS 10
|
||||||
|
|
||||||
#define PLAYER_HURT_IFRAMES 120
|
#define PLAYER_HURT_IFRAMES 120
|
||||||
|
#define PLAYER_FLY_MAXFRAMES 480
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CHARA_SONIC = 0,
|
CHARA_SONIC = 0,
|
||||||
|
@ -39,6 +40,7 @@ typedef enum {
|
||||||
ACTION_SPRING,
|
ACTION_SPRING,
|
||||||
ACTION_HURT,
|
ACTION_HURT,
|
||||||
ACTION_GASP,
|
ACTION_GASP,
|
||||||
|
ACTION_FLY,
|
||||||
} PlayerAction;
|
} PlayerAction;
|
||||||
|
|
||||||
// Alias to make things look less weird
|
// Alias to make things look less weird
|
||||||
|
@ -75,10 +77,10 @@ typedef struct {
|
||||||
uint8_t grnd;
|
uint8_t grnd;
|
||||||
uint8_t ceil;
|
uint8_t ceil;
|
||||||
uint8_t push;
|
uint8_t push;
|
||||||
uint32_t spinrev;
|
uint32_t spinrev; // Also used as flight and glide direction toggle
|
||||||
uint8_t ctrllock;
|
uint8_t ctrllock;
|
||||||
uint8_t airdirlock;
|
uint8_t airdirlock;
|
||||||
uint8_t framecount;
|
uint16_t framecount;
|
||||||
uint8_t holding_jump;
|
uint8_t holding_jump;
|
||||||
uint16_t iframes;
|
uint16_t iframes;
|
||||||
uint8_t shield;
|
uint8_t shield;
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define MILES_GRAVITY_FLYDOWN 0x00000080
|
||||||
|
#define MILES_GRAVITY_FLYUP 0x00000200 // Fly up by SUBTRACTING this gravity
|
||||||
|
|
||||||
// Constants for running the game at a fixed 60 FPS.
|
// Constants for running the game at a fixed 60 FPS.
|
||||||
// These constants are also in a 12-scale format for fixed point math.
|
// These constants are also in a 12-scale format for fixed point math.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
75
src/player.c
75
src/player.c
|
@ -225,15 +225,28 @@ _player_set_tail_animation(Player *player, uint32_t anim_sum)
|
||||||
case ANIM_IDLE:
|
case ANIM_IDLE:
|
||||||
case ANIM_CROUCHDOWN:
|
case ANIM_CROUCHDOWN:
|
||||||
case ANIM_LOOKUP:
|
case ANIM_LOOKUP:
|
||||||
tail_sum = ANIM_TAILIDLE; // Fallthrough
|
tail_sum = ANIM_TAILIDLE;
|
||||||
|
tail_anim = player_get_animation(player, tail_sum);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Animations where the tail is a buttcopter */
|
||||||
|
case ANIM_FLYUP:
|
||||||
|
case ANIM_FLYDOWN:
|
||||||
|
case ANIM_FLYTIRED:
|
||||||
|
tail_sum = ANIM_TAILFLY;
|
||||||
|
tail_anim = player_get_animation(player, tail_sum);
|
||||||
|
break;
|
||||||
|
|
||||||
/* Animations where the tail is sideways */
|
/* Animations where the tail is sideways */
|
||||||
case ANIM_WALKING:
|
case ANIM_WALKING:
|
||||||
case ANIM_ROLLING:
|
case ANIM_ROLLING:
|
||||||
case ANIM_SPINDASH:
|
case ANIM_SPINDASH:
|
||||||
case ANIM_SKIDDING:
|
case ANIM_SKIDDING:
|
||||||
case ANIM_PUSHING:
|
case ANIM_PUSHING:
|
||||||
|
tail_sum = ANIM_TAILMOVE; // (Redundant failsafe)
|
||||||
tail_anim = player_get_animation(player, tail_sum);
|
tail_anim = player_get_animation(player, tail_sum);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Any animation not described implies on not showing the tail */
|
/* Any animation not described implies on not showing the tail */
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
@ -1030,22 +1043,58 @@ player_update(Player *player)
|
||||||
player->vel.vy = -player->cnst->y_min_jump;
|
player->vel.vy = -player->cnst->y_min_jump;
|
||||||
player->holding_jump = 0;
|
player->holding_jump = 0;
|
||||||
} else {
|
} else {
|
||||||
if(player->character == CHARA_SONIC) {
|
if(!player->holding_jump) {
|
||||||
// Drop dash charge wait
|
switch(player->character) {
|
||||||
if(!player->holding_jump) {
|
case CHARA_SONIC:
|
||||||
|
// Drop dash charge wait
|
||||||
if(player->framecount < 20) {
|
if(player->framecount < 20) {
|
||||||
player->framecount++;
|
player->framecount++;
|
||||||
} else {
|
} else {
|
||||||
sound_play_vag(sfx_dropd, 0);
|
sound_play_vag(sfx_dropd, 0);
|
||||||
player_set_action(player, ACTION_DROPDASH);
|
player_set_action(player, ACTION_DROPDASH);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case CHARA_MILES:
|
||||||
|
player_set_action(player, ACTION_FLY);
|
||||||
|
player->spinrev = 0; // Do not move up for first time
|
||||||
|
player->framecount = 0; // Start counter for tiredness
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if(player->action == ACTION_FLY) {
|
||||||
|
if(player->framecount < PLAYER_FLY_MAXFRAMES) {
|
||||||
|
player->framecount++;
|
||||||
|
|
||||||
|
// spinrev is a flight state. 1 is ascent, 0 is descent.
|
||||||
|
// This state affects gravity, so we're OK with the speed here
|
||||||
|
if(input_pressed(&player->input, PAD_CROSS)) {
|
||||||
|
player->spinrev = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ceiling collision
|
||||||
|
if(player->ceil) player->spinrev = 0;
|
||||||
|
}
|
||||||
|
// if ascending and ysp < -1, turn on descent again
|
||||||
|
if(player->spinrev && (player->vel.vy < -ONE))
|
||||||
|
player->spinrev = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply gravity
|
||||||
|
switch(player->action) {
|
||||||
|
case ACTION_HURT:
|
||||||
|
player->vel.vy += player->cnst->y_hurt_gravity;
|
||||||
|
break;
|
||||||
|
case ACTION_FLY:
|
||||||
|
// Flying up (spinrev > 0) uses negative gravity
|
||||||
|
if(player->spinrev) player->vel.vy -= MILES_GRAVITY_FLYUP;
|
||||||
|
else player->vel.vy += MILES_GRAVITY_FLYDOWN;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
player->vel.vy += player->cnst->y_gravity;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
player->vel.vy += (player->action == ACTION_HURT)
|
|
||||||
? player->cnst->y_hurt_gravity
|
|
||||||
: player->cnst->y_gravity;
|
|
||||||
} else {
|
} else {
|
||||||
if(input_pressed(&player->input, PAD_CROSS)
|
if(input_pressed(&player->input, PAD_CROSS)
|
||||||
&& (player->action != ACTION_SPINDASH)
|
&& (player->action != ACTION_SPINDASH)
|
||||||
|
@ -1146,6 +1195,18 @@ player_update(Player *player)
|
||||||
}
|
}
|
||||||
} else if(player->action == ACTION_HURT) {
|
} else if(player->action == ACTION_HURT) {
|
||||||
player_set_animation_direct(player, ANIM_HURT);
|
player_set_animation_direct(player, ANIM_HURT);
|
||||||
|
} else if(player->action == ACTION_FLY) {
|
||||||
|
if(player->framecount >= PLAYER_FLY_MAXFRAMES)
|
||||||
|
player_set_animation_direct(
|
||||||
|
player,
|
||||||
|
(player->underwater ? ANIM_SWIMTIRED : ANIM_FLYTIRED));
|
||||||
|
else player_set_animation_direct(
|
||||||
|
player,
|
||||||
|
player->underwater
|
||||||
|
? ANIM_SWIMMING
|
||||||
|
: ((player->spinrev) || (player->vel.vy < 0)
|
||||||
|
? ANIM_FLYUP
|
||||||
|
: ANIM_FLYDOWN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue