From 445e691331ad4e39cc9351e514f97e10d99f92ce Mon Sep 17 00:00:00 2001 From: driAn Date: Tue, 20 May 2008 20:43:29 +0000 Subject: [PATCH] bounce sound for grenades git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2072 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entity.h | 3 +++ source/src/physics.cpp | 6 +++++- source/src/sound.cpp | 2 +- source/src/sound.h | 2 +- source/src/weapon.cpp | 3 +-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source/src/entity.h b/source/src/entity.h index b4767015..b1ec597d 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -134,6 +134,8 @@ struct physent else if(crouching) return croucheyeheight; // fully crouching return eyeheight; // not crouching } + + virtual void oncollision() {}; }; struct dynent : physent // animated ent @@ -499,5 +501,6 @@ struct grenadeent : bounceent virtual void destroy(); virtual bool applyphysics(); void moveoutsidebbox(const vec &direction, playerent *boundingbox); + void oncollision(); }; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index b21bf99b..a8716c2f 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -385,6 +385,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) } } + bool collided = false; if(!editfly) loopi(moveres) // discrete steps collision detection & sliding { const float f = 1.0f/moveres; @@ -394,7 +395,8 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) pl->o.y += f*d.y; pl->o.z += f*d.z; hitplayer = NULL; - if(collide(pl, false, drop, rise)) continue; + if(collide(pl, false, drop, rise)) continue; + else collided = true; if(pl->type==ENT_CAMERA) return; if(pl->type==ENT_PLAYER && hitplayer) { @@ -438,6 +440,8 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) break; } + if(collided) pl->oncollision(); + if(pl->type==ENT_CAMERA) return; else if(pl->type!=ENT_BOUNCE) { diff --git a/source/src/sound.cpp b/source/src/sound.cpp index a30351b2..39ad91fd 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -158,8 +158,8 @@ struct oggstream alclearerr(); alBufferData(bufid, format, pcm, size, info->rate); - return !alerr(); } + return !alerr(); } bool update() diff --git a/source/src/sound.h b/source/src/sound.h index 824798a3..a8c93a8c 100644 --- a/source/src/sound.h +++ b/source/src/sound.h @@ -18,7 +18,7 @@ enum S_FEXPLODE, S_SPLASH1, S_SPLASH2, S_FLAGDROP, S_FLAGPICKUP, S_FLAGRETURN, S_FLAGSCORE, - S_GRENADEPULL, S_GRENADETHROW, + S_GRENADEPULL, S_GRENADETHROW, S_GRENADEBOUNCE1, S_GRENADEBOUNCE2, S_RAKIMBO, S_GUNCHANGE, S_GIB, S_HEADSHOT, S_CALLVOTE, S_VOTEPASS, S_VOTEFAIL, S_FOOTSTEPS, S_FOOTSTEPSCROUCH, diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index a8b827ea..5ee6447b 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -548,7 +548,6 @@ grenadeent::grenadeent (playerent *owner, int millis) bouncetype = BT_NADE; maxspeed = 27.0f; rotspeed = 6.0f; - } void grenadeent::explode() @@ -625,7 +624,7 @@ void grenadeent::moveoutsidebbox(const vec &direction, playerent *boundingbox) void grenadeent::destroy() { explode(); } bool grenadeent::applyphysics() { return nadestate==NS_THROWED; } - +void grenadeent::oncollision() { if(nadestate==NS_THROWED) playsound(S_GRENADEBOUNCE1+rnd(2), this, 0, 0); } // grenades