diff options
-rw-r--r-- | .build.yml | 1 | ||||
-rw-r--r-- | src/GameInitDispose.cpp | 219 | ||||
-rw-r--r-- | src/GameLoop.cpp | 1 | ||||
-rw-r--r-- | src/GameTick.cpp | 109 |
4 files changed, 53 insertions, 277 deletions
diff --git a/.build.yml b/.build.yml index 9c7016d..9475eb6 100644 --- a/.build.yml +++ b/.build.yml @@ -6,6 +6,7 @@ packages: - openal - sdl - stb + - zig sources: - https://git.sr.ht/~cnx/blackshades tasks: diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index c11f3c1..f71cc02 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -475,113 +475,60 @@ void Game::InitGame() killedinnocent=0; //Haven't shot any civilians yet... if(customlevels){ //Load custom levels - nummissions=1; //Default level in case of load failure - type=randomshoot_type; - possiblegun[0]=handgun1; - possiblegun[1]=handgun2; - possiblegun[2]=shotgun; - numpossibleguns=3; - evilprobability=6; - person[0].whichgun=knife; - person[0].reloads[person[0].whichgun]=6; - if(!gameinprogress)score=0; - timeremaining=50; - difficulty=.8; + ifstream ipstream {"Data/customlevels.txt"}; - ifstream ipstream("Data/customlevels.txt"); - - if(!ipstream) { - - customlevels=0; - - } - - if(ipstream){ - + if (ipstream) { ipstream.ignore(256,'\n');//ignore descriptive text - - ipstream >> nummissions; - - for(int j=0;j<mission+1;j++){ - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> type; - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> environment; - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> numpossibleguns; - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - for(int i=0;i<numpossibleguns;i++){ - - ipstream >> possiblegun[i]; - - } - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> evilprobability; - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> person[0].whichgun; - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> person[0].reloads[person[0].whichgun]; - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> timeremaining; - - ipstream.ignore(256,'\n'); - - ipstream.ignore(256,'\n'); - - ipstream >> difficulty; - - ipstream.ignore(256,'\n'); - - } - - ipstream.close(); - + ipstream >> nummissions; + for(int j = 0; j < mission + 1; j++) { + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> type; + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> environment; + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> numpossibleguns; + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + + for (int i = 0 ;i < numpossibleguns; i++) + ipstream >> possiblegun[i]; + + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> evilprobability; + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> person[0].whichgun; + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> person[0].reloads[person[0].whichgun]; + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> timeremaining; + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> difficulty; + ipstream.ignore(256,'\n'); + } + ipstream.close(); + } else { + customlevels=0; } - } if(!customlevels){ //Setup hardcoded default levels @@ -1142,33 +1089,24 @@ void Game::InitGame() if(!initialized)LoadingScreen(loadingscreenamount/loadingscreenamounttotal*100); path.load((unsigned char *)":Data:Models:path.solid"); - path.Rotate(90,0,0); - path.Scale(.8,.8,.8); - path.CalculateNormals(); - //Fix block radius - - for(int i=0;i<4;i++){ - - blocks[i].boundingspherecenter.x=0; - - blocks[i].boundingspherecenter.z=0; - - blocks[i].boundingsphereradius=0; - - for(int x=0;i<blocks[x].vertexNum;x++){ - - if(findDistancefast(blocks[i].boundingspherecenter,blocks[i].vertex[x])>blocks[i].boundingsphereradius)blocks[i].boundingsphereradius=findDistancefast(blocks[i].boundingspherecenter,blocks[i].vertex[x]); - + // Fix block radius + for (int i = 0; i < 4; i++) { + auto center = blocks[i].boundingspherecenter; + center.x = center.y = center.z = 0; + + float radiusqr = 0.0; + for (int x = 0; x < blocks[i].vertexNum; x++) { + auto distance = findDistancefast(center, + blocks[i].vertex[x]); + if (distance > radiusqr) + radiusqr = distance; } - - blocks[i].boundingsphereradius=sqrt(blocks[i].boundingsphereradius); - + blocks[i].boundingsphereradius = sqrt(radiusqr); } - } mousesensitivity=1; @@ -2120,101 +2058,56 @@ void Game::InitGame() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //light - GLfloat LightAmbient[]= { .3, .3, .3, 1.0f}; - GLfloat LightDiffuse[]= { 1, 1, 1, 1.0f }; - glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient); - glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse); - glEnable(GL_LIGHT0); - loadingscreenamount+=5; //Load some textures - if(!initialized){ - LoadingScreen(loadingscreenamount/loadingscreenamounttotal*100); - LoadPersonSpriteTexture(":Data:Textures:Personsprite.png",&personspritetextureptr); - LoadPersonSpriteTexture(":Data:Textures:DeadPersonsprite.png",&deadpersonspritetextureptr); - LoadPersonSpriteTexture(":Data:Textures:Scope.png",&scopetextureptr); - LoadPersonSpriteTexture(":Data:Textures:Flare.png",&flaretextureptr); - sprites.LoadFlareTexture(":Data:Textures:HitFlash.png"); - sprites.LoadMuzzleFlareTexture(":Data:Textures:MuzzleFlash.png"); - sprites.LoadSmokeTexture(":Data:Textures:Smoke.png"); - sprites.LoadBloodTexture(":Data:Textures:Blood.png"); - sprites.LoadRainTexture(":Data:Textures:rain.png"); - sprites.LoadSnowTexture(":Data:Textures:snow.png"); - decals.LoadBulletHoleTexture(":Data:Textures:BulletHole.png"); - decals.LoadCraterTexture(":Data:Textures:Crater.png"); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood1.png",0); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood2.png",1); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood3.png",2); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood4.png",3); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood5.png",4); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood6.png",5); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood7.png",6); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood8.png",7); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood9.png",8); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood10.png",9); - decals.LoadBloodTexture(":Data:Textures:Blood:Blood11.png",10); - } //Setup clip plane equation - eqn[0]=0; - eqn[1]=1; - eqn[2]=0; - eqn[3]=0; - glClearColor(fogcolorr,fogcolorg,fogcolorb,1); if(!initialized)InitMouse(); - //Draw city one frame to fix evil menu bug - if(!initialized)mainmenu=2; - if(!initialized){ - LoadingScreen(loadingscreenamount/loadingscreenamounttotal*100); - flashamount=1; - flashr=1;flashg=1;flashb=1; - alSourcePlay(gSourceID[soulinsound]); - } initialized=1; @@ -2225,27 +2118,17 @@ void Game::InitGame() GLint swapInt = 1; /* - for(int i=0;i<sprites.howmanysprites;i++){ - sprites.DeleteSprite(0); - } - for(int i=0;i<decals.howmanydecals;i++){ - decals.DeleteDecal(0); - }*/ decals.howmanydecals=0; - sprites.howmanysprites=0; - losedelay=1; - oldscore=score; - } /*********************> InitGL() <*****/ diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index fe7292f..3a9e8a0 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -346,6 +346,7 @@ void Game::EventLoop( void ) int colaccuracy,i; GLfloat oldmult; gQuit = false; + framespersecond = 60; while ( gQuit == false ) { ProcessSDLEvents(this); start=TimerGetTime(&theTimer); diff --git a/src/GameTick.cpp b/src/GameTick.cpp index 045f903..3350634 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -1,51 +1,28 @@ #include "Game.h" extern double multiplier; - extern int thirdperson; - extern int visions; - extern Sprites sprites; - extern unsigned int gSourceID[100]; - extern unsigned int gSampleSet[100]; - extern Camera camera; - extern float camerashake; - extern Fog fog; - extern int environment; - extern float precipitationhorz; - extern float precipitationvert; - extern float snowdelay; - extern float precipitationdensity; - extern float soundscalefactor; - extern int slomo; - extern int forwardskey; - extern int backwardskey; - extern int leftkey; - extern int rightkey; - extern int aimkey; - extern int psychicaimkey; - extern int psychickey; - extern Decals decals; /********************> Tick() <*****/ @@ -54,58 +31,35 @@ extern Decals decals; void Game::Splat(int k){ if(k!=0||visions==0){ - person[k].health=0; - person[k].DoAnimations(k); - person[k].skeleton.offset=0; - person[k].skeleton.free=1; - person[k].longdead=1; - person[k].bleeding=1; - person[k].bleeddelay=1; - person[k].bjoint1=&person[k].skeleton.joints[person[k].skeleton.jointlabels[head]]; - person[k].bjoint2=&person[k].skeleton.joints[person[k].skeleton.jointlabels[neck]]; for(int j=0;j<person[k].skeleton.num_joints;j++){ - person[k].skeleton.joints[j].position+=person[k].skeleton.joints[j].offset; - person[k].skeleton.joints[j].position=DoRotation(person[k].skeleton.joints[j].position,0,person[k].playerrotation,0); - person[k].skeleton.joints[j].position+=person[k].playercoords; - person[k].skeleton.joints[j].realoldposition=person[k].skeleton.joints[j].position; - person[k].skeleton.joints[j].velocity=0; - person[k].skeleton.joints[j].velocity.y+=person[k].velocity.y; } float gLoc[3]; - gLoc[0]=person[k].skeleton.joints[person[k].skeleton.jointlabels[head]].position.x/soundscalefactor; - gLoc[1]=person[k].skeleton.joints[person[k].skeleton.jointlabels[head]].position.y/soundscalefactor; - gLoc[2]=person[k].skeleton.joints[person[k].skeleton.jointlabels[head]].position.z/soundscalefactor; - alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[headwhacksound]); - } - } void Game::Tick(){ - if(mainmenu){ unsigned char theKeyMap[16]; @@ -4401,13 +4355,10 @@ void Game::Tick(){ } //camera shake - camerashake-=multiplier; - if(camerashake<0)camerashake=0; //camera position - XYZ average; if(!zoom)average=person[0].skeleton.joints[(person[0].skeleton.jointlabels[head])].position*(person[0].aimamount/2+.5)+person[0].skeleton.joints[(person[0].skeleton.jointlabels[neck])].position*((1-person[0].aimamount)/2); @@ -4423,145 +4374,85 @@ void Game::Tick(){ if(camera.position.y<.1)camera.position.y=.1; if(thirdperson!=2){ - oldrot=camera.visrotation; - oldrot2=camera.visrotation2; - } //Kill count - for(int i=0;i<numpeople;i++){ - if(person[i].oldhealth>0&&person[i].health<=0){ - if(i==1)alSourcePlay(gSourceID[losesound]); - if(person[i].type==civiliantype){ - alSourcePlay(gSourceID[disguisekillsound]); - score-=300; - } if(person[i].type==eviltype){ - alSourcePlay(gSourceID[soulinsound]); - score+=75; - if(person[i].whichgun==knife)score+=50; - } - person[i].firstlongdead=0; - } - person[i].oldhealth=person[i].health; - } if(slomo==2){ - psychicpower-=multiplier*15; - if(psychicpower<0){ - soundscalefactor=soundscalefactordefault; - alSourceStop(gSourceID[whichsong]); - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0); - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 0); - 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); - slomo=0; - alSourcePlay(gSourceID[soulinsound]); - psychicpower=0; - flashamount=.5; - flashr=1;flashg=1;flashb=1; - } - } psychicpower+=multiplier*5; - if(psychicpower>10)psychicpower=10; //3d sound float gLoc[3]; - gLoc[0]=camera.position.x/soundscalefactor; - gLoc[1]=camera.position.y/soundscalefactor; - gLoc[2]=camera.position.z/soundscalefactor; //Set listener position - alListenerfv(AL_POSITION, gLoc); //Set orientation with forward and up vectors - XYZ upvector; - upvector=0; - upvector.z=-1; - upvector=DoRotation(upvector,-camera.rotation2+90,0,0); - 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; - alListenerfv(AL_ORIENTATION, ori); if(person[0].currentanimation==throwanim||person[0].currentanimation==diveanim||paused){ - MoveMouse(oldmouseloc.h,oldmouseloc.v,&mouseloc); - GetMouse(&mouseloc); - } oldmouseloc=mouseloc; - if(score<0)score=0; - } } |