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->tumbleLastBounce = players[i].tumbleLastBounce;
rsp->tumbleSound = players[i].tumbleSound; rsp->tumbleSound = players[i].tumbleSound;
rsp->glanceDir = players[i].glanceDir;
// respawnvars_t // respawnvars_t
rsp->respawn_state = players[i].respawn.state; rsp->respawn_state = players[i].respawn.state;
rsp->respawn_pointx = (fixed_t)LONG(players[i].respawn.pointx); 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].tumbleLastBounce = (boolean)rsp->tumbleLastBounce;
players[i].tumbleSound = (boolean)rsp->tumbleSound; players[i].tumbleSound = (boolean)rsp->tumbleSound;
players[i].glanceDir = (SINT8)rsp->glanceDir;
// respawnvars_t // respawnvars_t
players[i].respawn.state = rsp->respawn_state; players[i].respawn.state = rsp->respawn_state;
players[i].respawn.pointx = (fixed_t)LONG(rsp->respawn_pointx); players[i].respawn.pointx = (fixed_t)LONG(rsp->respawn_pointx);

View file

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

View file

@ -569,6 +569,8 @@ typedef struct player_s
boolean tumbleLastBounce; boolean tumbleLastBounce;
boolean tumbleSound; boolean tumbleSound;
SINT8 glanceDir; // Direction the player is trying to look backwards in
// //
UINT32 charflags; // Extra abilities/settings for skins (combinable stuff) 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; ticcmd_t *cmd = &player->cmd;
const boolean spinningwheels = ((cmd->buttons & BT_ACCELERATE) || (onground && player->speed > 0)); const boolean spinningwheels = ((cmd->buttons & BT_ACCELERATE) || (onground && player->speed > 0));
SINT8 destGlanceDir = 0;
if (cmd->turning < -minturn) if (cmd->turning < -minturn)
{ {
turndir = -1; turndir = -1;
@ -1943,27 +1945,46 @@ void K_KartMoveAnimation(player_t *player)
} }
else else
{ {
SINT8 glanceDir = 0;
if (turndir == 0) if (turndir == 0)
{ {
// Only try glancing if you're driving straight. // Only try glancing if you're driving straight.
glanceDir = K_GlanceAtPlayers(player); destGlanceDir = K_GlanceAtPlayers(player);
if (cmd->buttons & BT_LOOKBACK) if (cmd->buttons & BT_LOOKBACK)
{ {
if (glanceDir == 0) if (destGlanceDir == 0)
{ {
// Look to your right by default if (player->glanceDir != 0)
glanceDir = -1; {
// 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 else
{ {
// Looking back AND glancing? Amplify the look! // 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)) if (player->speed >= fastspeed && player->speed >= (player->lastspeed - speedthreshold))
{ {
@ -1979,7 +2000,7 @@ void K_KartMoveAnimation(player_t *player)
} }
else else
{ {
switch (glanceDir) switch (player->glanceDir)
{ {
case -2: case -2:
SetState(S_KART_FAST_LOOK_R); SetState(S_KART_FAST_LOOK_R);
@ -2015,7 +2036,7 @@ void K_KartMoveAnimation(player_t *player)
} }
else else
{ {
switch (glanceDir) switch (player->glanceDir)
{ {
case -2: case -2:
SetState(S_KART_SLOW_LOOK_R); SetState(S_KART_SLOW_LOOK_R);
@ -2049,7 +2070,7 @@ void K_KartMoveAnimation(player_t *player)
} }
else else
{ {
switch (glanceDir) switch (player->glanceDir)
{ {
case -2: case -2:
SetState(S_KART_STILL_LOOK_R); 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); lua_pushboolean(L, plr->tumbleLastBounce);
else if (fastcmp(field,"tumbleSound")) else if (fastcmp(field,"tumbleSound"))
lua_pushboolean(L, plr->tumbleSound); lua_pushboolean(L, plr->tumbleSound);
else if (fastcmp(field,"glanceDir"))
lua_pushinteger(L, plr->glanceDir);
else if (fastcmp(field,"trickpanel")) else if (fastcmp(field,"trickpanel"))
lua_pushinteger(L, plr->trickpanel); lua_pushinteger(L, plr->trickpanel);
else if (fastcmp(field,"trickdelay")) else if (fastcmp(field,"trickdelay"))
@ -529,6 +531,8 @@ static int player_set(lua_State *L)
plr->tumbleLastBounce = luaL_checkboolean(L, 3); plr->tumbleLastBounce = luaL_checkboolean(L, 3);
else if (fastcmp(field,"tumbleSound")) else if (fastcmp(field,"tumbleSound"))
plr->tumbleSound = luaL_checkboolean(L, 3); plr->tumbleSound = luaL_checkboolean(L, 3);
else if (fastcmp(field,"glanceDir"))
plr->glanceDir = (SINT8)luaL_checkinteger(L, 3);
else if (fastcmp(field,"trickpanel")) else if (fastcmp(field,"trickpanel"))
plr->trickpanel = luaL_checkinteger(L, 3); plr->trickpanel = luaL_checkinteger(L, 3);
else if (fastcmp(field,"trickdelay")) 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].tumbleLastBounce);
WRITEUINT8(save_p, players[i].tumbleSound); WRITEUINT8(save_p, players[i].tumbleSound);
WRITESINT8(save_p, players[i].glanceDir);
// respawnvars_t // respawnvars_t
WRITEUINT8(save_p, players[i].respawn.state); WRITEUINT8(save_p, players[i].respawn.state);
WRITEUINT32(save_p, K_GetWaypointHeapIndex(players[i].respawn.wp)); 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].tumbleLastBounce = (boolean)READUINT8(save_p);
players[i].tumbleSound = (boolean)READUINT8(save_p); players[i].tumbleSound = (boolean)READUINT8(save_p);
players[i].glanceDir = READSINT8(save_p);
// respawnvars_t // respawnvars_t
players[i].respawn.state = READUINT8(save_p); players[i].respawn.state = READUINT8(save_p);
players[i].respawn.wp = (waypoint_t *)(size_t)READUINT32(save_p); players[i].respawn.wp = (waypoint_t *)(size_t)READUINT32(save_p);