summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--src/Game.h3
-rw-r--r--src/GameTick.cpp250
3 files changed, 117 insertions, 141 deletions
diff --git a/README.md b/README.md
index e9fcae5..416a0c0 100644
--- a/README.md
+++ b/README.md
@@ -139,5 +139,6 @@ sniper rifle, handgun, shotgun and grenade.
 David Rosen's other friends and beta testers also helped
 during the early phases of development.
 
-Black Shades was ported to other operating systems by relnev,
-theoddone33, icculus and zakk.  The Bug was fixed by Toby Haynes.
+Black Shades was ported to other operating systems by Steven "relnev" Fuller,
+Dan "theoddone33" Olson, Ryan "icculus" Gordon and Zachary "zakk" Jack Slater.
+The Bug was fixed by Toby Haynes.
diff --git a/src/Game.h b/src/Game.h
index 60b745f..8d3d7fc 100644
--- a/src/Game.h
+++ b/src/Game.h
@@ -32,6 +32,9 @@
 
 class Game
 {
+		void saveHighScore();
+		void updateSong();
+		void handleMenu();
 	public:
 		//Eventloop
   		Boolean	gQuit;
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index b7d0d64..a0534a7 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -1,3 +1,25 @@
+// Game tick handling
+// Copyright (C) 2002  David Rosen
+// Copyright (C) 2003  Dan Olson
+// Copyright (C) 2003  Steven Fuller
+// Copyright (C) 2003  Zachary Jack Slater
+// Copyright (C) 2021  Nguyễn Gia Phong
+//
+// This file is part of Black Shades.
+//
+// Black Shades is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Black Shades is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
+
 #include "Game.h"
 
 extern double multiplier;
@@ -57,150 +79,108 @@ void Game::Splat(int k){
 	}
 }
 
-void Game::Tick()
+void Game::saveHighScore()
 {
-	if (mainmenu) {
-		unsigned char theKeyMap[16];
-		GetKeys((unsigned long*) theKeyMap);
-		if (IsKeyDown(theKeyMap, MAC_SPACE_KEY))
-			mainmenu = 0;
-
-		GetMouse(&mouseloc);
-		float mousex = (float) mouseloc.h * 640 / screenwidth;
-		float mousey = 480 - (float) mouseloc.v * 480 / screenheight;
-
-		oldmouseoverbutton = mouseoverbutton;
-		mouseoverbutton = 0;
-		if (mousex > 120 && mousex < 560) {
-			if (mousey > 235 && mousey < 305)
-				mouseoverbutton = 1;
-			else if (mousey > 112 && mousey < 182)
-				mouseoverbutton = 2;
-		}
-
-		if((Button()&&mouseoverbutton==1&&!gameinprogress&&!oldbutton)||!mainmenuness){
-
-			if(environment==rainy_environment)alSourcePlay(gSourceID[rainsound]);
-
-			if(environment!=rainy_environment)alSourcePause(gSourceID[rainsound]);
-
-			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);
-
-			flashamount=1;
-
-			flashr=1;flashg=1;flashb=1;
+	if (score > highscore) {
+		highscore = score;
+		/* TODO */
+		ofstream opstream("Data/Highscore");
+		opstream << highscore;
+		opstream << "\n";
+		opstream << beatgame;
+		opstream.close();
+	}
+}
 
-			mainmenu=0;
+void Game::updateSong()
+{
+	if (environment == rainy_environment)
+		alSourcePlay(gSourceID[rainsound]);
+	else
+		alSourcePause(gSourceID[rainsound]);
+
+	alSourceStop(gSourceID[whichsong]);
+	alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0);
+	alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 0);
+
+	if (type == zombie_type)
+		whichsong = zombiesong;
+	else if (person[0].whichgun == knife)
+		whichsong = knifesong;
+	else
+		whichsong = shootsong;
+
+	alSourcef(gSourceID[whichsong], AL_PITCH, 1);
+	alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1);
+	alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1);
+	alSourcePlay(gSourceID[whichsong]);
+}
 
