about summary refs log tree commit diff
path: root/src/GameTick.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2023-11-19 05:08:01 +0900
committerNguyễn Gia Phong <cnx@loang.net>2023-11-19 05:08:01 +0900
commite68d3ee2380dba98a72f2668a2c2664fc993bb4a (patch)
tree8aaabd3bc11b16b31c67fe2667ad8a6542327ef1 /src/GameTick.cpp
parentdb730f01951231196cac36630d043c7a3676d446 (diff)
downloadblackshades-e68d3ee2380dba98a72f2668a2c2664fc993bb4a.tar.gz
Fix off-by-one music selection
Fixes: https://todo.sr.ht/~cnx/blackshades/25
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r--src/GameTick.cpp57
1 files changed, 20 insertions, 37 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 75bcc9d..a449ae2 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -90,22 +90,18 @@ void updateSong(Game* game)
 	if (environment == rainy_environment)
 		alSourcePlay(gSourceID[rainsound]);
 	else
-		alSourcePause(gSourceID[rainsound]);
+		alSourceStop(gSourceID[rainsound]);
 
+	if (!game->musictoggle)
+		return;
 	alSourceStop(gSourceID[game->whichsong]);
-	alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 0);
-	alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 0);
-
 	if (game->type == zombie_type)
 		game->whichsong = zombiesong;
 	else if (game->person[0].whichgun == knife)
 		game->whichsong = knifesong;
 	else
 		game->whichsong = shootsong;
-
 	alSourcef(gSourceID[game->whichsong], AL_PITCH, 1);
-	alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1);
-	alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 1);
 	alSourcePlay(gSourceID[game->whichsong]);
 }
 
@@ -136,7 +132,6 @@ void click(Game* game, int button, int action, int mods)
 
 		switch (game->mouseoverbutton) {
 		case 1:
-			updateSong(game);
 			game->flashr = game->flashg = game->flashb = 1.0f;
 			game->flashamount = 1.0f;
 			alSourcePlay(gSourceID[soulinsound]);
@@ -146,6 +141,7 @@ void click(Game* game, int button, int action, int mods)
 				initGame(game);
 			}
 
+			updateSong(game);
 			if (visions)
 				alSourcePlay(gSourceID[visionsound]);
 
@@ -443,23 +439,19 @@ void nextLevel(Game* game)
 	alSourcePlay(gSourceID[souloutsound]);
 
 	if (game->mission >= game->nummissions) {
-		alSourcePause(gSourceID[rainsound]);
+		alSourceStop(gSourceID[rainsound]);
 		alSourceStop(gSourceID[visionsound]);
-		alSourceStop(gSourceID[game->whichsong]);
-		alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 0);
-		alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 0);
-
-		game->whichsong = mainmenusong;
-		alSourcef(gSourceID[game->whichsong], AL_PITCH, 1);
-		alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1);
-		alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 1);
-		alSourcePlay(gSourceID[game->whichsong]);
-
+		if (game->musictoggle) {
+			alSourceStop(gSourceID[game->whichsong]);
+			game->whichsong = mainmenusong;
+			alSourcef(gSourceID[game->whichsong], AL_PITCH, 1);
+			alSourcePlay(gSourceID[game->whichsong]);
+		}
 		setMenu(game, game->beatgame = true);
 		game->gameinprogress = 0;
 	} else {
-		updateSong(game);
 		initGame(game);
+		updateSong(game);
 	}
 }
 
@@ -994,8 +986,8 @@ void Game::Tick()
 		flashr = flashg = flashb = 0;
 		alSourcePlay(gSourceID[soulinsound]);
 
-		updateSong(this);
 		initGame(this);
+		updateSong(this);
 	}
 
 	spawnNpc(this);
@@ -2404,24 +2396,15 @@ hit_terrain:
 		person[i].oldhealth=person[i].health;
 	}
 
-	if(slomo==2){
-		psychicpower-=multiplier*15;
-		if(psychicpower<0){
-			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;
+	if (slomo == 2) {
+		psychicpower -= multiplier*15;
+		if (psychicpower < 0) {
 			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;
+			slomo = 0;
 			alSourcePlay(gSourceID[soulinsound]);
-			psychicpower=0;
-			flashamount=.5;
-			flashr=1;flashg=1;flashb=1;
+			psychicpower = 0;
+			flashamount = 0.5f;
+			flashr = flashg = flashb = 1.0f;
 		}
 	}