diff options
| author | Ray <raysan5@gmail.com> | 2013-11-18 23:38:44 +0100 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2013-11-18 23:38:44 +0100 |
| commit | 46f10b45ad181a00e8cfa3ba2540f2922e1553cd (patch) | |
| tree | da74ac29ab65c9c6fa82a36cadd796091a14d71f /examples | |
| parent | cbbf800bb838431a626b232df8eb5db4e0a7e150 (diff) | |
| download | raylib-46f10b45ad181a00e8cfa3ba2540f2922e1553cd.tar.gz raylib-46f10b45ad181a00e8cfa3ba2540f2922e1553cd.zip | |
raylib basic folders structure and some files... ;)
Diffstat (limited to 'examples')
20 files changed, 516 insertions, 0 deletions
diff --git a/examples/ex01_basic_window.c b/examples/ex01_basic_window.c new file mode 100644 index 00000000..7b40bbd0 --- /dev/null +++ b/examples/ex01_basic_window.c @@ -0,0 +1,50 @@ +/******************************************************************************************* +* +* raylib example 01 - Basic Window +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 01a - basic window"); // Window and context initialization + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + // TODO: Update your variables here + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Congrats! You created your first window!", 190, 200, 20, 1, LIGHTGRAY); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex01_basic_window.png b/examples/ex01_basic_window.png Binary files differnew file mode 100644 index 00000000..34618441 --- /dev/null +++ b/examples/ex01_basic_window.png diff --git a/examples/ex02a_logo_raylib.c b/examples/ex02a_logo_raylib.c new file mode 100644 index 00000000..cbd67b20 --- /dev/null +++ b/examples/ex02a_logo_raylib.c @@ -0,0 +1,54 @@ +/******************************************************************************************* +* +* raylib example 02a - Draw raylib logo +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 02a - raylib logo"); // Window and context initialization + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + // TODO: Update your variables here + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, BLACK); + DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE); + DrawText("raylib", 356, 273, 50, 1, BLACK); + + DrawText("this is NOT a texture!", 350, 370, 10, 1, GRAY); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex02a_logo_raylib.png b/examples/ex02a_logo_raylib.png Binary files differnew file mode 100644 index 00000000..6b385f7c --- /dev/null +++ b/examples/ex02a_logo_raylib.png diff --git a/examples/ex02b_shapes.c b/examples/ex02b_shapes.c new file mode 100644 index 00000000..93a0bccd --- /dev/null +++ b/examples/ex02b_shapes.c @@ -0,0 +1,73 @@ +/******************************************************************************************* +* +* raylib example 02b - Draw basic shapes 2d (rectangle, circle, line...) +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 02b - basic shapes drawing"); // Window and context initialization + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + // TODO: Update your variables here + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // TODO: draw some shapes... with names... :P +/* + void DrawPixel(int posX, int posY, Color color); // Draw a pixel + void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) + void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line + void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) + void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle + void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle + void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) + void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline + void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle + void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle + void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle + void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) + void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline + void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle + void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline + void DrawPoly(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points + void DrawPolyLine(Vector2 *points, int numPoints, Color color); // Draw polygon lines +*/ + DrawRectangle(screenWidth/4 - 50, screenHeight/2 - 100, 100, 100, GOLD); + DrawCircle(3*screenWidth/4, screenHeight/2 - 50, 50, MAROON); + + DrawText("_____", 320, 280, 50, 1, BLACK); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex02c_color_palette.c b/examples/ex02c_color_palette.c new file mode 100644 index 00000000..3a735295 --- /dev/null +++ b/examples/ex02c_color_palette.c @@ -0,0 +1,95 @@ +/******************************************************************************************* +* +* raylib example 02c - Draw raylib custom color palette +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 02c - raylib color palette"); // Window and context initialization + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + // TODO: Update your variables here + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("raylib color palette", 28, 42, 20, 2, BLACK); + + DrawRectangle(26, 80, 100, 100, DARKGRAY); + DrawRectangle(26, 188, 100, 100, GRAY); + DrawRectangle(26, 296, 100, 100, LIGHTGRAY); + DrawRectangle(134, 80, 100, 100, MAROON); + DrawRectangle(134, 188, 100, 100, RED); + DrawRectangle(134, 296, 100, 100, PINK); + DrawRectangle(242, 80, 100, 100, ORANGE); + DrawRectangle(242, 188, 100, 100, GOLD); + DrawRectangle(242, 296, 100, 100, YELLOW); + DrawRectangle(350, 80, 100, 100, DARKGREEN); + DrawRectangle(350, 188, 100, 100, LIME); + DrawRectangle(350, 296, 100, 100, GREEN); + DrawRectangle(458, 80, 100, 100, DARKBLUE); + DrawRectangle(458, 188, 100, 100, BLUE); + DrawRectangle(458, 296, 100, 100, SKYBLUE); + DrawRectangle(566, 80, 100, 100, DARKPURPLE); + DrawRectangle(566, 188, 100, 100, VIOLET); + DrawRectangle(566, 296, 100, 100, PURPLE); + DrawRectangle(674, 80, 100, 100, DARKBROWN); + DrawRectangle(674, 188, 100, 100, BROWN); + DrawRectangle(674, 296, 100, 100, BEIGE); + + + DrawText("DARKGRAY", 57, 166, 10, 2, BLACK); + DrawText("GRAY", 89, 274, 10, 2, BLACK); + DrawText("LIGHTGRAY", 51, 382, 10, 2, BLACK); + DrawText("MAROON", 180, 166, 10, 2, BLACK); + DrawText("RED", 207, 274, 10, 2, BLACK); + DrawText("PINK", 200, 382, 10, 2, BLACK); + DrawText("ORANGE", 290, 166, 10, 2, BLACK); + DrawText("GOLD", 306, 274, 10, 2, BLACK); + DrawText("YELLOW", 290, 382, 10, 2, BLACK); + DrawText("DARKGREEN", 374, 166, 10, 2, BLACK); + DrawText("LIME", 417, 274, 10, 2, BLACK); + DrawText("GREEN", 407, 382, 10, 2, BLACK); + DrawText("DARKBLUE", 491, 166, 10, 2, BLACK); + DrawText("BLUE", 523, 274, 10, 2, BLACK); + DrawText("SKYBLUE", 499, 382, 10, 2, BLACK); + DrawText("DARKPURPLE", 582, 166, 10, 2, BLACK); + DrawText("VIOLET", 617, 274, 10, 2, BLACK); + DrawText("PURPLE", 615, 382, 10, 2, BLACK); + DrawText("DARKBROWN", 695, 166, 10, 2, BLACK); + DrawText("BROWN", 728, 274, 10, 2, BLACK); + DrawText("BEIGE", 733, 382, 10, 2, BLACK); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex02c_color_palette.png b/examples/ex02c_color_palette.png Binary files differnew file mode 100644 index 00000000..04583e9a --- /dev/null +++ b/examples/ex02c_color_palette.png diff --git a/examples/ex03a_input_keys.c b/examples/ex03a_input_keys.c new file mode 100644 index 00000000..85deb2b4 --- /dev/null +++ b/examples/ex03a_input_keys.c @@ -0,0 +1,57 @@ +/******************************************************************************************* +* +* raylib example 03a - Keyboard input +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + Vector2 ballPosition = { screenWidth/2, screenHeight/2 }; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 05 - keyboard input"); // Window and context initialization + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + if (IsKeyPressed(KEY_RIGHT)) ballPosition.x += 0.8; + if (IsKeyPressed(KEY_LEFT)) ballPosition.x -= 0.8; + if (IsKeyPressed(KEY_UP)) ballPosition.y -= 0.8; + if (IsKeyPressed(KEY_DOWN)) ballPosition.y += 0.8; + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("move the ball with arrow keys", 10, 10, 20, 1, DARKGRAY); + + DrawCircleV(ballPosition, 50, MAROON); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex03a_input_keys.png b/examples/ex03a_input_keys.png Binary files differnew file mode 100644 index 00000000..48370321 --- /dev/null +++ b/examples/ex03a_input_keys.png diff --git a/examples/ex03b_input_mouse.c b/examples/ex03b_input_mouse.c new file mode 100644 index 00000000..996cd73e --- /dev/null +++ b/examples/ex03b_input_mouse.c @@ -0,0 +1,63 @@ +/******************************************************************************************* +* +* raylib example 03b - Mouse input +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + Vector2 ballPosition = { -100.0, -100.0 }; + int counter = 0; + int mouseX, mouseY; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 06 - mouse input"); // Window and context initialization + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + mouseX = GetMouseX(); + mouseY = GetMouseY(); + + ballPosition.x = (float)mouseX; + ballPosition.y = (float)mouseY; + } + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawCircleV(ballPosition, 40, GOLD); + + DrawText("mouse click to draw the ball", 10, 10, 20, 1, DARKGRAY); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex03b_input_mouse.png b/examples/ex03b_input_mouse.png Binary files differnew file mode 100644 index 00000000..76567281 --- /dev/null +++ b/examples/ex03b_input_mouse.png diff --git a/examples/ex03c_input_gamepad.c b/examples/ex03c_input_gamepad.c new file mode 100644 index 00000000..377ac7f5 --- /dev/null +++ b/examples/ex03c_input_gamepad.c @@ -0,0 +1,67 @@ +/******************************************************************************************* +* +* raylib example 03c - Gamepad input +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + Vector2 ballPosition = { screenWidth/2, screenHeight/2 }; + Vector2 gamepadMove = { 0, 0 }; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 01 - gamepad input"); // Window and context initialization + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + if (IsGamepadAvailable(GAMEPAD_PLAYER1)) + { + gamepadMove = GetGamepadMovement(GAMEPAD_PLAYER1); + + ballPosition.x += gamepadMove.x; + ballPosition.y -= gamepadMove.y; + + if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A)) + { + ballPosition.x = screenWidth/2; + ballPosition.y = screenHeight/2; + } + } + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("move the ball with gamepad", 10, 10, 20, 1, DARKGRAY); + + DrawCircleV(ballPosition, 50, MAROON); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex03c_input_gamepad.png b/examples/ex03c_input_gamepad.png Binary files differnew file mode 100644 index 00000000..f7e55658 --- /dev/null +++ b/examples/ex03c_input_gamepad.png diff --git a/examples/ex04a_textures.c b/examples/ex04a_textures.c new file mode 100644 index 00000000..5c2bf650 --- /dev/null +++ b/examples/ex04a_textures.c @@ -0,0 +1,57 @@ +/******************************************************************************************* +* +* raylib example 04a - Texture loading and drawing +* +* 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) +* +* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + int screenWidth = 800; + int screenHeight = 450; + + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "raylib example 04a - texture loading and drawing"); // Window and context initialization + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading + //---------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //----------------------------------------------------- + // TODO: Update your variables here + //----------------------------------------------------- + + // Draw + //----------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); + + DrawText("this IS a texture!", 360, 370, 10, 1, GRAY); + + EndDrawing(); + //----------------------------------------------------- + } + + // De-Initialization + //--------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //---------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/ex04a_textures.png b/examples/ex04a_textures.png Binary files differnew file mode 100644 index 00000000..c18bf880 --- /dev/null +++ b/examples/ex04a_textures.png diff --git a/examples/resources/catsham.png b/examples/resources/catsham.png Binary files differnew file mode 100644 index 00000000..8d7978e0 --- /dev/null +++ b/examples/resources/catsham.png diff --git a/examples/resources/catwhite.png b/examples/resources/catwhite.png Binary files differnew file mode 100644 index 00000000..b849c4c0 --- /dev/null +++ b/examples/resources/catwhite.png diff --git a/examples/resources/coin.wav b/examples/resources/coin.wav Binary files differnew file mode 100644 index 00000000..6007509b --- /dev/null +++ b/examples/resources/coin.wav diff --git a/examples/resources/raylib_logo.png b/examples/resources/raylib_logo.png Binary files differnew file mode 100644 index 00000000..66545627 --- /dev/null +++ b/examples/resources/raylib_logo.png diff --git a/examples/resources/spring.wav b/examples/resources/spring.wav Binary files differnew file mode 100644 index 00000000..c7fbf1b9 --- /dev/null +++ b/examples/resources/spring.wav |
