From 528f41896e4d5a0a52c080302b75c143bb2c9b05 Mon Sep 17 00:00:00 2001 From: Charadon Date: Tue, 7 Jun 2022 04:25:50 -0400 Subject: From what I can tell, i'm finished migrating the sound code to SDL --- src/marathon.c | 12 +++++++----- src/pong.h | 10 +--------- src/sounds.h | 1 - src/versus.c | 23 ++++++++++++++++------- 4 files changed, 24 insertions(+), 22 deletions(-) (limited to 'src') 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 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 #include #include @@ -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 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; } -- cgit 1.4.1-2-gfad0