Browse Source

Updated games to latest raylib version

Updated to new audio system
raysan5 9 years ago
parent
commit
29f14186c1

+ 9 - 6
games/drturtle/05_drturtle_audio.c

@@ -12,7 +12,7 @@
 *
 *   Enjoy using raylib. :)
 *
-*   This game has been created using raylib 1.1 (www.raylib.com)
+*   This game has been created using raylib 1.6 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
 *   Copyright (c) 2014 Ramon Santamaria (Ray San - [email protected])
@@ -59,8 +59,9 @@ int main()
     Sound die = LoadSound("resources/die.wav");
     Sound growl = LoadSound("resources/gamera.wav");
     
-    // Start playing streaming music
-    PlayMusicStream("resources/speeding.ogg");
+    // Load music stream and start playing music
+    Music music = LoadMusicStream("resources/speeding.ogg");
+    PlayMusicStream(music);
 
     // Define scrolling variables
     int backScrolling = 0;
@@ -118,6 +119,8 @@ int main()
     {
         // Update
         //----------------------------------------------------------------------------------
+        UpdateMusicStream(music);   // Refill music stream buffers (if required)
+        
         framesCounter++;
 
         // Game screens management
@@ -458,10 +461,10 @@ int main()
     UnloadSound(die);
     UnloadSound(growl);
     
-    StopMusicStream();      // Stop music
-    CloseAudioDevice();     // Close audio device
+    UnloadMusicStream(music);   // Unload music
+    CloseAudioDevice();         // Close audio device
     
-    CloseWindow();          // Close window and OpenGL context
+    CloseWindow();              // Close window and OpenGL context
     //--------------------------------------------------------------------------------------
     
     return 0;

+ 10 - 7
games/drturtle/06_drturtle_final.c

@@ -12,7 +12,7 @@
 *
 *   Enjoy using raylib. :)
 *
-*   This game has been created using raylib 1.1 (www.raylib.com)
+*   This game has been created using raylib 1.6 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
 *   Copyright (c) 2014 Ramon Santamaria (Ray San - [email protected])
@@ -39,7 +39,7 @@ int main()
     InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
     
     // Initialize audio device
-    InitAudioDevice();      
+    InitAudioDevice();    
     
     // Load game resources: textures
     Texture2D sky = LoadTexture("resources/sky.png");
@@ -62,8 +62,9 @@ int main()
     Sound die = LoadSound("resources/die.wav");
     Sound growl = LoadSound("resources/gamera.wav");
     
-    // Start playing streaming music
-    PlayMusicStream("resources/speeding.ogg");
+    // Load music stream and start playing music
+    Music music = LoadMusicStream("resources/speeding.ogg");
+    PlayMusicStream(music);
 
     // Define scrolling variables
     int backScrolling = 0;
@@ -127,6 +128,8 @@ int main()
     {
         // Update
         //----------------------------------------------------------------------------------
+        UpdateMusicStream(music);   // Refill music stream buffers (if required)
+        
         framesCounter++;
         
         // Sea color tint effect
@@ -483,10 +486,10 @@ int main()
     UnloadSound(die);
     UnloadSound(growl);
     
-    StopMusicStream();      // Stop music
-    CloseAudioDevice();     // Close audio device
+    UnloadMusicStream(music);   // Unload music
+    CloseAudioDevice();         // Close audio device
     
-    CloseWindow();          // Close window and OpenGL context
+    CloseWindow();              // Close window and OpenGL context
     //--------------------------------------------------------------------------------------
     
     return 0;

+ 11 - 8
games/drturtle/drturtle_final_web.c

@@ -12,7 +12,7 @@
 *
 *   Enjoy using raylib. :)
 *
-*   This game has been created using raylib 1.1 (www.raylib.com)
+*   This game has been created using raylib 1.6 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
 *   Copyright (c) 2014 Ramon Santamaria (Ray San - [email protected])
@@ -54,6 +54,8 @@ Sound eat;
 Sound die;
 Sound growl;
 
+Music music;
+
 // Define scrolling variables
 int backScrolling = 0;
 int seaScrolling = 0;
@@ -124,8 +126,9 @@ int main()
     die = LoadSound("resources/die.wav");
     growl = LoadSound("resources/gamera.wav");
     
-    // Start playing streaming music
-    PlayMusicStream("resources/speeding.ogg");
+    // Load music stream and start playing music
+    music = LoadMusicStream("resources/speeding.ogg");
+    PlayMusicStream(music);
     
     playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
     
