1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-23 08:08:47 -05:00

Digging and placing sounds

This commit is contained in:
Perttu Ahola 2012-03-24 00:33:58 +02:00
parent 6c14025b2d
commit 77120a021d
4 changed files with 96 additions and 16 deletions

View File

@ -188,13 +188,23 @@ void Camera::step(f32 dtime)
if (m_digging_button != -1) if (m_digging_button != -1)
{ {
f32 offset = dtime * 3.5; f32 offset = dtime * 3.5;
float m_digging_anim_was = m_digging_anim;
m_digging_anim += offset; m_digging_anim += offset;
if (m_digging_anim >= 1) if (m_digging_anim >= 1)
{ {
m_digging_anim = 0; m_digging_anim = 0;
m_digging_button = -1; m_digging_button = -1;
MtEvent *e = new SimpleTriggerEvent("CameraDig"); }
m_gamedef->event()->put(e); float lim = 0.15;
if(m_digging_anim_was < lim && m_digging_anim >= lim)
{
if(m_digging_button == 0){
MtEvent *e = new SimpleTriggerEvent("CameraPunchLeft");
m_gamedef->event()->put(e);
} else if(m_digging_button == 1){
MtEvent *e = new SimpleTriggerEvent("CameraPunchRight");
m_gamedef->event()->put(e);
}
} }
} }
} }

View File

@ -785,12 +785,14 @@ class SoundMaker
public: public:
ISoundManager *m_sound; ISoundManager *m_sound;
SimpleSoundSpec m_player_step_sound;
float m_player_step_timer; float m_player_step_timer;
SimpleSoundSpec m_player_step_sound;
SimpleSoundSpec m_player_leftpunch_sound;
SimpleSoundSpec m_player_rightpunch_sound;
SoundMaker(ISoundManager *sound): SoundMaker(ISoundManager *sound):
m_sound(sound), m_sound(sound),
m_player_step_sound("default_grass_walk"),
m_player_step_timer(0) m_player_step_timer(0)
{ {
} }
@ -803,6 +805,20 @@ public:
} }
} }
void playPlayerLeftPunch()
{
if(m_player_leftpunch_sound.exists()){
m_sound->playSound(m_player_leftpunch_sound, false);
}
}
void playPlayerRightPunch()
{
if(m_player_rightpunch_sound.exists()){
m_sound->playSound(m_player_rightpunch_sound, false);
}
}
static void viewBobbingStep(MtEvent *e, void *data) static void viewBobbingStep(MtEvent *e, void *data)
{ {
SoundMaker *sm = (SoundMaker*)data; SoundMaker *sm = (SoundMaker*)data;
@ -817,6 +833,19 @@ public:
static void playerJump(MtEvent *e, void *data) static void playerJump(MtEvent *e, void *data)
{ {
//SoundMaker *sm = (SoundMaker*)data;
}
static void cameraPunchLeft(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker*)data;
sm->playPlayerLeftPunch();
}
static void cameraPunchRight(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker*)data;
sm->playPlayerRightPunch();
} }
void registerReceiver(MtEventManager *mgr) void registerReceiver(MtEventManager *mgr)
@ -824,6 +853,8 @@ public:
mgr->reg("ViewBobbingStep", SoundMaker::viewBobbingStep, this); mgr->reg("ViewBobbingStep", SoundMaker::viewBobbingStep, this);
mgr->reg("PlayerRegainGround", SoundMaker::playerRegainGround, this); mgr->reg("PlayerRegainGround", SoundMaker::playerRegainGround, this);
mgr->reg("PlayerJump", SoundMaker::playerJump, this); mgr->reg("PlayerJump", SoundMaker::playerJump, this);
mgr->reg("CameraPunchLeft", SoundMaker::cameraPunchLeft, this);
mgr->reg("CameraPunchRight", SoundMaker::cameraPunchRight, this);
} }
void step(float dtime) void step(float dtime)
@ -904,11 +935,26 @@ void the_game(
// Test sounds // Test sounds
sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_grass_walk3_mono.ogg"); + "sounds" + DIR_DELIM + "default_grass_walk1.ogg");
sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_grass_walk4_mono.ogg"); + "sounds" + DIR_DELIM + "default_grass_walk2.ogg");
//sound->playSound("default_grass_walk", false, 1.0); sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
//sound->playSoundAt("default_grass_walk", true, 1.0, v3f(0,10,0)*BS); + "sounds" + DIR_DELIM + "default_grass_walk3.ogg");
sound->loadSound("default_dig_crumbly", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_dig_crumbly1.ogg");
sound->loadSound("default_dig_crumbly", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_dig_crumbly2.ogg");
sound->loadSound("default_dig_cracky", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_dig_cracky1.ogg");
sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_place_node1.ogg");
sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_place_node2.ogg");
sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_place_node3.ogg");
// Add chat log output for errors to be shown in chat // Add chat log output for errors to be shown in chat
LogOutputBuffer chat_log_error_buf(LMT_ERROR); LogOutputBuffer chat_log_error_buf(LMT_ERROR);
@ -2131,6 +2177,11 @@ void the_game(
} }
} }
// We can't actually know, but assume the sound of right-clicking
// to be the sound of placing a node
soundmaker.m_player_rightpunch_sound.gain = 0.5;
soundmaker.m_player_rightpunch_sound.name = "default_place_node";
/* /*
Handle digging Handle digging
*/ */
@ -2157,6 +2208,16 @@ void the_game(
params = getDigParams(nodedef->get(n).groups, tp); params = getDigParams(nodedef->get(n).groups, tp);
} }
soundmaker.m_player_leftpunch_sound.gain = 0.5;
if(params.main_group == "crumbly")
soundmaker.m_player_leftpunch_sound.name =
"default_dig_crumbly";
else if(params.main_group == "cracky")
soundmaker.m_player_leftpunch_sound.name =
"default_dig_cracky";
else
soundmaker.m_player_leftpunch_sound.name = "";
float dig_time_complete = 0.0; float dig_time_complete = 0.0;
if(params.diggable == false) if(params.diggable == false)

