Skip to content

Commit

Permalink
time footsteps with duration of movement, not with actor age
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Oct 20, 2024
1 parent 34dc204 commit 6e5e023
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions wadsrc/static/zscript/actors/player/player.zs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,39 +1728,55 @@ class PlayerPawn : Actor
//
//---------------------------------------------------------------------------

int footstepCounter;

virtual void MakeFootsteps()
{
if (pos.z > floorz) return;
if(pos.z > floorz) return;

let Ground = GetFloorTerrain();
let cmd = player.cmd;

if (Ground && (cmd.forwardMove != 0 || cmd.sideMove != 0))
if(Ground && (player.cmd.forwardMove != 0 || player.cmd.sideMove != 0))
{
bool Running = (cmd.buttons & BT_RUN); //Holding down run key, or it's toggled.
int Delay = !Running ? Ground.WalkStepTics : Ground.RunStepTics;

if (Delay <= 0 || GetAge() % Delay != 0) return;
int Delay = (player.cmd.buttons & BT_RUN) ? Ground.RunStepTics : Ground.WalkStepTics;

Sound Step = Ground.StepSound;
if((player.cmd.buttons ^ player.oldbuttons) & BT_RUN) footstepCounter = 0; // zero out counter when starting/stopping a run

//Generic foot-agnostic sound takes precedence.
if (!Step)
if(Delay > 0 && (footstepCounter % Delay == 0))
{
//Apparently most people walk with their right foot first, so assume that here.
if (GetAge() % (Delay*2) == 0)
Step = Ground.LeftStepSound;
else
Step = Ground.RightStepSound;
}
Sound Step = Ground.StepSound;

//Generic foot-agnostic sound takes precedence.
if(!Step)
{
//Apparently most people walk with their right foot first, so assume that here.
if (footstepCounter == 0)
{
Step = Ground.LeftStepSound;
}
else
{
Step = Ground.RightStepSound;
}
}

if(Step)
{
A_StartSound(Step, flags: CHANF_OVERLAP, volume: Ground.StepVolume);
}

if (Step)
A_StartSound (Step,flags:CHANF_OVERLAP,volume:Ground.StepVolume);
//Steps make splashes regardless.
bool Heavy = (Mass >= 200) ? 0 : THW_SMALL; //Big player makes big splash.
HitWater(CurSector, (Pos.XY, CurSector.FloorPlane.ZatPoint(Pos.XY)), true, false, flags: Heavy | THW_NOVEL);
}

//Steps make splashes regardless.
bool Heavy = Mass >= 200 ? 0 : THW_SMALL; //Big player makes big splash.
HitWater (CurSector,(Pos.XY,CurSector.FloorPlane.ZatPoint(Pos.XY)),True,False,flags:Heavy|THW_NOVEL);
footstepCounter = (footstepCounter + 1) % (Delay * 2);
}
else
{
footstepCounter = 0;
}

}

//---------------------------------------------------------------------------
Expand Down

0 comments on commit 6e5e023

Please sign in to comment.