Reset state when bouncing

This commit is contained in:
Sally Coolatta 2022-05-31 21:53:19 -04:00
parent c3bb2c8539
commit 3164199512
2 changed files with 67 additions and 64 deletions

View file

@ -129,7 +129,6 @@ void K_SetFollowerByNum(INT32 playernum, INT32 skinnum)
K_SetFollowerByNum(playernum, -1); // Not found, then set -1 (nothing) as our follower.
}
/*--------------------------------------------------
static void K_SetFollowerState(mobj_t *f, statenum_t state)
@ -176,6 +175,35 @@ static void K_SetFollowerState(mobj_t *f, statenum_t state)
}
}
/*--------------------------------------------------
static void K_UpdateFollowerState(mobj_t *f, statenum_t state, followerstate_t type)
Sets a follower object's state & current state type tracker.
If the state tracker already matches, then this is ignored.
Input Arguments:-
f - The follower's mobj_t.
state - The state to set.
type - State type tracker.
Return:-
None
--------------------------------------------------*/
static void K_UpdateFollowerState(mobj_t *f, statenum_t state, followerstate_t type)
{
if (f == NULL || P_MobjWasRemoved(f) == true)
{
// safety net
return;
}
if (f->extravalue1 != (INT32)type)
{
K_SetFollowerState(f, state);
f->extravalue1 = type;
}
}
/*--------------------------------------------------
void K_HandleFollower(player_t *player)
@ -299,8 +327,9 @@ void K_HandleFollower(player_t *player)
// so let's spawn one!
P_SetTarget(&player->follower, P_SpawnMobj(sx, sy, sz, MT_FOLLOWER));
K_SetFollowerState(player->follower, fl.idlestate);
P_SetTarget(&player->follower->target, player->mo); // we need that to know when we need to disappear
K_UpdateFollowerState(player->follower, fl.idlestate, FOLLOWERSTATE_IDLE);
P_SetTarget(&player->follower->target, player->mo); // we need that to know when we need to disappear
P_InitAngle(player->follower, player->mo->angle);
// This is safe to only spawn it here, the follower is removed then respawned when switched.
@ -314,16 +343,6 @@ void K_HandleFollower(player_t *player)
P_SetTarget(&player->follower->hnext->hnext, bmobj); // this seems absolutely stupid, I know, but this will make updating the momentums/flags of these a bit easier.
P_SetTarget(&bmobj->target, player->follower); // Ditto
}
player->follower->extravalue1 = 0; // extravalue1 is used to know what "state set" to use.
/*
0 = idle
1 = forwards
2 = hurt
3 = win
4 = lose
5 = hitconfirm (< this one uses ->movecount as timer to know when to end, and goes back to normal states afterwards, unless hurt)
*/
}
else // follower exists, woo!
{
@ -431,10 +450,11 @@ void K_HandleFollower(player_t *player)
{
player->follower->z = fh;
if (!(player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz <= 0)
if (!(player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz <= 0 && fl.bobamp != 0)
{
// Ground bounce
player->follower->momz = P_GetMobjZMovement(player->mo) + FixedMul(fl.bobamp, player->follower->scale);
player->follower->extravalue1 = FOLLOWERSTATE_RESET;
}
else if (player->follower->momz < 0)
{
@ -446,10 +466,11 @@ void K_HandleFollower(player_t *player)
{
player->follower->z = ch;
if ((player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz >= 0)
if ((player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz >= 0 && fl.bobamp != 0)
{
// Ground bounce
player->follower->momz = P_GetMobjZMovement(player->mo) - FixedMul(fl.bobamp, player->follower->scale);
player->follower->extravalue1 = FOLLOWERSTATE_RESET;
}
else if (player->follower->momz > 0)
{
@ -512,11 +533,7 @@ void K_HandleFollower(player_t *player)
// spin out
player->follower->angle = player->drawangle;
if (player->follower->extravalue1 != 2)
{
player->follower->extravalue1 = 2;
K_SetFollowerState(player->follower, fl.hurtstate);
}
K_UpdateFollowerState(player->follower, fl.hurtstate, FOLLOWERSTATE_HURT);
if (player->mo->health <= 0)
{
@ -524,58 +541,32 @@ void K_HandleFollower(player_t *player)
player->follower->momz = player->mo->momz;
}
}
else if (player->exiting)
{
// win/ loss animations
if (K_IsPlayerLosing(player))
{
// L
K_UpdateFollowerState(player->follower, fl.losestate, FOLLOWERSTATE_LOSE);
}
else
{
// W
K_UpdateFollowerState(player->follower, fl.winstate, FOLLOWERSTATE_WIN);
}
}
else if (player->follower->movecount)
{
if (player->follower->extravalue1 != 5)
{
player->follower->extravalue1 = 5;
K_SetFollowerState(player->follower, fl.hitconfirmstate);
}
K_UpdateFollowerState(player->follower, fl.hitconfirmstate, FOLLOWERSTATE_HITCONFIRM);
player->follower->movecount--;
}
else if (player->speed > 10*player->mo->scale) // animation for moving fast enough
else if (player->speed > 10*player->mo->scale) // animation for moving fast enough
{
if (player->follower->extravalue1 != 1)
{
player->follower->extravalue1 = 1;
K_SetFollowerState(player->follower, fl.followstate);
}
K_UpdateFollowerState(player->follower, fl.followstate, FOLLOWERSTATE_FOLLOW);
}
else
{
// animations when nearly still. This includes winning and losing.
if (player->follower->extravalue1 != 0)
{
if (player->exiting)
{
// win/ loss animations
if (K_IsPlayerLosing(player))
{
// L
if (player->follower->extravalue1 != 4)
{
player->follower->extravalue1 = 4;
K_SetFollowerState(player->follower, fl.losestate);
}
}
else
{
// W
if (player->follower->extravalue1 != 3)
{
player->follower->extravalue1 = 3;
K_SetFollowerState(player->follower, fl.winstate);
}
}
}
else
{
// normal standstill
player->follower->extravalue1 = 0;
K_SetFollowerState(player->follower, fl.idlestate);
}
}
K_UpdateFollowerState(player->follower, fl.idlestate, FOLLOWERSTATE_IDLE);
}
}
}

View file

@ -29,6 +29,18 @@ typedef enum
FOLLOWERMODE__MAX
} followermode_t;
typedef enum
{
FOLLOWERSTATE_RESET, // Set to this to reset the state entirely.
FOLLOWERSTATE_IDLE,
FOLLOWERSTATE_FOLLOW,
FOLLOWERSTATE_HURT,
FOLLOWERSTATE_WIN,
FOLLOWERSTATE_LOSE,
FOLLOWERSTATE_HITCONFIRM, // Uses movecount as a timer for how long to play this state.
FOLLOWERSTATE__MAX
} followerstate_t;
//
// We'll define these here because they're really just a mobj that'll follow some rules behind a player
//