View File

@ -77,10 +77,10 @@ DigParams getDigParams(const ItemGroupList &groups,
switch(itemgroup_get(groups, "dig_immediate")){ switch(itemgroup_get(groups, "dig_immediate")){
case 2: case 2:
//infostream<<"dig_immediate=2"<<std::endl; //infostream<<"dig_immediate=2"<<std::endl;
return DigParams(true, 0.5, 0); return DigParams(true, 0.5, 0, "dig_immediate");
case 3: case 3:
//infostream<<"dig_immediate=3"<<std::endl; //infostream<<"dig_immediate=3"<<std::endl;
return DigParams(true, 0.0, 0); return DigParams(true, 0.0, 0, "dig_immediate");
default: default:
break; break;
} }
@ -89,6 +89,7 @@ DigParams getDigParams(const ItemGroupList &groups,
bool result_diggable = false; bool result_diggable = false;
float result_time = 0.0; float result_time = 0.0;
float result_wear = 0.0; float result_wear = 0.0;
std::string result_main_group = "";
int level = itemgroup_get(groups, "level"); int level = itemgroup_get(groups, "level");
//infostream<<"level="<<level<<std::endl; //infostream<<"level="<<level<<std::endl;
@ -106,6 +107,7 @@ DigParams getDigParams(const ItemGroupList &groups,
result_time = time; result_time = time;
int leveldiff = cap.maxlevel - level; int leveldiff = cap.maxlevel - level;
result_wear = cap.maxwear / pow(4.0, (double)leveldiff); result_wear = cap.maxwear / pow(4.0, (double)leveldiff);
result_main_group = name;
} }
} }
} }
@ -121,7 +123,7 @@ DigParams getDigParams(const ItemGroupList &groups,
} }
u16 wear_i = 65535.*result_wear; u16 wear_i = 65535.*result_wear;
return DigParams(result_diggable, result_time, wear_i); return DigParams(result_diggable, result_time, wear_i, result_main_group);
} }
DigParams getDigParams(const ItemGroupList &groups, DigParams getDigParams(const ItemGroupList &groups,
@ -145,7 +147,7 @@ HitParams getHitParams(const ItemGroupList &groups,
// Wear is the same as for digging a single node // Wear is the same as for digging a single node
s16 wear = (float)digprop.wear; s16 wear = (float)digprop.wear;
return HitParams(hp, wear); return HitParams(hp, wear, digprop.main_group);
} }
HitParams getHitParams(const ItemGroupList &groups, HitParams getHitParams(const ItemGroupList &groups,
@ -181,6 +183,7 @@ PunchDamageResult getPunchDamage(
result.did_punch = true; result.did_punch = true;
result.wear = hitparams.wear; result.wear = hitparams.wear;
result.damage = hitparams.hp; result.damage = hitparams.hp;
result.main_group = hitparams.main_group;
} }
return result; return result;

View File

@ -82,11 +82,14 @@ struct DigParams
float time; float time;
// Caused wear // Caused wear
u16 wear; u16 wear;
std::string main_group;
DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0): DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0,
std::string a_main_group=""):
diggable(a_diggable), diggable(a_diggable),
time(a_time), time(a_time),
wear(a_wear) wear(a_wear),
main_group(a_main_group)
{} {}
}; };
@ -100,10 +103,12 @@ struct HitParams
{ {
s16 hp; s16 hp;
s16 wear; s16 wear;
std::string main_group;
HitParams(s16 hp_=0, s16 wear_=0): HitParams(s16 hp_=0, s16 wear_=0, std::string main_group_=""):
hp(hp_), hp(hp_),
wear(wear_) wear(wear_),
main_group(main_group_)
{} {}
}; };
@ -118,6 +123,7 @@ struct PunchDamageResult
bool did_punch; bool did_punch;
int damage; int damage;
int wear; int wear;
std::string main_group;
PunchDamageResult(): PunchDamageResult():
did_punch(false), did_punch(false),