aboutsummaryrefslogtreecommitdiff
path: root/src/GameTick.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-07-24 20:09:39 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-07-24 20:09:39 +0700
commit2cd872fd9ec311673f9d48c9043101c84182492a (patch)
treee9db1d2b63e3a1e43e1ac39577f642bd3b987da1 /src/GameTick.cpp
parent1fcb480ed59b6a1646b7fa5170b33b9bcaa47a0e (diff)
downloadblackshades-2cd872fd9ec311673f9d48c9043101c84182492a.tar.gz
Refactor menu handling
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r--src/GameTick.cpp250
1 files changed, 111 insertions, 139 deletions
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){