@@ -190,10 +193,10 @@ int main()
     UnloadSound(die);
     UnloadSound(growl);
     
-    StopMusicStream();      // Stop music
-    CloseAudioDevice();     // Close audio device
+    UnloadMusicStream(music);   // Unload music
+    CloseAudioDevice();         // Close audio device
     
-    CloseWindow();          // Close window and OpenGL context
+    CloseWindow();              // Close window and OpenGL context
     //--------------------------------------------------------------------------------------
     
     return 0;
@@ -206,8 +209,8 @@ void UpdateDrawFrame(void)
 {
     // Update
     //----------------------------------------------------------------------------------
-    UpdateMusicStream();
-    
+    UpdateMusicStream(music);   // Refill music stream buffers (if required)
+        
     framesCounter++;
     
     // Sea color tint effect

+ 11 - 6
games/just_do/just_do.c

@@ -6,7 +6,7 @@
 *
 *   Developed by: Ramon Santamaria (Ray San)
 *
-*   This game has been created using raylib (www.raylib.com)
+*   This game has been created using raylib 1.6 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
 *   raylib - Copyright (c) 2015 Ramon Santamaria (Ray San - [email protected])
@@ -23,7 +23,7 @@
 //----------------------------------------------------------------------------------
 // Global Variables Definition (local to this module)
 //----------------------------------------------------------------------------------
-const int screenWidth = 1280;      // Moved to screens.h
+const int screenWidth = 1280;     // Moved to screens.h
 const int screenHeight = 720;     // Moved to screens.h
 
 // Required variables to manage screen transitions (fade-in, fade-out)
@@ -35,6 +35,7 @@ int transToScreen = -1;
 int framesCounter = 0;
 
 //static Sound levelWin;
+Music music;
 
 //----------------------------------------------------------------------------------
 // Local Functions Declaration
@@ -57,10 +58,11 @@ int main(void)
     //SetupFlags(FLAG_FULLSCREEN_MODE);
     InitWindow(screenWidth, screenHeight, windowTitle);
 
-    // TODO: Load global data here (assets that must be available in all screens, i.e. fonts)
+    // Load global data here (assets that must be available in all screens, i.e. fonts)
     InitAudioDevice();
     
     levelWin = LoadSound("resources/win.wav");
+    music = LoadMusicStream("resources/ambient.ogg");
     
     // Setup and Init first screen
     currentScreen = LOGO;
@@ -85,8 +87,9 @@ int main(void)
     // De-Initialization
     //--------------------------------------------------------------------------------------
     
-    // TODO: Unload all global loaded data (i.e. fonts) here!
+    // Unload all global loaded data (i.e. fonts) here!
     UnloadSound(levelWin);
+    UnloadMusicStream(music);
     
     CloseAudioDevice();
     
@@ -197,6 +200,8 @@ void UpdateDrawFrame(void)
             InitLevel08Screen();
         }
         
+        UpdateMusicStream(music);
+        
         switch(currentScreen) 
         {
             case LOGO: 
@@ -209,8 +214,8 @@ void UpdateDrawFrame(void)
                     TransitionToScreen(LEVEL00);
                     InitLevel00Screen();
                     
-                    PlayMusicStream("resources/ambient.ogg");
-                    SetMusicVolume(0.6f);
+                    PlayMusicStream(music);
+                    SetMusicVolume(music, 0.6f);
                 }
             } break;
             case LEVEL00: 

+ 15 - 5
games/light_my_ritual/light_my_ritual.c

@@ -35,6 +35,8 @@ bool onTransition = false;
 bool transFadeOut = false;
 int transFromScreen = -1;
 int transToScreen = -1;
+
+static Music music;
     
 //----------------------------------------------------------------------------------
 // Local Functions Declaration
@@ -66,11 +68,13 @@ int main(void)
     
     UnloadImage(image);                         // Unload image from CPU memory (RAM)
     
-    //PlayMusicStream("resources/audio/come_play_with_me.ogg");
-    
     font = LoadSpriteFont("resources/font_arcadian.png");
 	//doors = LoadTexture("resources/textures/doors.png");
     //sndDoor = LoadSound("resources/audio/door.ogg");
+    
+    music = LoadMusicStream("resources/audio/ambient.ogg");
+    PlayMusicStream(music);
+    SetMusicVolume(music, 1.0f);
 
     // Setup and Init first screen
     currentScreen = LOGO_RL;
