Skip to content

Commit eb0f0df

Browse files
committed
temporary car engine sound
1 parent 4422722 commit eb0f0df

10 files changed

Lines changed: 81 additions & 10 deletions

File tree

gamedata/config/inputs.json.default

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
{"action":"Run", "keycode":"Up", "gpbutton":"Up"},
1616
{"action":"Shoot", "keycode":"LCtrl", "gpbutton":"B"},
1717
{"action":"EnterCar", "keycode":"Enter", "gpbutton":"X"},
18-
{"action":"EnterCarAsPassenger", "keycode":"f", "gpbutton":"A"},
18+
{"action":"EnterCarAsPassenger", "keycode":"f", "gpbutton":"A"},
19+
{"action":"Special", "keycode":"Tab"},
1920
// in car
2021
{"action":"HandBrake", "keycode":"Space", "gpbutton":"Y"},
2122
{"action":"Accelerate", "keycode":"Up", "gpbutton":"Up"},

src/GameDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ struct PedestrianCtlState
868868
bool mRun = false;
869869
bool mShoot = false;
870870
bool mJump = false;
871+
bool mSpecial = false;
871872
};
872873
struct // in car control actions
873874
{

src/HumanPlayer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ void HumanPlayer::ProcessInputAction(eInputAction action, bool isActivated)
190190
}
191191
break;
192192

193+
case eInputAction_Special:
194+
ctlState.mSpecial = isActivated;
195+
break;
196+
193197
case eInputAction_EnterCar:
194198
case eInputAction_LeaveCar:
195199
case eInputAction_EnterCarAsPassenger:

src/InputActionsMapping.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static const DefaultActionMapping gDefaultActionsMapping[] =
4242
{eInputActionsGroup_OnFoot, eInputAction_Shoot, eKeycode_LEFT_CTRL},
4343
{eInputActionsGroup_OnFoot, eInputAction_EnterCar, eKeycode_ENTER},
4444
{eInputActionsGroup_OnFoot, eInputAction_EnterCarAsPassenger, eKeycode_F},
45+
{eInputActionsGroup_OnFoot, eInputAction_Special, eKeycode_TAB},
4546
};
4647

4748
InputActionsMapping::InputActionsMapping()
@@ -168,6 +169,7 @@ eInputActionsGroup InputActionsMapping::GetInputActionsGroup(eInputAction action
168169
case eInputAction_Shoot:
169170
case eInputAction_EnterCar:
170171
case eInputAction_EnterCarAsPassenger:
172+
case eInputAction_Special:
171173
return eInputActionsGroup_OnFoot;
172174

173175
case eInputAction_HandBrake:

src/InputsDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ enum eInputAction
162162
eInputAction_Shoot,
163163
eInputAction_EnterCar,
164164
eInputAction_EnterCarAsPassenger,
165+
eInputAction_Special,
165166

166167
// in car
167168
eInputAction_HandBrake,

src/PedestrianStates.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,13 @@ void PedestrianStatesManager::StateIdle_ProcessFrame()
697697
isShooting = !((mCurrentStateID == ePedestrianState_Walks) && (mPedestrian->mCurrentWeapon == eWeapon_Fists));
698698
}
699699

700+
// do special sounds :)
701+
if (ctlState.mSpecial)
702+
{
703+
SfxIndex specialSound = gCarnageGame.mGameRand.random_chance(50) ? SfxLevel_SpecialSound1 : SfxLevel_SpecialSound2;
704+
mPedestrian->StartGameObjectSound(ePedSfxChannelIndex_Voice, eSfxType_Level, specialSound, SfxFlags_RandomPitch);
705+
}
706+
700707
// update animation
701708
ePedestrianAnimID animID = DetectIdleAnimation(isShooting);
702709
if (animID != mPedestrian->mCurrentAnimID)

src/SfxDefs.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ enum : SfxIndex
5151
SfxLevel_CrateBreak = 11,
5252
SfxLevel_CarJacking = 15,
5353
SfxLevel_Punch = 16,
54+
SfxLevel_Squashed = 17,
5455
SfxLevel_WaterSplash = 18,
5556
SfxLevel_FootStep1 = 19,
5657
SfxLevel_FootStep2 = 20,
57-
SfxLevel_Scream1 = 21,
58-
SfxLevel_Scream2 = 22,
59-
SfxLevel_Scream3 = 23,
60-
SfxLevel_Scream4 = 24,
61-
SfxLevel_Scream5 = 25,
62-
SfxLevel_Scream6 = 26,
63-
SfxLevel_Scream7 = 27,
58+
SfxLevel_ScaredScream1 = 21,
59+
SfxLevel_ScaredScream2 = 22,
60+
SfxLevel_ScaredScream3 = 23,
61+
SfxLevel_DieScream1 = 24, // burn
62+
SfxLevel_DieScream2 = 25,
63+
SfxLevel_DieScream3 = 26,
64+
SfxLevel_DieScream4 = 27, // electrocuted
6465
SfxLevel_PhoneRing = 28,
6566
SfxLevel_PistolShot = 33,
6667
SfxLevel_MachineGunShot = 34,
@@ -77,6 +78,11 @@ enum : SfxIndex
7778
SfxLevel_FirstCarHornSound = 58,
7879
// car horn sounds
7980

