Skip to content

Commit a24d3b3

Browse files
authoredApr 11, 2020
Play 'player_jump' when player jumps (#9373)
1 parent 3833396 commit a24d3b3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ These sound files are played back by the engine if provided.
897897
* `player_damage`: Played when the local player takes damage (gain = 0.5)
898898
* `player_falling_damage`: Played when the local player takes
899899
damage by falling (gain = 0.5)
900+
* `player_jump`: Played when the local player jumps
900901
* `default_dig_<groupname>`: Default node digging sound
901902
(see node sound definition for details)
902903

‎src/client/game.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class SoundMaker
266266
public:
267267
bool makes_footstep_sound;
268268
float m_player_step_timer;
269+
float m_player_jump_timer;
269270

270271
SimpleSoundSpec m_player_step_sound;
271272
SimpleSoundSpec m_player_leftpunch_sound;
@@ -275,7 +276,8 @@ class SoundMaker
275276
m_sound(sound),
276277
m_ndef(ndef),
277278
makes_footstep_sound(true),
278-
m_player_step_timer(0)
279+
m_player_step_timer(0.0f),
280+
m_player_jump_timer(0.0f)
279281
{
280282
}
281283

@@ -288,6 +290,14 @@ class SoundMaker
288290
}
289291
}
290292

293+
void playPlayerJump()
294+
{
295+
if (m_player_jump_timer <= 0.0f) {
296+
m_player_jump_timer = 0.2f;
297+
m_sound->playSound(SimpleSoundSpec("player_jump", 0.5f), false);
298+
}
299+
}
300+
291301
static void viewBobbingStep(MtEvent *e, void *data)
292302
{
293303
SoundMaker *sm = (SoundMaker *)data;
@@ -302,7 +312,8 @@ class SoundMaker
302312

303313
static void playerJump(MtEvent *e, void *data)
304314
{
305-
//SoundMaker *sm = (SoundMaker*)data;
315+
SoundMaker *sm = (SoundMaker *)data;
316+
sm->playPlayerJump();
306317
}
307318

308319
static void cameraPunchLeft(MtEvent *e, void *data)
@@ -351,6 +362,7 @@ class SoundMaker
351362
void step(float dtime)
352363
{
353364
m_player_step_timer -= dtime;
365+
m_player_jump_timer -= dtime;
354366
}
355367
};
356368

0 commit comments

Comments
 (0)
Please sign in to comment.