Squash and stretch player sprite with sudden changes in vertical momentum

Stretch with a sudden increase of
momentum, squash with a decrease.
This commit is contained in:
James R 2021-04-10 19:37:20 -07:00
parent a77ed63c5f
commit 661d8818d6
3 changed files with 39 additions and 0 deletions

View file

@ -597,6 +597,7 @@ typedef struct player_s
fixed_t speed; // Player's speed (distance formula of MOMX and MOMY values)
fixed_t lastspeed;
fixed_t lastmomz;
UINT8 secondjump; // Jump counter
UINT8 fly1; // Tails flying

View file

@ -2288,6 +2288,7 @@ void K_KartMoveAnimation(player_t *player)
// Update lastspeed value -- we use to display slow driving frames instead of fast driving when slowing down.
player->lastspeed = player->speed;
player->lastmomz = player->mo->momz;
}
static void K_TauntVoiceTimers(player_t *player)

View file

@ -1845,6 +1845,41 @@ static void P_DoBubbleBreath(player_t *player)
}
}
static void squish(player_t *player)
{
const fixed_t maxstretch = 2*FRACUNIT;
const fixed_t factor = 3 * player->mo->height / 2;
const fixed_t threshold = factor / 6;
const fixed_t old3dspeed = abs(player->lastmomz);
const fixed_t new3dspeed = abs(player->mo->momz);
const fixed_t delta = abs(old3dspeed - new3dspeed);
if (delta > threshold)
{
player->mo->spritexscale =
FRACUNIT + FixedDiv(delta, factor);
if (player->mo->spritexscale > maxstretch)
player->mo->spritexscale = maxstretch;
if (abs(new3dspeed) > abs(old3dspeed))
{
player->mo->spritexscale =
FixedDiv(FRACUNIT, player->mo->spritexscale);
}
}
else
{
player->mo->spritexscale -=
(player->mo->spritexscale - FRACUNIT) / 8;
}
player->mo->spriteyscale =
FixedDiv(FRACUNIT, player->mo->spritexscale);
}
//#define OLD_MOVEMENT_CODE 1
static void P_3dMovement(player_t *player)
{
@ -2031,6 +2066,8 @@ static void P_3dMovement(player_t *player)
}
}
}
squish(player);
}
//