diff options
-rw-r--r-- | src/Game.h | 4 | ||||
-rw-r--r-- | src/GameInitDispose.cpp | 1 | ||||
-rw-r--r-- | src/GameTick.cpp | 410 | ||||
-rw-r--r-- | src/PhysicsMath.h | 6 |
4 files changed, 134 insertions, 287 deletions
diff --git a/src/Game.h b/src/Game.h index 154fbc3..69289d7 100644 --- a/src/Game.h +++ b/src/Game.h @@ -54,7 +54,8 @@ class Game { void saveHighScore(); void updateSong(); - void handleMenu(); + void handleMenu(unsigned char*); + void handleToggles(unsigned char*); public: // Event loop Boolean gQuit; @@ -171,7 +172,6 @@ public: int murderer; float timeremaining; int whichsong; - int oldscore; int highscore; int score; int mission; diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index 9a0435d..8a56e73 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -2127,7 +2127,6 @@ void Game::InitGame() decals.howmanydecals=0; sprites.howmanysprites=0; losedelay=1; - oldscore=score; } int Game::InitGL(void) diff --git a/src/GameTick.cpp b/src/GameTick.cpp index 697d799..0d13e2d 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -116,10 +116,8 @@ void Game::updateSong() alSourcePlay(gSourceID[whichsong]); } -void Game::handleMenu() +void Game::handleMenu(unsigned char* theKeyMap) { - unsigned char theKeyMap[16]; - GetKeys((unsigned long*) theKeyMap); if (IsKeyDown(theKeyMap, MAC_SPACE_KEY)) mainmenu = 0; @@ -173,305 +171,165 @@ void Game::handleMenu() } } -void Game::Tick() +void Game::handleToggles(unsigned char* theKeyMap) { - if (mainmenu) { - handleMenu(); - return; - } + if (!IsKeyDown(theKeyMap, psychickey)) { + oldvisionkey = 0; + } else if (!oldvisionkey) { + oldvisionkey = 1; + if (visions ^= 1) { + flashamount = flashr = 1; + flashg = flashb = 0; + alSourceStop(gSourceID[visionsound]); + alSourcePlay(gSourceID[souloutsound]); - XYZ facing; - XYZ flatfacing; + 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]); - if(person[1].health<=0||person[0].health<=0||killedinnocent){ - losedelay-=multiplier/6; - } + alSourcef(gSourceID[knifesong], AL_PITCH, 1.0f); + alSourcef(gSourceID[shootsong], AL_PITCH, 1.0f); + alSourcef(gSourceID[zombiesong], AL_PITCH, 1.0f); - if(person[1].health>0&&person[0].health>0&&!killedinnocent)timeremaining-=multiplier*25/40; + 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; - if(timeremaining<=0){ + camera.visrotation = camera.rotation; + camera.oldrotation = camera.rotation; + camera.oldoldrotation = camera.rotation; + } - flashamount=1; + person[0].playercoords = bodycoords; + person[0].oldplayercoords = bodycoords; + person[0].velocity = 0; + } + } + + if (!IsKeyDown(theKeyMap, MAC_TAB_KEY)) { + tabkeydown = 0; + } else if (!tabkeydown && debug) { + thirdperson++; + if (thirdperson > 2) + thirdperson = 0; + tabkeydown = 1; + } - flashr=0;flashg=1;flashb=0; + if (!IsKeyDown(theKeyMap, aimkey)) { + aimtoggle = 0; + } else if (!aimtoggle) { + person[0].aiming ^= aimtoggle = 1; + } - mission++; + if (!IsKeyDown(theKeyMap, MAC_R_KEY)) { + 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(theKeyMap, psychicaimkey)) { + slomokeydown = 0; + } else if (!slomokeydown && !slomo) { + flashamount = 0.5; + flashr = 1; + flashg = flashb = 0; alSourcePlay(gSourceID[souloutsound]); - score+=100+(mission*50); + slomokeydown = 1; + slomo = 2; + score -= 20; - if(mission>=nummissions){ + alSourcef(gSourceID[knifesong], AL_PITCH, (ALfloat)(.5)); + alSourcef(gSourceID[shootsong], AL_PITCH, (ALfloat)(.5)); + alSourcef(gSourceID[zombiesong], AL_PITCH, (ALfloat)(.5)); + } +} + +void Game::Tick() +{ + unsigned char theKeyMap[16]; + GetKeys((unsigned long*) theKeyMap); + if (mainmenu) { + handleMenu(theKeyMap); + return; + } - beatgame=1; + XYZ facing; + XYZ flatfacing; - mainmenu=1; + if (person[1].health <= 0 || person[0].health <= 0 || killedinnocent) + losedelay -= multiplier / 6; + else + timeremaining -= multiplier * 25 / 40; - gameinprogress=0; + if (timeremaining <= 0) { + score += ++mission * 50 + 100; - alSourcePause(gSourceID[rainsound]); + flashamount = flashg = 1; + flashr = flashb = 0; + alSourcePlay(gSourceID[souloutsound]); + if (mission >= nummissions) { + alSourcePause(gSourceID[rainsound]); alSourceStop(gSourceID[visionsound]); - alSourceStop(gSourceID[whichsong]); - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0); - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 0); - whichsong=mainmenusong; - - alSourceStop(gSourceID[whichsong]); - + whichsong = mainmenusong; alSourcef(gSourceID[whichsong], AL_PITCH, 1); - - alSourcePlay(gSourceID[whichsong]); - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1); - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1); + alSourcePlay(gSourceID[whichsong]); + mainmenu = beatgame = 1; + gameinprogress = 0; saveHighScore(); - } - - if(!mainmenu){ - + } else { + updateSong(); InitGame(); - - if(environment==rainy_environment)alSourcePlay(gSourceID[rainsound]); - - if(environment!=rainy_environment)alSourcePause(gSourceID[rainsound]); - - alSourceStop(gSourceID[visionsound]); - - alSourceStop(gSourceID[whichsong]); - - if(person[0].whichgun==knife)whichsong=knifesong; - - if(person[0].whichgun!=knife)whichsong=shootsong; - - if(type==zombie_type)whichsong=zombiesong; - - alSourcef(gSourceID[whichsong], AL_PITCH, 1); - - alSourcePlay(gSourceID[whichsong]); - - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1); - - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1); - } - } - if(losedelay<=0){ - - flashamount=1; - - flashr=0;flashg=0;flashb=0; - - if(person[murderer].health>0)score=oldscore-200; - - if(person[murderer].health<=0)score=oldscore-100; - - InitGame(); - - alSourceStop(gSourceID[whichsong]); - - if(person[0].whichgun==knife)whichsong=knifesong; - - if(person[0].whichgun!=knife)whichsong=shootsong; - - if(type==zombie_type)whichsong=zombiesong; - - alSourcef(gSourceID[whichsong], AL_PITCH, 1); - - alSourcePlay(gSourceID[whichsong]); - - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1); - - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1); + if (losedelay <= 0) { + score -= (person[murderer].health > 0) ? 200 : 100; + flashamount = 1; + flashr = flashg = flashb = 0; alSourcePlay(gSourceID[soulinsound]); + updateSong(); + InitGame(); } - unsigned char theKeyMap[16]; - - GetKeys( ( unsigned long * )theKeyMap ); - - //Sprites - sprites.DoStuff(); - - //Decals - decals.DoStuff(); - //Facing - - facing=0; - - facing.z=-1; - - facing=DoRotation(facing,-camera.rotation2,0,0); - - facing=DoRotation(facing,0,0-camera.rotation,0); - - flatfacing=facing; - - flatfacing.y=0; + // Facing + facing = 0; + facing.z = -1; + facing = DoRotation(facing, -camera.rotation2, 0, 0); + facing = DoRotation(facing, 0, 0 - camera.rotation, 0); + flatfacing = facing; + flatfacing.y = 0; Normalise(&flatfacing); - if(IsKeyDown(theKeyMap, psychickey)&&!oldvisionkey){ - - oldvisionkey=1; - - visions++; - - if(visions==2)visions=0; - - if(visions==0){ - flashamount=1; - flashr=1;flashg=1;flashb=1; - - if(person[0].playercoords.x!=bodycoords.x||person[0].playercoords.z!=bodycoords.z){ - - XYZ towards; - - towards=person[0].playercoords-bodycoords; - - Normalise(&towards); - - camera.rotation=-asin(0-towards.x); - - camera.rotation*=360/6.28; - - if(towards.z>0)camera.rotation=180-camera.rotation; - - camera.visrotation=camera.rotation; - - camera.oldrotation=camera.rotation; - - camera.oldoldrotation=camera.rotation; - - } - - person[0].playercoords=bodycoords; - - person[0].oldplayercoords=bodycoords; - - person[0].velocity=0; - - alSourcePlay(gSourceID[soulinsound]); - - alSourceStop(gSourceID[visionsound]); - - alSourcef(gSourceID[knifesong], AL_PITCH, (ALfloat)(1)); - - alSourcef(gSourceID[shootsong], AL_PITCH, (ALfloat)(1)); - - alSourcef(gSourceID[zombiesong], AL_PITCH, (ALfloat)(1)); - - } - - if(visions==1){ - - alSourceStop(gSourceID[visionsound]); - - flashamount=1; - - flashr=1;flashg=0;flashb=0; - - bodycoords=person[0].oldplayercoords; - - alSourcePlay(gSourceID[souloutsound]); - - alSourcef(gSourceID[knifesong], AL_PITCH, (ALfloat)(.5)); - - alSourcef(gSourceID[shootsong], AL_PITCH, (ALfloat)(.5)); - - alSourcef(gSourceID[zombiesong], AL_PITCH, (ALfloat)(.5)); - - alSourcePlay(gSourceID[visionsound]); - - } - - } - - if(!IsKeyDown(theKeyMap, psychickey)){ - - oldvisionkey=0; - - } - - if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!tabkeydown&&debug){ - - thirdperson++; - - if(thirdperson>2)thirdperson=0; - - tabkeydown=1; - - } - - if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)) - - tabkeydown=0; - - if(IsKeyDown(theKeyMap, aimkey)&&!aimtoggle){ - - person[0].aiming=1-person[0].aiming; - - aimtoggle=1; - - } - - if(!IsKeyDown(theKeyMap, aimkey)) - - aimtoggle=0; - - if(IsKeyDown(theKeyMap, MAC_R_KEY)&&!reloadtoggle){ - - if(person[0].reloads[person[0].whichgun]>0&&person[0].reloading<=0)person[0].ammo=-1; - - reloadtoggle=1; - - } - - if(!IsKeyDown(theKeyMap, MAC_R_KEY)) - - reloadtoggle=0; - - if(IsKeyDown(theKeyMap, psychicaimkey)&&!slomokeydown&&slomo==0){ - - alSourcePlay(gSourceID[souloutsound]); - - slomo=2; - - flashamount=.5; - - flashr=1;flashg=0;flashb=0; - - slomokeydown=1; - - score-=20; - - alSourcef(gSourceID[knifesong], AL_PITCH, (ALfloat)(.5)); - - alSourcef(gSourceID[shootsong], AL_PITCH, (ALfloat)(.5)); - - alSourcef(gSourceID[zombiesong], AL_PITCH, (ALfloat)(.5)); - - } - - if(!IsKeyDown(theKeyMap, psychicaimkey)) - - slomokeydown=0; - - //Mouse look + handleToggles(theKeyMap); + // Mouse look if((person[0].aimamount<=0&&person[0].targetanimation!=crouchanim)){ camera.rotation=camera.visrotation; @@ -808,20 +666,14 @@ void Game::Tick() } - if(IsKeyDown( theKeyMap, MAC_SPACE_KEY )){ - - if(visions==0&&person[0].targetanimation==joganim&&person[0].currentanimation==joganim&&person[0].backwardsanim==0&&person[0].playerrotation==person[0].playerlowrotation){ - - person[0].targetanimation=diveanim; - - person[0].targetframe=0; - - person[0].target=0; - - person[0].aimamount=0; - - } - + if (IsKeyDown(theKeyMap, MAC_SPACE_KEY) + && 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 @@ -3881,12 +3733,12 @@ void Game::Tick() upvector=DoRotation(upvector,0,0-camera.rotation,0); float ori[6]; - ori[0] = -facing.x; - ori[1] = facing.y; - ori[2] = facing.z; - ori[3] = -upvector.x; - ori[4] = upvector.y; - ori[5] = upvector.z; + ori[0] = -facing.x; + ori[1] = facing.y; + ori[2] = facing.z; + ori[3] = -upvector.x; + ori[4] = upvector.y; + ori[5] = upvector.z; alListenerfv(AL_ORIENTATION, ori); if(person[0].currentanimation==throwanim||person[0].currentanimation==diveanim||paused){ diff --git a/src/PhysicsMath.h b/src/PhysicsMath.h index 758931b..7eb13c5 100644 --- a/src/PhysicsMath.h +++ b/src/PhysicsMath.h @@ -12,7 +12,7 @@ //------------------------------------------------------------------------// -float const pi = 3.14159265f; +const float pi = acosf(-1); float const g = -32.174f; // acceleration due to gravity, ft/s^2 @@ -31,17 +31,13 @@ inline float DegreesToRadians(float deg); inline float RadiansToDegrees(float rad); inline float DegreesToRadians(float deg) - { return deg * pi / 180.0f; } inline float RadiansToDegrees(float rad) - { - return rad * 180.0f / pi; - } //------------------------------------------------------------------------// |