2013-11-24 23:30:05 +04:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
2014-09-21 16:26:42 +04:00
|
|
|
* raylib [audio] example - Sound loading and playing
|
2013-11-24 23:30:05 +04:00
|
|
|
*
|
2019-05-20 17:36:42 +03:00
|
|
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
2013-11-29 00:16:31 +04:00
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
2013-11-24 23:30:05 +04:00
|
|
|
*
|
2019-05-20 17:36:42 +03:00
|
|
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
2013-11-24 23:30:05 +04:00
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
int main(void)
|
2013-11-24 23:30:05 +04:00
|
|
|
{
|
2013-11-29 00:16:31 +04:00
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-09-21 16:26:42 +04:00
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-28 22:59:56 +04:00
|
|
|
InitAudioDevice(); // Initialize audio device
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2017-04-09 00:31:58 +03:00
|
|
|
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
|
|
|
Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
|
2019-05-20 17:36:42 +03:00
|
|
|
|
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
2013-11-29 00:16:31 +04:00
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-24 23:30:05 +04:00
|
|
|
// Main game loop
|
2013-11-29 00:16:31 +04:00
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
2013-11-24 23:30:05 +04:00
|
|
|
{
|
2013-11-29 00:16:31 +04:00
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
2014-09-21 16:26:42 +04:00
|
|
|
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
|
|
|
|
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
|
2013-11-29 00:16:31 +04:00
|
|
|
//----------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-29 00:16:31 +04:00
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-29 00:16:31 +04:00
|
|
|
ClearBackground(RAYWHITE);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-09-21 16:26:42 +04:00
|
|
|
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
|
|
|
|
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-28 22:59:56 +04:00
|
|
|
EndDrawing();
|
2013-11-29 00:16:31 +04:00
|
|
|
//----------------------------------------------------------------------------------
|
2013-11-28 22:59:56 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 00:16:31 +04:00
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-21 16:26:42 +04:00
|
|
|
UnloadSound(fxWav); // Unload sound data
|
|
|
|
UnloadSound(fxOgg); // Unload sound data
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-29 00:16:31 +04:00
|
|
|
CloseAudioDevice(); // Close audio device
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-28 22:59:56 +04:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
2013-11-29 00:16:31 +04:00
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2013-11-24 23:30:05 +04:00
|
|
|
return 0;
|
2014-09-21 16:26:42 +04:00
|
|
|
}
|