@@ -105,6 +109,8 @@ int main(void)
     UnloadSpriteFont(font);
     //UnloadSound(sndDoor);
     
+    UnloadMusicStream(music);
+    
     free(lightsMap);
     
     CloseAudioDevice();
@@ -218,13 +224,17 @@ void UpdateDrawFrame(void)
                 rlUpdateLogoScreen();
                 
                 if (rlFinishLogoScreen()) TransitionToScreen(TITLE);
-                
+
             } break;
             case TITLE: 
             {
                 UpdateTitleScreen();
                 
-                if (FinishTitleScreen() == 1) TransitionToScreen(GAMEPLAY);
+                if (FinishTitleScreen() == 1)
+                {
+                    StopMusicStream(music);
+                    TransitionToScreen(GAMEPLAY);
+                }
 
             } break;
             case GAMEPLAY:
@@ -244,7 +254,7 @@ void UpdateDrawFrame(void)
         UpdateTransition();
     }
     
-    UpdateMusicStream();
+    if (currentScreen != GAMEPLAY) UpdateMusicStream(music);
     //----------------------------------------------------------------------------------
     
     // Draw

+ 14 - 7
games/light_my_ritual/screens/screen_gameplay.c

@@ -64,7 +64,7 @@ typedef struct Enemy {
     Color color;
 } Enemy;
 
-typedef struct Light {
+typedef struct LightSpot {
     Vector2 position;
     int radius;
     int requiredEnergy;
@@ -74,7 +74,7 @@ typedef struct Light {
     int framesCounter;
     int currentFrame;
     Rectangle frameRec;
-} Light;
+} LightSpot;
 
 typedef enum { LEVEL_I, LEVEL_II, LEVEL_III, LEVEL_FINISHED } LightedLevel;
 
@@ -92,9 +92,9 @@ static bool pause;
 
 static Player player;
 
-static Light lightsI[MAX_LIGHTS_I];
-static Light lightsII[MAX_LIGHTS_II];
-static Light lightsIII[MAX_LIGHTS_III];
+static LightSpot lightsI[MAX_LIGHTS_I];
+static LightSpot lightsII[MAX_LIGHTS_II];
+static LightSpot lightsIII[MAX_LIGHTS_III];
 
 static Enemy enemies[MAX_ENEMIES];
 
@@ -133,6 +133,8 @@ static Rectangle lightOff, lightOn;
 
 static Sound fxLightOn, fxLightOff;
 
+static Music music;
+
 // Debug variables
 static bool enemiesStopped;
 
@@ -286,7 +288,8 @@ void InitGameplayScreen(void)
     
     enemiesStopped = false;
     
-    PlayMusicStream("resources/audio/ritual.ogg");
+    music = LoadMusicStream("resources/audio/ritual.ogg");
+    PlayMusicStream(music);
 }
 
 // Gameplay Screen Update logic
@@ -549,10 +552,12 @@ void UpdateGameplayScreen(void)
     {
         alphaRitual += 0.02f;
         
-        SetMusicVolume(1.0f - alphaRitual);  
+        SetMusicVolume(music, 1.0f - alphaRitual);  
         
         if (alphaRitual > 1.0f) finishScreen = 1;
     }
+    
+    UpdateMusicStream(music);
 }
 
 // Gameplay Screen Draw logic
@@ -757,6 +762,8 @@ void UnloadGameplayScreen(void)
     // Unload sounds
     UnloadSound(fxLightOn);
     UnloadSound(fxLightOff);
+    
+    UnloadMusicStream(music);
 }
 
 // Gameplay Screen should finish?

+ 1 - 4
games/light_my_ritual/screens/screen_logo_raylib.c

@@ -75,9 +75,6 @@ void rlInitLogoScreen(void)
     
     state = 0;
     alpha = 1.0f;
-    
-    PlayMusicStream("resources/audio/ambient.ogg");
-    SetMusicVolume(1.0f);
 }
 
 // Logo Screen Update logic
@@ -204,7 +201,7 @@ void rlDrawLogoScreen(void)
 // Logo Screen Unload logic
 void rlUnloadLogoScreen(void)
 {
-    // TODO: Unload LOGO screen variables here!
+    // Unload LOGO screen variables here!
 }
 
 // Logo Screen should finish?

+ 14 - 6
games/raylib_demo/raylib_demo.c

@@ -123,6 +123,8 @@ Model cat;
 Sound fxWav;
 Sound fxOgg;
 
