Examples renaming and test examples merge

Examples have been renamed for coherence with raylib modules and test
examples have been merged into examples folder.
This commit is contained in:
raysan5 2014-09-21 14:26:42 +02:00
commit 5ecb6801fa
84 changed files with 501 additions and 5225 deletions

View file

@ -0,0 +1,87 @@
/*******************************************************************************************
*
* raylib [audio] example - Music playing (streaming)
*
* NOTE: This example requires OpenAL Soft library installed
*
* This example has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
InitAudioDevice(); // Initialize audio device
PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream
int framesCounter = 0;
float volume = 1.0;
float timePlayed = 0;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
framesCounter++;
// Testing music fading from one file to another
/*
if (framesCounter > 600) // Wait for 10 seconds (600 frames)
{
volume -= 0.01; // Decrement music volume level
// When music volume level equal or lower than 0,
// restore volume level and init another music file
if (volume <= 0)
{
volume = 1.0;
framesCounter = 0;
PlayMusicStream("resources/audio/another_file.ogg");
}
SetMusicVolume(volume);
}
*/
timePlayed = GetMusicTimePlayed() / GetMusicTimeLength() * 100 * 4; // We scale by 4 to fit 400 pixels
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY);
DrawRectangle(200, 250, 400, 12, LIGHTGRAY);
DrawRectangle(200, 250, (int)timePlayed, 12, MAROON);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1,13 +1,13 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib example 08 - Audio loading and playing * raylib [audio] example - Sound loading and playing
* *
* NOTE: This example requires OpenAL32 dll installed (or in the same folder) * NOTE: This example requires OpenAL Soft library installed
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
* *
********************************************************************************************/ ********************************************************************************************/
@ -20,11 +20,12 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib example 08 - audio loading and playing"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
Sound fx = LoadSound("resources/audio/weird.wav"); // Load WAV audio file Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -32,7 +33,9 @@ int main()
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) PlaySound(fx); // Play the sound! if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -41,7 +44,9 @@ int main()
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Press SPACE to PLAY the SOUND!", 240, 200, 20, LIGHTGRAY); DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -49,7 +54,8 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadSound(fx); // Unload sound data UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data
CloseAudioDevice(); // Close audio device CloseAudioDevice(); // Close audio device
@ -57,4 +63,4 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1,11 +1,11 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib example 07a - Initialize 3d mode * raylib [core] example - Initialize 3d mode
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
* *
********************************************************************************************/ ********************************************************************************************/
@ -18,11 +18,14 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
Vector3 position = { 0.0, 0.0, 0.0 }; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
InitWindow(screenWidth, screenHeight, "raylib example 07a - 3d mode"); Vector3 cubePosition = { 0.0, 0.0, 0.0 };
//SetTargetFPS(60); // Set our game to run at 60 frames-per-second, but not now...
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -41,7 +44,8 @@ int main()
Begin3dMode(camera); Begin3dMode(camera);
DrawCube(position, 2, 2, 2, RED); DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawGrid(10.0, 1.0); DrawGrid(10.0, 1.0);
@ -61,4 +65,4 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

BIN
examples/core_3d_mode.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View file

