Keep look backwards direction in a variable, so it can smoothly rotate

This commit is contained in:
Sally Coolatta 2021-02-04 00:26:59 -05:00
parent e2e342f3f7
commit b7e578b82b
6 changed files with 57 additions and 10 deletions

View file

@ -631,6 +631,8 @@ static inline void resynch_write_player(resynch_pak *rsp, const size_t i)
rsp->tumbleLastBounce = players[i].tumbleLastBounce;
rsp->tumbleSound = players[i].tumbleSound;
rsp->glanceDir = players[i].glanceDir;
// respawnvars_t
rsp->respawn_state = players[i].respawn.state;
rsp->respawn_pointx = (fixed_t)LONG(players[i].respawn.pointx);
@ -789,6 +791,8 @@ static void resynch_read_player(resynch_pak *rsp)
players[i].tumbleLastBounce = (boolean)rsp->tumbleLastBounce;
players[i].tumbleSound = (boolean)rsp->tumbleSound;
players[i].glanceDir = (SINT8)rsp->glanceDir;
// respawnvars_t
players[i].respawn.state = rsp->respawn_state;
players[i].respawn.pointx = (fixed_t)LONG(rsp->respawn_pointx);

View file

@ -295,6 +295,8 @@ typedef struct
boolean tumbleLastBounce;
boolean tumbleSound;
SINT8 glanceDir;
// respawnvars_t
UINT8 respawn_state;
fixed_t respawn_pointx;

View file

@ -569,6 +569,8 @@ typedef struct player_s
boolean tumbleLastBounce;
boolean tumbleSound;
SINT8 glanceDir; // Direction the player is trying to look backwards in
//
UINT32 charflags; // Extra abilities/settings for skins (combinable stuff)

View file

@ -1849,6 +1849,8 @@ void K_KartMoveAnimation(player_t *player)
ticcmd_t *cmd = &player->cmd;
const boolean spinningwheels = ((cmd->buttons & BT_ACCELERATE) || (onground && player->speed > 0));
SINT8 destGlanceDir = 0;
if (cmd->turning < -minturn)
{
turndir = -1;
@ -1943,27 +1945,46 @@ void K_KartMoveAnimation(player_t *player)
}
else
{
SINT8 glanceDir = 0;
if (turndir == 0)
{
// Only try glancing if you're driving straight.
glanceDir = K_GlanceAtPlayers(player);
destGlanceDir = K_GlanceAtPlayers(player);
if (cmd->buttons & BT_LOOKBACK)
{
if (glanceDir == 0)
if (destGlanceDir == 0)
{
// Look to your right by default
glanceDir = -1;
if (player->glanceDir != 0)
{
// Keep to the side you were already on.
if (player->glanceDir < 0)
{
destGlanceDir = -1;
}
else
{
destGlanceDir = 1;
}
}
else
{
// Look to your right by default
destGlanceDir = -1;
}
}
else
{
// Looking back AND glancing? Amplify the look!
glanceDir *= 2;
destGlanceDir *= 2;
}
}
}
else
{
// Not glancing
destGlanceDir = 0;
player->glanceDir = 0;
}
if (player->speed >= fastspeed && player->speed >= (player->lastspeed - speedthreshold))
{
@ -1979,7 +2000,7 @@ void K_KartMoveAnimation(player_t *player)
}
else
{
switch (glanceDir)
switch (player->glanceDir)
{
case -2:
SetState(S_KART_FAST_LOOK_R);
@ -2015,7 +2036,7 @@ void K_KartMoveAnimation(player_t *player)
}
else
{
switch (glanceDir)
switch (player->glanceDir)
{
case -2:
SetState(S_KART_SLOW_LOOK_R);
@ -2049,7 +2070,7 @@ void K_KartMoveAnimation(player_t *player)
}
else
{
switch (glanceDir)
switch (player->glanceDir)
{
case -2:
SetState(S_KART_STILL_LOOK_R);
@ -2070,6 +2091,16 @@ void K_KartMoveAnimation(player_t *player)
}
}
}
// Update your value to smooth it out.
if (player->glanceDir > destGlanceDir)
{
player->glanceDir--;
}
else if (player->glanceDir < destGlanceDir)
{
player->glanceDir++;
}
}
}

View file

@ -222,6 +222,8 @@ static int player_get(lua_State *L)
lua_pushboolean(L, plr->tumbleLastBounce);
else if (fastcmp(field,"tumbleSound"))
lua_pushboolean(L, plr->tumbleSound);
else if (fastcmp(field,"glanceDir"))
lua_pushinteger(L, plr->glanceDir);
else if (fastcmp(field,"trickpanel"))
lua_pushinteger(L, plr->trickpanel);
else if (fastcmp(field,"trickdelay"))
@ -529,6 +531,8 @@ static int player_set(lua_State *L)
plr->tumbleLastBounce = luaL_checkboolean(L, 3);
else if (fastcmp(field,"tumbleSound"))
plr->tumbleSound = luaL_checkboolean(L, 3);
else if (fastcmp(field,"glanceDir"))
plr->glanceDir = (SINT8)luaL_checkinteger(L, 3);
else if (fastcmp(field,"trickpanel"))
plr->trickpanel = luaL_checkinteger(L, 3);
else if (fastcmp(field,"trickdelay"))

View file

@ -271,6 +271,8 @@ static void P_NetArchivePlayers(void)
WRITEUINT8(save_p, players[i].tumbleLastBounce);
WRITEUINT8(save_p, players[i].tumbleSound);
WRITESINT8(save_p, players[i].glanceDir);
// respawnvars_t
WRITEUINT8(save_p, players[i].respawn.state);
WRITEUINT32(save_p, K_GetWaypointHeapIndex(players[i].respawn.wp));
@ -471,6 +473,8 @@ static void P_NetUnArchivePlayers(void)
players[i].tumbleLastBounce = (boolean)READUINT8(save_p);
players[i].tumbleSound = (boolean)READUINT8(save_p);
players[i].glanceDir = READSINT8(save_p);
// respawnvars_t
players[i].respawn.state = READUINT8(save_p);
players[i].respawn.wp = (waypoint_t *)(size_t)READUINT32(save_p);