+Music music;
+
 Vector2 soundBallsPosition[MAX_BALLS];
 Color soundBallsColor[MAX_BALLS];
 bool soundBallsActive[MAX_BALLS];
@@ -203,11 +205,13 @@ int main()
 
     catTexture = LoadTexture("resources/catsham.png");   // Load model texture
     cat = LoadModel("resources/cat.obj");                // Load OBJ model
-    cat.material.texDiffuse = texture;                   // Set cat model diffuse texture
+    cat.material.texDiffuse = catTexture;                // Set cat model diffuse texture
     
     fxWav = LoadSound("resources/audio/weird.wav");         // Load WAV audio file
     fxOgg = LoadSound("resources/audio/tanatana.ogg");      // Load OGG audio file
     
+    music = LoadMusicStream("resources/audio/guitar_noodling.ogg");     // Load music
+    
     for (int i = 0; i < MAX_BALLS; i++)
     {
         soundBallsPosition[i] = (Vector2){ 650 + 560/2 + GetRandomValue(-280, 280), 220 + 200 + GetRandomValue(-200, 200) };
@@ -267,6 +271,8 @@ int main()
 
     UnloadSound(fxWav);
     UnloadSound(fxOgg);
+    
+    UnloadMusicStream(music);
 
     CloseAudioDevice();
     
@@ -464,11 +470,11 @@ void UpdateDrawOneFrame(void)
 
                 if (selectedModule == AUDIO)
                 {
-                    if (IsKeyPressed(KEY_SPACE) && !MusicIsPlaying()) PlayMusicStream("resources/audio/guitar_noodling.ogg");         // Play music stream
+                    if (IsKeyPressed(KEY_SPACE) && !IsMusicPlaying(music)) PlayMusicStream(music);         // Play music stream
 
                     if (IsKeyPressed('S'))
                     {
-                        StopMusicStream();
+                        StopMusicStream(music);
                         timePlayed = 0.0f;
 
                         for (int i = 0; i < MAX_BALLS; i++)
@@ -482,9 +488,11 @@ void UpdateDrawOneFrame(void)
                         }
                     }
 
-                    if (MusicIsPlaying())
+                    if (IsMusicPlaying(music))
                     {
-                        timePlayed = GetMusicTimePlayed() / GetMusicTimeLength() * 100 * 4;
+                        UpdateMusicStream(music);
+                        
+                        timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4;
 
                         if ((framesCounter%10) == 0)
                         {
@@ -842,7 +850,7 @@ void UpdateDrawOneFrame(void)
                         DrawRectangle(150, 390, 400, 12, LIGHTGRAY);
                         DrawRectangle(150, 390, (int)timePlayed, 12, MAROON);
 
-                        if (MusicIsPlaying())
+                        if (IsMusicPlaying(music))
                         {
                             DrawText("PRESS 'S' to STOP PLAYING MUSIC", 165, 425, 20, GRAY);
 

+ 8 - 3
games/skully_escape/skully_escape.c

@@ -2,7 +2,7 @@
 *
 *   SKULLY ESCAPE [KING GAME JAM 2015]
 *
-*   This game has been created using raylib (www.raylib.com)
+*   This game has been created using raylib 1.6 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
 *   Copyright (c) 2014 Ramon Santamaria (Ray San - [email protected])
@@ -32,6 +32,8 @@ int transFromScreen = -1;
 int transToScreen = -1;
 
 static int framesCounter = 0;
+
+Music music;
     
 //----------------------------------------------------------------------------------
 // Local Functions Declaration
@@ -57,7 +59,8 @@ int main(void)
     // Global data loading (assets that must be available in all screens, i.e. fonts)
     InitAudioDevice();
     
-    PlayMusicStream("resources/audio/come_play_with_me.ogg");
+    music = LoadMusicStream("resources/audio/come_play_with_me.ogg");
+    PlayMusicStream(music);
     
     font = LoadSpriteFont("resources/textures/alagard.png");
 	doors = LoadTexture("resources/textures/doors.png");
@@ -93,6 +96,8 @@ int main(void)
     UnloadSound(sndDoor);
     UnloadSound(sndScream);
     
+    UnloadMusicStream(music);
+    
     CloseAudioDevice();
     
     CloseWindow();        // Close window and OpenGL context
@@ -368,7 +373,7 @@ void UpdateDrawFrame(void)
         UpdateTransition();
     }
     
-    UpdateMusicStream();
+    UpdateMusicStream(music);
     //----------------------------------------------------------------------------------
     
     // Draw