@ -1,11 +1,11 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib example 01 - Basic Window * raylib [core] example - Basic window
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
* *
********************************************************************************************/ ********************************************************************************************/
@ -18,7 +18,7 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib example 01a - basic window"); InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -47,4 +47,4 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -1,11 +1,11 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib example 06a - Color selection by mouse (collision detection) * raylib [core] example - Color selection by mouse (collision detection)
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
* *
********************************************************************************************/ ********************************************************************************************/
@ -17,29 +17,29 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 400; int screenHeight = 400;
InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)");
Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
GREEN, SKYBLUE, PURPLE, BEIGE }; GREEN, SKYBLUE, PURPLE, BEIGE };
Rectangle recs[21]; // Rectangles array Rectangle colorsRecs[21]; // Rectangles array
// Fills recs data (for every rectangle) // Fills colorsRecs data (for every rectangle)
for (int i = 0; i < 21; i++) for (int i = 0; i < 21; i++)
{ {
recs[i].x = 20 + 100*(i%7) + 10*(i%7); colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7);
recs[i].y = 40 + 100*(i/7) + 10*(i/7); colorsRecs[i].y = 40 + 100*(i/7) + 10*(i/7);
recs[i].width = 100; colorsRecs[i].width = 100;
recs[i].height = 100; colorsRecs[i].height = 100;
} }
bool selected[21] = { false }; // Selected rectangles indicator bool selected[21] = { false }; // Selected rectangles indicator
Vector2 mousePoint; Vector2 mousePoint;
InitWindow(screenWidth, screenHeight, "raylib example 06a - color selection"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second
SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -51,7 +51,7 @@ int main()
for (int i = 0; i < 21; i++) // Iterate along all the rectangles for (int i = 0; i < 21; i++) // Iterate along all the rectangles
{ {
if (CheckCollisionPointRec(mousePoint, recs[i])) if (CheckCollisionPointRec(mousePoint, colorsRecs[i]))
{ {
colors[i].a = 120; colors[i].a = 120;
@ -69,15 +69,15 @@ int main()
for (int i = 0; i < 21; i++) // Draw all rectangles for (int i = 0; i < 21; i++) // Draw all rectangles
{ {
DrawRectangleRec(recs[i], colors[i]); DrawRectangleRec(colorsRecs[i], colors[i]);
// Draw four rectangles around selected rectangle // Draw four rectangles around selected rectangle
if (selected[i]) if (selected[i])
{ {
DrawRectangle(recs[i].x, recs[i].y, 100, 10, RAYWHITE); // Square top rectangle DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 100, 10, RAYWHITE); // Square top rectangle
DrawRectangle(recs[i].x, recs[i].y, 10, 100, RAYWHITE); // Square left rectangle DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 10, 100, RAYWHITE); // Square left rectangle
DrawRectangle(recs[i].x + 90, recs[i].y, 10, 100, RAYWHITE); // Square right rectangle DrawRectangle(colorsRecs[i].x + 90, colorsRecs[i].y, 10, 100, RAYWHITE); // Square right rectangle
DrawRectangle(recs[i].x, recs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle
} }
} }
@ -91,4 +91,4 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -1,11 +1,14 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib example 03c - Gamepad input * raylib [core] example - Gamepad input
*
* NOTE: This example requires a Gamepad connected to the system
* raylib is configured to work with Xbox 360 gamepad, check raylib.h for buttons configuration
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
* *
********************************************************************************************/ ********************************************************************************************/
@ -18,12 +21,12 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
Vector2 ballPosition = { screenWidth/2, screenHeight/2 }; Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
Vector2 gamepadMove = { 0, 0 }; Vector2 gamepadMovement = { 0, 0 };
InitWindow(screenWidth, screenHeight, "raylib example 01 - gamepad input"); SetTargetFPS(60); // Set target frames-per-second
SetTargetFPS(60); // Set target frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -33,10 +36,10 @@ int main()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsGamepadAvailable(GAMEPAD_PLAYER1)) if (IsGamepadAvailable(GAMEPAD_PLAYER1))
{ {
gamepadMove = GetGamepadMovement(GAMEPAD_PLAYER1); gamepadMovement = GetGamepadMovement(GAMEPAD_PLAYER1);
ballPosition.x += gamepadMove.x; ballPosition.x += gamepadMovement.x;
ballPosition.y -= gamepadMove.y; ballPosition.y -= gamepadMovement.y;
if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A)) if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A))
{ {
@ -66,4 +69,4 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -1,11 +1,11 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib example 03a - Keyboard input * raylib [core] example - Keyboard input
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
* *
********************************************************************************************/ ********************************************************************************************/
@ -18,10 +18,10 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
Vector2 ballPosition = { screenWidth/2, screenHeight/2 }; InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
InitWindow(screenWidth, screenHeight, "raylib example 05 - keyboard input"); Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
SetTargetFPS(60); // Set target frames-per-second SetTargetFPS(60); // Set target frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -56,4 +56,4 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -1,11 +1,11 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib example 03b - Mouse input * raylib [core] example - Mouse input
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
* *
********************************************************************************************/ ********************************************************************************************/
@ -18,10 +18,10 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
Vector2 ballPosition = { -100.0, -100.0 }; InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
int mouseX, mouseY;
InitWindow(screenWidth, screenHeight, "raylib example 06 - mouse input"); int mouseX, mouseY;
Vector2 ballPosition = { -100.0, -100.0 };
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -59,4 +59,4 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -0,0 +1,58 @@
/*******************************************************************************************
*
* raylib [core] examples - Mouse wheel
*
* This test has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel");
int boxPositionY = screenHeight/2 - 40;
int scrollSpeed = 4; // Scrolling speed in pixels
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
boxPositionY -= (GetMouseWheelMove()*scrollSpeed);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);
DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -0,0 +1,65 @@
/*******************************************************************************************
*
* raylib [core] example - Generate random values
*
* This example has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values");
int framesCounter = 0; // Variable used to count frames
int randValue = GetRandomValue(-8,5); // Get a random integer number between -8 and 5 (both included)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
framesCounter++;
// Every two seconds (120 frames) a new random value is generated
if (((framesCounter/120)%2) == 1)
{
randValue = GetRandomValue(-8,5);
framesCounter = 0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Some files were not shown because too many files have changed in this diff Show more