Skip to content

Commit

Permalink
Play player_damage.ogg when recieving damage and additionally play pl…
Browse files Browse the repository at this point in the history
…ayer_falling_damage.ogg when recieving falling damage
  • Loading branch information
PilzAdam committed Jun 12, 2013
1 parent 7734717 commit 2cdf0ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/environment.cpp
Expand Up @@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER
#include "clientmap.h"
#include "localplayer.h"
#include "event.h"
#endif
#include "daynightratio.h"
#include "map.h"
Expand Down Expand Up @@ -2190,8 +2191,11 @@ void ClientEnvironment::step(float dtime)
{
f32 damage_f = (speed - tolerance)/BS * post_factor;
u16 damage = (u16)(damage_f+0.5);
if(damage != 0)
if(damage != 0){
damageLocalPlayer(damage, true);
MtEvent *e = new SimpleTriggerEvent("PlayerFallingDamage");
m_gamedef->event()->put(e);
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/game.cpp
Expand Up @@ -729,6 +729,18 @@ class SoundMaker
sm->m_sound->playSound(sm->m_ndef->get(nde->n).sound_dug, false);
}

static void playerDamage(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker*)data;
sm->m_sound->playSound(SimpleSoundSpec("player_damage", 0.5), false);
}

static void playerFallingDamage(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker*)data;
sm->m_sound->playSound(SimpleSoundSpec("player_falling_damage", 0.5), false);
}

void registerReceiver(MtEventManager *mgr)
{
mgr->reg("ViewBobbingStep", SoundMaker::viewBobbingStep, this);
Expand All @@ -737,6 +749,8 @@ class SoundMaker
mgr->reg("CameraPunchLeft", SoundMaker::cameraPunchLeft, this);
mgr->reg("CameraPunchRight", SoundMaker::cameraPunchRight, this);
mgr->reg("NodeDug", SoundMaker::nodeDug, this);
mgr->reg("PlayerDamage", SoundMaker::playerDamage, this);
mgr->reg("PlayerFallingDamage", SoundMaker::playerFallingDamage, this);
}

void step(float dtime)
Expand Down Expand Up @@ -2202,6 +2216,9 @@ void the_game(
player->hurt_tilt_timer = 1.5;
player->hurt_tilt_strength = event.player_damage.amount/2;
player->hurt_tilt_strength = rangelim(player->hurt_tilt_strength, 2.0, 10.0);

MtEvent *e = new SimpleTriggerEvent("PlayerDamage");
gamedef->event()->put(e);
}
else if(event.type == CE_PLAYER_FORCE_MOVE)
{
Expand Down

0 comments on commit 2cdf0ff

Please sign in to comment.