diff options
Diffstat (limited to 'src/GameLoop.cpp')
-rw-r--r-- | src/GameLoop.cpp | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index a927f2f..77ec774 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -24,6 +24,7 @@ extern float multiplier; extern int thirdperson; extern int visions; +extern float soundscalefactor; extern unsigned int gSourceID[100]; extern unsigned int gSampleSet[100]; extern Camera camera; @@ -76,23 +77,56 @@ void handleKey(Game* game, int key, int action, int mods) player.aimamount = 0; } } else if (key == GLFW_KEY_R) { - if (player.reloads[player.whichgun] > 0 + if (player.whichgun != grenade + && player.reloads[player.whichgun] > 0 && player.reloading <= 0) player.ammo = -1; } else if (key == aimkey) { player.aiming ^= 1; } else if (key == psychicaimkey) { - game->flashamount = 0.5; - game->flashr = 1; - game->flashg = game->flashb = 0; - alSourcePlay(gSourceID[souloutsound]); + // Picking up gun from rag doll + if (player.currentanimation == crouchanim + && (!player.aiming || player.whichgun == nogun + || player.whichgun == knife + || player.whichgun == grenade)) { + for (int i = 1; i < game->numpeople; ++i) { + auto& person = game->person[i]; + if (!person.skeleton.free + || findDistancefast(player.playercoords, + person.averageloc) > 200) + continue; + + auto soundsrc = (player.playercoords + - camera.position) / soundscalefactor; + float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z}; + alSourcefv(gSourceID[clicksound], AL_POSITION, gLoc); + alSourcePlay(gSourceID[clicksound]); + + auto tmp_gun = player.whichgun; + player.whichgun = person.whichgun; + person.whichgun = tmp_gun; + + auto tmp_ammo = player.ammo; + player.ammo = person.ammo; + person.ammo = tmp_ammo; + + player.aiming = 1; + player.aimamount = 0; + break; + } + } else { + game->flashamount = 0.5; + game->flashr = 1; + game->flashg = game->flashb = 0; + alSourcePlay(gSourceID[souloutsound]); - slomo = 2; - game->score -= 20; + slomo = 2; + game->score -= 20; - alSourcef(gSourceID[knifesong], AL_PITCH, 0.5f); - alSourcef(gSourceID[shootsong], AL_PITCH, 0.5f); - alSourcef(gSourceID[zombiesong], AL_PITCH, 0.5f); + alSourcef(gSourceID[knifesong], AL_PITCH, 0.5f); + alSourcef(gSourceID[shootsong], AL_PITCH, 0.5f); + alSourcef(gSourceID[zombiesong], AL_PITCH, 0.5f); + } } else if (key == psychickey) { if (visions ^= 1) { game->flashamount = game->flashr = 1; @@ -186,14 +220,14 @@ void handleKey(Game* game, int key, int action, int mods) } break; case GLFW_KEY_X: - if (!shift || player.grenphase) + if (player.grenphase) break; + player.grenphase = 0; player.ammo = -1; player.whichgun++; - player.grenphase = 0; - player.reloads[player.whichgun] = 3; if (player.whichgun > 7) player.whichgun = 0; + player.reloads[player.whichgun] = 3; break; } } |