diff options
-rw-r--r-- | src/Game.h | 8 | ||||
-rw-r--r-- | src/GameLoop.cpp | 139 | ||||
-rw-r--r-- | src/GameTick.cpp | 102 |
3 files changed, 106 insertions, 143 deletions
diff --git a/src/Game.h b/src/Game.h index 1f92ba7..aafc199 100644 --- a/src/Game.h +++ b/src/Game.h @@ -81,9 +81,6 @@ public: float mousesensitivity; float usermousesensitivity; - // Keyboard - bool tabkeydown; - // Project specific int cityrotation[num_blocks][num_blocks]; int citytype[num_blocks][num_blocks]; @@ -135,9 +132,6 @@ public: bool paused; int mainmenu; - bool reloadtoggle; - bool aimtoggle; - Point olddrawmouse; XYZ vipgoal; XYZ aimer[2]; @@ -156,7 +150,6 @@ public: bool musictoggle; float psychicpower; int type; - bool slomokeydown; int mouseoverbutton; int oldmouseoverbutton; @@ -184,7 +177,6 @@ public: int evilprobability; float difficulty; bool azertykeyboard; - bool oldvisionkey; // GL functions GLvoid ReSizeGLScene(float fov, float near); diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index 9e42b88..1ef1c9f 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -22,6 +22,7 @@ #include "Game.h" extern float multiplier; +extern int thirdperson; extern int visions; extern unsigned int gSourceID[100]; extern unsigned int gSampleSet[100]; @@ -30,27 +31,120 @@ extern float rad2deg; extern Fog fog; extern int environment; extern int slomo; +extern int aimkey; +extern int psychicaimkey; +extern int psychickey; void keyCallback(Game* game, int key, int action, int mods) { - if (game->mainmenu || action != GLFW_PRESS) + if (action != GLFW_PRESS) return; + if (game->mainmenu) { + if (key == GLFW_KEY_SPACE) + game->mainmenu = 0; + return; + } + + auto& player = game->person[0]; + if (key == GLFW_KEY_ESCAPE) { + alSourcePause(gSourceID[rainsound]); + game->mainmenu = 1; + alSourcePlay(gSourceID[souloutsound]); + game->flashamount = 1.0f; + game->flashr = game->flashg = game->flashb = 1.0f; + alSourceStop(gSourceID[visionsound]); + game->whichsong = mainmenusong; + alSourceStop(gSourceID[knifesong]); + alSourceStop(gSourceID[shootsong]); + alSourceStop(gSourceID[zombiesong]); + alSourceStop(gSourceID[mainmenusong]); + alSourcef(gSourceID[knifesong], AL_MIN_GAIN, 0); + alSourcef(gSourceID[shootsong], AL_MIN_GAIN, 0); + alSourcef(gSourceID[zombiesong], AL_MIN_GAIN, 0); + alSourcef(gSourceID[mainmenusong], AL_MIN_GAIN, 0); + alSourcePlay(gSourceID[game->whichsong]); + alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1); + } else if (key == GLFW_KEY_L) { + game->lasersight ^= 1; + } else if (key == GLFW_KEY_SPACE) { + if (player.playerrotation == player.playerlowrotation + && player.targetanimation == joganim + && player.currentanimation == joganim + && !player.backwardsanim && !visions) { + player.targetanimation = diveanim; + player.targetframe = player.target = 0; + player.aimamount = 0; + } + } else if (key == GLFW_KEY_R) { + if (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]); + + 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); + } else if (key == psychickey) { + if (visions ^= 1) { + game->flashamount = game->flashr = 1; + game->flashg = game->flashb = 0; + alSourceStop(gSourceID[visionsound]); + alSourcePlay(gSourceID[souloutsound]); + + alSourcef(gSourceID[knifesong], AL_PITCH, 0.5f); + alSourcef(gSourceID[shootsong], AL_PITCH, 0.5f); + alSourcef(gSourceID[zombiesong], AL_PITCH, 0.5f); + alSourcePlay(gSourceID[visionsound]); + game->bodycoords = player.oldplayercoords; + } else { + game->flashamount = 1; + game->flashr = game->flashg = game->flashb = 1; + alSourceStop(gSourceID[visionsound]); + alSourcePlay(gSourceID[soulinsound]); + + alSourcef(gSourceID[knifesong], AL_PITCH, 1.0f); + alSourcef(gSourceID[shootsong], AL_PITCH, 1.0f); + alSourcef(gSourceID[zombiesong], AL_PITCH, 1.0f); + + XYZ towards = player.playercoords - game->bodycoords; + if (towards.x || towards.z) { + Normalise(&towards); + camera.rotation = RadiansToDegrees(asin(towards.x)); + if (towards.z > 0) + camera.rotation = 180 - camera.rotation; + + camera.visrotation = camera.rotation; + camera.oldrotation = camera.rotation; + } + + player.playercoords = game->bodycoords; + player.oldplayercoords = game->bodycoords; + player.velocity = 0; + } + } - auto shift = mods & GLFW_MOD_SHIFT; - auto player = game->person[0]; + if (!game->debug) + return; + const auto shift = mods & GLFW_MOD_SHIFT; XYZ facing; switch(key) { - case GLFW_KEY_L: - game->lasersight ^= 1; + case GLFW_KEY_TAB: + thirdperson = (thirdperson == 2) ? 0 : (thirdperson + 1); break; case GLFW_KEY_K: - if (game->debug) - game->timeremaining = 0; + game->timeremaining = 0; break; case GLFW_KEY_B: - if (!game->debug) - break; alSourcePlay(gSourceID[soulinsound]); if (shift) { game->paused = 1 - game->paused; @@ -62,13 +156,10 @@ void keyCallback(Game* game, int key, int action, int mods) } break; case GLFW_KEY_F: - if (!game->debug) - break; - alSourcePlay(gSourceID[souloutsound]); - facing = {0, 0, -1}; facing = DoRotation(facing, -camera.rotation2, 0, 0); facing = DoRotation(facing, 0, 0 - camera.rotation, 0); + alSourcePlay(gSourceID[souloutsound]); for (int i = 1; i < game->numpeople; i++) { auto& person = game->person[i]; @@ -95,7 +186,7 @@ void keyCallback(Game* game, int key, int action, int mods) } break; case GLFW_KEY_X: - if (!game->debug || !shift || player.grenphase) + if (!shift || player.grenphase) break; player.ammo = -1; player.whichgun++; @@ -139,24 +230,4 @@ void eventLoop(Game* game) multiplier /= 5; if (game->paused) multiplier = 0; - - if (IsKeyDown(GLFW_KEY_ESCAPE)) { - alSourcePause(gSourceID[rainsound]); - game->mainmenu = 1; - alSourcePlay(gSourceID[souloutsound]); - game->flashamount = 1.0f; - game->flashr = game->flashg = game->flashb = 1.0f; - alSourceStop(gSourceID[visionsound]); - game->whichsong = mainmenusong; - alSourceStop(gSourceID[knifesong]); - alSourceStop(gSourceID[shootsong]); - alSourceStop(gSourceID[zombiesong]); - alSourceStop(gSourceID[mainmenusong]); - alSourcef(gSourceID[knifesong], AL_MIN_GAIN, 0); - alSourcef(gSourceID[shootsong], AL_MIN_GAIN, 0); - alSourcef(gSourceID[zombiesong], AL_MIN_GAIN, 0); - alSourcef(gSourceID[mainmenusong], AL_MIN_GAIN, 0); - alSourcePlay(gSourceID[game->whichsong]); - alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1); - } } diff --git a/src/GameTick.cpp b/src/GameTick.cpp index 708508e..2e9c71a 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -124,9 +124,6 @@ void Game::updateSong() void Game::handleMenu() { - if (IsKeyDown(GLFW_KEY_SPACE)) - mainmenu = 0; - GetMouse(&mouseloc); float mousex = (float) mouseloc.h * 640 / screenwidth; float mousey = 480 - (float) mouseloc.v * 480 / screenheight; @@ -178,91 +175,6 @@ void Game::handleMenu() } } -void Game::handleToggles() -{ - if (!IsKeyDown(psychickey)) { - oldvisionkey = 0; - } else if (!oldvisionkey) { - oldvisionkey = 1; - if (visions ^= 1) { - flashamount = flashr = 1; - flashg = flashb = 0; - alSourceStop(gSourceID[visionsound]); - alSourcePlay(gSourceID[souloutsound]); - - alSourcef(gSourceID[knifesong], AL_PITCH, 0.5f); - alSourcef(gSourceID[shootsong], AL_PITCH, 0.5f); - alSourcef(gSourceID[zombiesong], AL_PITCH, 0.5f); - alSourcePlay(gSourceID[visionsound]); - bodycoords = person[0].oldplayercoords; - } else { - flashamount = flashr = flashg = flashb = 1; - alSourceStop(gSourceID[visionsound]); - alSourcePlay(gSourceID[soulinsound]); - - alSourcef(gSourceID[knifesong], AL_PITCH, 1.0f); - alSourcef(gSourceID[shootsong], AL_PITCH, 1.0f); - alSourcef(gSourceID[zombiesong], AL_PITCH, 1.0f); - - XYZ towards = person[0].playercoords - bodycoords; - if (towards.x || towards.z) { - Normalise(&towards); - camera.rotation = RadiansToDegrees(asin(towards.x)); - if (towards.z > 0) - camera.rotation = 180 - camera.rotation; - - camera.visrotation = camera.rotation; - camera.oldrotation = camera.rotation; - } - - person[0].playercoords = bodycoords; - person[0].oldplayercoords = bodycoords; - person[0].velocity = 0; - } - } - - if (!IsKeyDown(GLFW_KEY_TAB)) { - tabkeydown = 0; - } else if (!tabkeydown && debug) { - thirdperson++; - if (thirdperson > 2) - thirdperson = 0; - tabkeydown = 1; - } - - if (!IsKeyDown(aimkey)) { - aimtoggle = 0; - } else if (!aimtoggle) { - person[0].aiming ^= aimtoggle = 1; - } - - if (!IsKeyDown(GLFW_KEY_R)) { - reloadtoggle = 0; - } else if (!reloadtoggle) { - if (person[0].reloads[person[0].whichgun] > 0 - && person[0].reloading <= 0) - person[0].ammo=-1; - reloadtoggle = 1; - } - - if (!IsKeyDown(psychicaimkey)) { - slomokeydown = 0; - } else if (!slomokeydown && !slomo) { - flashamount = 0.5; - flashr = 1; - flashg = flashb = 0; - alSourcePlay(gSourceID[souloutsound]); - - slomokeydown = 1; - slomo = 2; - score -= 20; - - alSourcef(gSourceID[knifesong], AL_PITCH, 0.5f); - alSourcef(gSourceID[shootsong], AL_PITCH, 0.5f); - alSourcef(gSourceID[zombiesong], AL_PITCH, 0.5f); - } -} - void Game::mouseLook() { if ((person[0].aimamount <= 0 @@ -470,7 +382,6 @@ void Game::Tick() flatfacing.y = 0; Normalise(&flatfacing); - handleToggles(); mouseLook(); //Check collision with buildings @@ -689,16 +600,6 @@ void Game::Tick() } - if (IsKeyDown(GLFW_KEY_SPACE) - && person[0].playerrotation == person[0].playerlowrotation - && person[0].targetanimation == joganim - && person[0].currentanimation == joganim - && !person[0].backwardsanim && !visions) { - person[0].targetanimation = diveanim; - person[0].targetframe = person[0].target = 0; - person[0].aimamount = 0; - } - //Camera camera.oldposition=camera.position; camera.targetoffset=0; @@ -2136,8 +2037,7 @@ void Game::Tick() } XYZ end {start + aim * 1000}; - if (debug && j == 0 - && IsKeyDown(GLFW_KEY_G)) { + if (debug && j == 0 && IsKeyDown(GLFW_KEY_G)) { sprites.MakeSprite(grenadesprite, 1, 1, 1, 1, start, aim * 200, 1.01); continue; |