Play 'player_jump' when player jumps (#9373)
authorWuzzy <wuzzy2@mail.ru>
Sat, 11 Apr 2020 23:50:40 +0000 (01:50 +0200)
committerGitHub <noreply@github.com>
Sat, 11 Apr 2020 23:50:40 +0000 (00:50 +0100)
doc/lua_api.txt
src/client/game.cpp

index 1a9aad3443420ea464e7e9b8e992f8173113d50b..dff6c728ea39e1a1e00cdc8f2b689441832c8484 100644 (file)
@@ -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)
 
index 06e76d1705142ce193eec563d76eed306c4c913c..ac6045190a3d585d3e140d2ae5b3dbb6dee19bd2 100644 (file)
@@ -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;
@@ -275,7 +276,8 @@ public:
                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)
        {
        }
 
@@ -288,6 +290,14 @@ public:
                }
        }
 
+       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;
@@ -302,7 +312,8 @@ public:
 
        static void playerJump(MtEvent *e, void *data)
        {
-               //SoundMaker *sm = (SoundMaker*)data;
+               SoundMaker *sm = (SoundMaker *)data;
+               sm->playPlayerJump();
        }
 
        static void cameraPunchLeft(MtEvent *e, void *data)
@@ -351,6 +362,7 @@ public:
        void step(float dtime)
        {
                m_player_step_timer -= dtime;
+               m_player_jump_timer -= dtime;
        }
 };