-			alSourcePlay(gSourceID[soulinsound]);
+void Game::handleMenu()
+{
+	unsigned char theKeyMap[16];
+	GetKeys((unsigned long*) theKeyMap);
+	if (IsKeyDown(theKeyMap, MAC_SPACE_KEY))
+		mainmenu = 0;
+
+	GetMouse(&mouseloc);
+	float mousex = (float) mouseloc.h * 640 / screenwidth;
+	float mousey = 480 - (float) mouseloc.v * 480 / screenheight;
+
+	oldmouseoverbutton = mouseoverbutton;
+	mouseoverbutton = 0;
+	if (mousex > 120 && mousex < 560 && Button() && !oldbutton) {
+		if (mousey > 235 && mousey < 305)
+			mouseoverbutton = 1;
+		else if (mousey > 112 && mousey < 182)
+			mouseoverbutton = 2;
+	} else if (!mainmenuness) {
+		mouseoverbutton = 1;
+	}
+	oldbutton = Button();
 
-			mission=0;
+	switch (mouseoverbutton) {
+	case 1:
+		updateSong();
+		flashamount = flashr = flashg = flashb = 1;
+		alSourcePlay(gSourceID[soulinsound]);
 
+		if (!gameinprogress) {
+			mission = 0;
 			InitGame();
-
-			gameinprogress=1;
-
-		}
-
-		if((Button()&&mouseoverbutton==1&&gameinprogress&&!oldbutton)||!mainmenuness){
-
-			flashamount=1;
-
-			flashr=1;flashg=1;flashb=1;
-
-			mainmenu=0;
-
-			MoveMouse(oldmouseloc.h,oldmouseloc.v,&mouseloc);
-
-			//if(!visions){
-
-				if(environment==rainy_environment)alSourcePlay(gSourceID[rainsound]);
-
-				if(environment!=rainy_environment)alSourcePause(gSourceID[rainsound]);
-
-				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;
-
-				alSourcePlay(gSourceID[whichsong]);
-
-				alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1);
-
-				alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1);
-
-			//}
-
-			alSourcePlay(gSourceID[soulinsound]);
-
-			if(visions)alSourcePlay(gSourceID[visionsound]);
-
 		}
 
-		if(Button()&&mouseoverbutton==2&&!gameinprogress&&!oldbutton){
-			flashamount=1;
-			flashr=1;flashg=0;flashb=0;
-			alSourcePlay(gSourceID[losesound]);
+		MoveMouse(oldmouseloc.h, oldmouseloc.v, &mouseloc);
+		if (visions)
+			alSourcePlay(gSourceID[visionsound]);
+
+		gameinprogress = 1;
+		mainmenu = 0;
+		break;
+	case 2:
+		if (gameinprogress) {
+			flashamount = flashr = flashg = flashb = 1;
+			gameinprogress = 0;
+		} else {
+			flashamount = flashr = 1;
+			flashg = flashb = 0;
 			gQuit = true;
-			if(score>highscore){
-				highscore=score;
-				/* TODO */
-				ofstream opstream("Data/Highscore");
-				opstream << highscore;
-				opstream << "\n";
-				opstream << beatgame;
-				opstream.close();
-			}
 		}
 
-		if(Button()&&mouseoverbutton==2&&gameinprogress&&!oldbutton){
-			flashamount=1;
-			flashr=1;flashg=1;flashb=1;
-			alSourcePlay(gSourceID[losesound]);
-			gameinprogress=0;
-			if(score>highscore){
-				highscore=score;
-				/* TODO */
-				ofstream opstream("Data/Highscore");
-				opstream << highscore;
-				opstream << "\n";
-				opstream << beatgame;
-				opstream.close();
-			}
-		}
-
-		if(Button())oldbutton=1;
-
-		if(!Button())oldbutton=0;
+		alSourcePlay(gSourceID[losesound]);
+		saveHighScore();
+		break;
+	}
+}
 
+void Game::Tick()
+{
+	if (mainmenu) {
+		handleMenu();
+		return;
 	}
 
-	if(!mainmenu){
+	if (!mainmenu) {
 		XYZ facing;
 		XYZ flatfacing;
 
@@ -252,15 +232,7 @@ void Game::Tick()
 
 				alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1);
 
-				if(score>highscore){
-					highscore=score;
-					/* TODO */
-					ofstream opstream("Data/Highscore");
-					opstream << highscore;
-					opstream << "\n";
-					opstream << beatgame;
-					opstream.close();
-				}
+				saveHighScore();
 			}
 
 			if(!mainmenu){