Glance frames

When someone is about to pass you, you'll take a glance at 'em!
This commit is contained in:
Sally Coolatta 2021-02-03 01:24:00 -05:00
parent c178ca6c1a
commit bea2724a86
4 changed files with 171 additions and 9 deletions

View file

@ -5204,12 +5204,18 @@ static const char *const STATE_LIST[] = { // array length left dynamic for sanit
"S_KART_STILL",
"S_KART_STILL_L",
"S_KART_STILL_R",
"S_KART_STILL_GLANCE_L",
"S_KART_STILL_GLANCE_R",
"S_KART_SLOW",
"S_KART_SLOW_L",
"S_KART_SLOW_R",
"S_KART_SLOW_GLANCE_L",
"S_KART_SLOW_GLANCE_R",
"S_KART_FAST",
"S_KART_FAST_L",
"S_KART_FAST_R",
"S_KART_FAST_GLANCE_L",
"S_KART_FAST_GLANCE_R",
"S_KART_DRIFT_L",
"S_KART_DRIFT_L_OUT",
"S_KART_DRIFT_L_IN",

View file

@ -749,9 +749,9 @@ char sprnames[NUMSPRITES + 1][5] =
char spr2names[NUMPLAYERSPRITES][5] =
{
"STIN", "STIL", "STIR", // Still
"SLWN", "SLWL", "SLWR", // Slow driving
"FSTN", "FSTL", "FSTR", // Fast driving
"STIN", "STIL", "STIR", "STGL", "STGR", // Still
"SLWN", "SLWL", "SLWR", "SLGL", "SLGR", // Slow driving
"FSTN", "FSTL", "FSTR", "FSGL", "FSGR", // Fast driving
"DRLN", "DRLO", "DRLI", // Drifting left
"DRRN", "DRRO", "DRRI", // Drifting right
"SPIN", // Spinout
@ -765,14 +765,20 @@ playersprite_t spr2defaults[NUMPLAYERSPRITES] = {
0, // SPR2_STIN
SPR2_STIN, // SPR2_STIL
SPR2_STIN, // SPR2_STIR
SPR2_STIN, // SPR2_STGL
SPR2_STIN, // SPR2_STGR
0, // SPR2_SLWN
SPR2_SLWN, // SPR2_SLWL
SPR2_SLWN, // SPR2_SLWR
SPR2_SLWN, // SPR2_SLGL
SPR2_SLWN, // SPR2_SLGR
0, // SPR2_FSTN
SPR2_FSTN, // SPR2_FSTL
SPR2_FSTN, // SPR2_FSTR
SPR2_FSTN, // SPR2_FSGL
SPR2_FSTN, // SPR2_FSGR
0, // SPR2_DRLN
SPR2_DRLN, // SPR2_DRLO
@ -786,6 +792,7 @@ playersprite_t spr2defaults[NUMPLAYERSPRITES] = {
0, // SPR2_DEAD
0, // SPR2_SIGN
0, // SPR2_XTRA
};
// Doesn't work with g++, needs actionf_p1 (don't modify this comment)
@ -816,12 +823,18 @@ state_t states[NUMSTATES] =
{SPR_PLAY, SPR2_STIN, 1, {NULL}, 0, 0, S_KART_STILL}, // S_KART_STILL
{SPR_PLAY, SPR2_STIL, 1, {NULL}, 0, 0, S_KART_STILL_L}, // S_KART_STILL_L
{SPR_PLAY, SPR2_STIR, 1, {NULL}, 0, 0, S_KART_STILL_R}, // S_KART_STILL_R
{SPR_PLAY, SPR2_STGL, 1, {NULL}, 0, 0, S_KART_STILL_GLANCE_L}, // S_KART_STILL_GLANCE_L
{SPR_PLAY, SPR2_STGR, 1, {NULL}, 0, 0, S_KART_STILL_GLANCE_R}, // S_KART_STILL_GLANCE_R
{SPR_PLAY, SPR2_SLWN, 1, {NULL}, 0, 0, S_KART_SLOW}, // S_KART_SLOW
{SPR_PLAY, SPR2_SLWL, 1, {NULL}, 0, 0, S_KART_SLOW_L}, // S_KART_SLOW_L
{SPR_PLAY, SPR2_SLWR, 1, {NULL}, 0, 0, S_KART_SLOW_R}, // S_KART_SLOW_R
{SPR_PLAY, SPR2_SLGL, 1, {NULL}, 0, 0, S_KART_SLOW_GLANCE_L}, // S_KART_SLOW_GLANCE_L
{SPR_PLAY, SPR2_SLGR, 1, {NULL}, 0, 0, S_KART_SLOW_GLANCE_R}, // S_KART_SLOW_GLANCE_R
{SPR_PLAY, SPR2_FSTN, 1, {NULL}, 0, 0, S_KART_FAST}, // S_KART_FAST
{SPR_PLAY, SPR2_FSTL, 1, {NULL}, 0, 0, S_KART_FAST_L}, // S_KART_FAST_L
{SPR_PLAY, SPR2_FSTR, 1, {NULL}, 0, 0, S_KART_FAST_R}, // S_KART_FAST_R
{SPR_PLAY, SPR2_FSGL, 1, {NULL}, 0, 0, S_KART_FAST_GLANCE_L}, // S_KART_FAST_GLANCE_L
{SPR_PLAY, SPR2_FSGR, 1, {NULL}, 0, 0, S_KART_FAST_GLANCE_R}, // S_KART_FAST_GLANCE_R
{SPR_PLAY, SPR2_DRLN, 1, {NULL}, 0, 0, S_KART_DRIFT_L}, // S_KART_DRIFT_L
{SPR_PLAY, SPR2_DRLO, 1, {NULL}, 0, 0, S_KART_DRIFT_L_OUT}, // S_KART_DRIFT_L_OUT
{SPR_PLAY, SPR2_DRLI, 1, {NULL}, 0, 0, S_KART_DRIFT_L_IN}, // S_KART_DRIFT_L_IN

View file

@ -1027,9 +1027,9 @@ typedef enum sprite
// Since this is zero-based, there can be at most 128 different SPR2_'s without changing that.
typedef enum playersprite
{
SPR2_STIN = 0, SPR2_STIL, SPR2_STIR,
SPR2_SLWN, SPR2_SLWL, SPR2_SLWR,
SPR2_FSTN, SPR2_FSTL, SPR2_FSTR,
SPR2_STIN = 0, SPR2_STIL, SPR2_STIR, SPR2_STGL, SPR2_STGR,
SPR2_SLWN, SPR2_SLWL, SPR2_SLWR, SPR2_SLGL, SPR2_SLGR,
SPR2_FSTN, SPR2_FSTL, SPR2_FSTR, SPR2_FSGL, SPR2_FSGR,
SPR2_DRLN, SPR2_DRLO, SPR2_DRLI,
SPR2_DRRN, SPR2_DRRO, SPR2_DRRI,
SPR2_SPIN,
@ -1061,12 +1061,18 @@ typedef enum state
S_KART_STILL,
S_KART_STILL_L,
S_KART_STILL_R,
S_KART_STILL_GLANCE_L,
S_KART_STILL_GLANCE_R,
S_KART_SLOW,
S_KART_SLOW_L,
S_KART_SLOW_R,
S_KART_SLOW_GLANCE_L,
S_KART_SLOW_GLANCE_R,
S_KART_FAST,
S_KART_FAST_L,
S_KART_FAST_R,
S_KART_FAST_GLANCE_L,
S_KART_FAST_GLANCE_R,
S_KART_DRIFT_L,
S_KART_DRIFT_L_OUT,
S_KART_DRIFT_L_IN,

View file

@ -1734,6 +1734,102 @@ void K_SpawnDriftBoostClipSpark(mobj_t *clip)
spark->momy = clip->momx/2;
}
static SINT8 K_GlanceAtPlayers(player_t *glancePlayer)
{
const fixed_t maxdistance = FixedMul(1280 * mapobjectscale, K_GetKartGameSpeedScalar(gamespeed));
const angle_t blindSpotSize = ANG10; // ANG5
UINT8 i;
SINT8 glanceDir = 0;
SINT8 lastValidGlance = 0;
// See if there's any players coming up behind us.
// If so, your character will glance at 'em.
for (i = 0; i < MAXPLAYERS; i++)
{
player_t *p;
angle_t back;
angle_t diff;
fixed_t distance;
SINT8 dir = -1;
if (!playeringame[i])
{
// Invalid player
continue;
}
p = &players[i];
if (p == glancePlayer)
{
// FOOL! Don't glance at yerself!
continue;
}
if (!p->mo || P_MobjWasRemoved(p->mo))
{
// Invalid mobj
continue;
}
if (p->spectator || p->kartstuff[k_hyudorotimer] > 0)
{
// Not playing / invisible
continue;
}
distance = R_PointToDist2(glancePlayer->mo->x, glancePlayer->mo->y, p->mo->x, p->mo->y);
if (distance > maxdistance)
{
continue;
}
back = glancePlayer->mo->angle + ANGLE_180;
diff = R_PointToAngle2(glancePlayer->mo->x, glancePlayer->mo->y, p->mo->x, p->mo->y) - back;
if (diff > ANGLE_180)
{
diff = InvAngle(diff);
dir = -dir;
}
if (diff > ANGLE_90)
{
// Not behind the player
continue;
}
if (diff < blindSpotSize)
{
// Small blindspot directly behind your back, gives the impression of smoothly turning.
continue;
}
if (P_CheckSight(glancePlayer->mo, p->mo) == true)
{
// Not blocked by a wall, we can glance at 'em!
// Adds, so that if there's more targets on one of your sides, it'll glance on that side.
glanceDir += dir;
// That poses a limitation if there's an equal number of targets on both sides...
// In that case, we'll pick the last chosen glance direction.
lastValidGlance = dir;
}
}
if (glanceDir > 0)
{
return 1;
}
else if (glanceDir < 0)
{
return -1;
}
return lastValidGlance;
}
/** \brief Handles the state changing for moving players, moved here to eliminate duplicate code
\param player player data
@ -1847,6 +1943,14 @@ 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);
}
if (player->speed >= fastspeed && player->speed >= (player->lastspeed - speedthreshold))
{
// Going REAL fast!
@ -1861,7 +1965,18 @@ void K_KartMoveAnimation(player_t *player)
}
else
{
SetState(S_KART_FAST);
if (glanceDir == -1)
{
SetState(S_KART_FAST_GLANCE_R);
}
else if (glanceDir == 1)
{
SetState(S_KART_FAST_GLANCE_L);
}
else
{
SetState(S_KART_FAST);
}
}
}
else
@ -1880,7 +1995,18 @@ void K_KartMoveAnimation(player_t *player)
}
else
{
SetState(S_KART_SLOW);
if (glanceDir == -1)
{
SetState(S_KART_SLOW_GLANCE_R);
}
else if (glanceDir == 1)
{
SetState(S_KART_SLOW_GLANCE_L);
}
else
{
SetState(S_KART_SLOW);
}
}
}
else
@ -1897,7 +2023,18 @@ void K_KartMoveAnimation(player_t *player)
}
else
{
SetState(S_KART_STILL);
if (glanceDir == -1)
{
SetState(S_KART_STILL_GLANCE_R);
}
else if (glanceDir == 1)
{
SetState(S_KART_STILL_GLANCE_L);
}
else
{
SetState(S_KART_STILL);
}
}
}
}