about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-07 04:25:50 -0400
committerCharadon <dev@iotib.net>2022-06-07 04:25:50 -0400
commit528f41896e4d5a0a52c080302b75c143bb2c9b05 (patch)
tree3c0dfc85a6a1855a16c173e027ffd05e2ec6111c
parente3daf6b1f38d6934ec85d78a2cad9d58dbe8d3ac (diff)
downloadPong-C-528f41896e4d5a0a52c080302b75c143bb2c9b05.tar.gz
From what I can tell, i'm finished migrating the sound code to SDL
-rw-r--r--src/marathon.c12
-rw-r--r--src/pong.h10
-rw-r--r--src/sounds.h1
-rw-r--r--src/versus.c23
4 files changed, 24 insertions, 22 deletions
diff --git a/src/marathon.c b/src/marathon.c
index 9e05b7a..02c5b3f 100644
--- a/src/marathon.c
+++ b/src/marathon.c
@@ -1,12 +1,12 @@
 #include "pong.h"
 #include "raylib.h"
+#include <SDL2/SDL_mixer.h>
 
 void marathon_main() {
 
     // Init Music
-    Music Background = LoadMusicStream("resources/marathon.wav");
-    Background.looping = true;
-    PlayMusicStream(Background);
+    Mix_Music *Background = Mix_LoadMUS("resources/marathon.wav");
+    Mix_PlayMusic(Background, -1);
 
     // Init balls lmao
     struct Balls Ball;
@@ -42,7 +42,7 @@ void marathon_main() {
         if (WindowShouldClose()) { //Quit Game if the window is closed.
             GameGoing = false;
         }
-        UpdateMusicStream(Background);
+
         snprintf(PlayerScore, 50, "Player: %d", Player.Score);
         MainCamera.zoom = GetScreenHeight()/720.0f;
 		MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
@@ -62,7 +62,7 @@ void marathon_main() {
         
         // Leave game
         if(IsKeyPressed(KEY_Q)) {
-            return;
+            MarathonGoing = false;
         }
 		
 		if(GetMouseY() < 0) {
@@ -93,6 +93,8 @@ void marathon_main() {
 			EndMode2D();
 		EndDrawing();
     }
+    Mix_HaltMusic();
+    Mix_FreeMusic(Background);
     EnableCursor();
     return;
 }
diff --git a/src/pong.h b/src/pong.h
index e933f97..76fa05d 100644
--- a/src/pong.h
+++ b/src/pong.h
@@ -4,6 +4,7 @@
 #include "raylib.h"
 #include "SDL2/SDL.h"
 #include "SDL2/SDL_mixer.h"
+#include "sounds.h"
 #include <stdatomic.h>
 #include <stdio.h>
 #include <time.h>
@@ -46,13 +47,4 @@ int title_screen();
 void versus_main();
 void marathon_main();
 
-//Sounds
-extern const int SOUND_BOUNCE;
-extern const int MUSIC_DEFEAT;
-extern const int MUSIC_VICTORY;
-extern const int MUSIC_TITLE;
-extern const int STOP_ALL_SOUNDS;
-extern const int SOUND_PLAYER_SCORE;
-extern const int SOUND_ENEMY_SCORE;
-
 #endif
diff --git a/src/sounds.h b/src/sounds.h
index 3f5412c..382e126 100644
--- a/src/sounds.h
+++ b/src/sounds.h
@@ -1,6 +1,5 @@
 #ifndef SOUNDS_H
 #define SOUNDS_H
-#include "pong.h"
 
 #define SOUND_BOUNCE 0
 #define MUSIC_DEFEAT 1
diff --git a/src/versus.c b/src/versus.c
index cd57d9a..233b238 100644
--- a/src/versus.c
+++ b/src/versus.c
@@ -1,5 +1,7 @@
 #include "pong.h"
 #include "raylib.h"
+#include "sounds.h"
+#include <SDL2/SDL_mixer.h>
 
 void versus_main() {
     // Init Player Variables
@@ -22,9 +24,9 @@ void versus_main() {
 	Ball.Angle = 0.0f;
 
 	// Init music
-	Music Background = LoadMusicStream("resources/versus.wav");
-	Background.looping = true;
-	PlayMusicStream(Background);
+	Mix_Music *Background = Mix_LoadMUS("resources/versus.wav");
+	Mix_PlayMusic(Background, -1);
+	Mix_VolumeMusic(MIX_MAX_VOLUME);
     
     // Set Sprites
 	Texture2D PaddleSprite = LoadTexture("resources/paddle.png");
@@ -49,14 +51,15 @@ void versus_main() {
             GameGoing = false;
         }
 
-		UpdateMusicStream(Background);
 		MainCamera.zoom = GetScreenHeight()/720.0f;
 		MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
 		MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
 
 		// Who won?
 		if (Enemy.Score >= 5) {
-			StopSoundMulti();
+			Mix_HaltMusic();
+			Mix_FreeMusic(Background);
+			play_audio(STOP_ALL_SOUNDS);
 			play_audio(MUSIC_DEFEAT);
 			while(!IsKeyDown(KEY_SPACE)) {
 				BeginDrawing();
@@ -68,7 +71,9 @@ void versus_main() {
 			}
 			return;
 		} else if (Player.Score >= 5) {
-			StopSoundMulti();
+			Mix_HaltMusic();
+			Mix_FreeMusic(Background);
+			play_audio(STOP_ALL_SOUNDS);
 			play_audio(MUSIC_VICTORY);
 			while(!IsKeyDown(KEY_SPACE)) {
 				BeginDrawing();
@@ -95,7 +100,7 @@ void versus_main() {
 		
 		// Leave Game
 		if(IsKeyPressed(KEY_Q)) {
-			return;
+			VersusGoing = false;
 		}
 		
 		if(GetMouseY() < 0) {
@@ -135,5 +140,9 @@ void versus_main() {
 			EndMode2D();
 		EndDrawing();
 	}
+
+	Mix_HaltMusic();
+	Mix_FreeMusic(Background);
+	play_audio(STOP_ALL_SOUNDS);
     return;
 }