Skip to content

Commit

Permalink
Play 'player_jump' when player jumps (#9373)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 committed Apr 11, 2020
1 parent 3833396 commit a24d3b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/lua_api.txt
Expand Up @@ -897,6 +897,7 @@ These sound files are played back by the engine if provided.
* `player_damage`: Played when the local player takes damage (gain = 0.5)
* `player_falling_damage`: Played when the local player takes
damage by falling (gain = 0.5)
* `player_jump`: Played when the local player jumps
* `default_dig_<groupname>`: Default node digging sound
(see node sound definition for details)

Expand Down
16 changes: 14 additions & 2 deletions src/client/game.cpp
Expand Up @@ -266,6 +266,7 @@ class SoundMaker
public:
bool makes_footstep_sound;
float m_player_step_timer;
float m_player_jump_timer;

SimpleSoundSpec m_player_step_sound;
SimpleSoundSpec m_player_leftpunch_sound;
Expand All @@ -275,7 +276,8 @@ class SoundMaker
m_sound(sound),
m_ndef(ndef),
makes_footstep_sound(true),
m_player_step_timer(0)
m_player_step_timer(0.0f),
m_player_jump_timer(0.0f)
{
}

Expand All @@ -288,6 +290,14 @@ class SoundMaker
}
}

void playPlayerJump()
{
if (m_player_jump_timer <= 0.0f) {
m_player_jump_timer = 0.2f;
m_sound->playSound(SimpleSoundSpec("player_jump", 0.5f), false);
}
}

static void viewBobbingStep(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker *)data;
Expand All @@ -302,7 +312,8 @@ class SoundMaker

static void playerJump(MtEvent *e, void *data)
{
//SoundMaker *sm = (SoundMaker*)data;
SoundMaker *sm = (SoundMaker *)data;
sm->playPlayerJump();
}

static void cameraPunchLeft(MtEvent *e, void *data)
Expand Down Expand Up @@ -351,6 +362,7 @@ class SoundMaker
void step(float dtime)
{
m_player_step_timer -= dtime;
m_player_jump_timer -= dtime;
}
};

Expand Down

0 comments on commit a24d3b3

Please sign in to comment.