81+
SfxLevel_CarAlarm = 64,
82+
83+
SfxLevel_SpecialSound1 = 76, // burp
84+
SfxLevel_SpecialSound2 = 77, // farts
85+
8086
SfxLevel_COUNT
8187
};
8288

@@ -99,4 +105,10 @@ enum ePedSfxChannelIndex
99105
ePedSfxChannelIndex_Voice,
100106
ePedSfxChannelIndex_Weapon,
101107
ePedSfxChannelIndex_Misc,
108+
};
109+
enum eCarSfxChannelIndex
110+
{
111+
eCarSfxChannelIndex_Doors,
112+
eCarSfxChannelIndex_Engine,
113+
eCarSfxChannelIndex_Misc, // horn, etc
102114
};

src/Vehicle.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Vehicle::~Vehicle()
3636
}
3737
mPassengers.clear();
3838
}
39+
40+
// force stop sounds
41+
if (mSfxEmitter)
42+
{
43+
mSfxEmitter->StopAllSounds();
44+
}
3945

4046
if (mPhysicsBody)
4147
{
@@ -73,7 +79,7 @@ void Vehicle::UpdateFrame()
7379
{
7480
UpdateBurnEffect();
7581
UpdateDamageFromRailways();
76-
82+
UpdateEngineSound();
7783
if (IsWrecked())
7884
return;
7985

@@ -875,7 +881,7 @@ bool Vehicle::OnAnimFrameAction(SpriteAnimation* animation, int frameIndex, eSpr
875881
if (actionID == eSpriteAnimAction_CarDoors)
876882
{
877883
bool openDoors = animation->IsRunsForwards();
878-
StartGameObjectSound(0, eSfxType_Level, openDoors ? SfxLevel_CarDoorOpen : SfxLevel_CarDoorClose, SfxFlags_RandomPitch);
884+
StartGameObjectSound(eCarSfxChannelIndex_Doors, eSfxType_Level, openDoors ? SfxLevel_CarDoorOpen : SfxLevel_CarDoorClose, SfxFlags_RandomPitch);
879885
}
880886
return true;
881887
}
@@ -884,3 +890,38 @@ bool Vehicle::IsCriticalDamageState() const
884890
{
885891
return mCurrentDamage >= 100;
886892
}
893+
894+
void Vehicle::UpdateEngineSound()
895+
{
896+
if (mSfxEmitter == nullptr)
897+
return;
898+
899+
if (IsWrecked())
900+
{
901+
mSfxEmitter->StopSound(eCarSfxChannelIndex_Engine);
902+
return;
903+
}
904+
905+
if (!HasPassengers())
906+
{
907+
mSfxEmitter->StopSound(eCarSfxChannelIndex_Engine);
908+
return;
909+
}
910+
911+
SfxIndex sfxIndex = SfxLevel_FirstCarEngineSound + mCarInfo->mEngine;
912+
913+
if (!mSfxEmitter->IsPlaying(eCarSfxChannelIndex_Engine))
914+
{
915+
if (!StartGameObjectSound(eCarSfxChannelIndex_Engine, eSfxType_Level, sfxIndex, SfxFlags_Loop))
916+
return;
917+
918+
mSfxEmitter->SetGain(eCarSfxChannelIndex_Engine, 0.35f);
919+
}
920+
// todo: this is temporary solution!
921+
922+
float speed = fabs(mPhysicsBody->GetCurrentSpeed());
923+
float maxSpeed = 3.0f;
924+
float pitchValue = 0.8f + (speed / maxSpeed);
925+
pitchValue = std::min(pitchValue, 4.0f);
926+
mSfxEmitter->SetPitch(eCarSfxChannelIndex_Engine, pitchValue);
927+
}

src/Vehicle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class Vehicle final: public GameObject
113113
void ComputeDrawHeight(const glm::vec3& position);
114114
void SetupDeltaAnimations();
115115
void UpdateDeltaAnimations();
116+
void UpdateEngineSound();
116117

117118
void SetBurnEffectActive(bool isActive);
118119
void UpdateBurnEffect();

src/enums_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ impl_enum_strings(eInputAction)
417417
{eInputAction_PrevWeapon, "PrevWeapon"},
418418
{eInputAction_EnterCar, "EnterCar"},
419419
{eInputAction_EnterCarAsPassenger, "EnterCarAsPassenger"},
420+
{eInputAction_Special, "Special"},
420421
{eInputAction_LeaveCar, "LeaveCar"},
421422
{eInputAction_HandBrake, "HandBrake"},
422423
{eInputAction_Accelerate, "Accelerate"},

0 commit comments

Comments
 (0)