aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2013-12-27 00:44:34 +0100
committerraysan5 <raysan5@gmail.com>2013-12-27 00:44:34 +0100
commit989bc0fe9d80107f1f44de647c51963e1dab79fc (patch)
tree0e70e90421a552f5b013c7184cf1e37fcb4b7644 /examples
parenta0d719d95f60d0b2109cebff29603625c3c3cbe1 (diff)
downloadraylib-989bc0fe9d80107f1f44de647c51963e1dab79fc.tar.gz
raylib-989bc0fe9d80107f1f44de647c51963e1dab79fc.zip
New example added
Replaced ex06b (incomplete) by a new useful one
Diffstat (limited to 'examples')
-rw-r--r--examples/ex06b_logo_anim.c150
-rw-r--r--examples/ex06b_logo_anim.exebin0 -> 332285 bytes
-rw-r--r--examples/ex06b_logo_anim.pngbin0 -> 4787 bytes
-rw-r--r--examples/ex06b_shape_select.c50
-rw-r--r--examples/ex06b_shape_select.pngbin3913 -> 0 bytes
5 files changed, 150 insertions, 50 deletions
diff --git a/examples/ex06b_logo_anim.c b/examples/ex06b_logo_anim.c
new file mode 100644
index 00000000..02458b33
--- /dev/null
+++ b/examples/ex06b_logo_anim.c
@@ -0,0 +1,150 @@
+/*******************************************************************************************
+*
+* raylib example 06b - raylib Logo Animation
+*
+* 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"
+
+// Useful function for fade-ins and fade-outs
+Color Fade(Color col, float alpha)
+{
+ return (Color){col.r, col.g, col.b, col.a*alpha};
+}
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ int logoPositionX = screenWidth/2 - 128;
+ int logoPositionY = screenHeight/2 - 128;
+
+ int framesCounter = 0;
+ int lettersCount = 0;
+
+ int topSideRecWidth = 16;
+ int leftSideRecHeight = 16;
+
+ int bottomSideRecWidth = 16;
+ int rightSideRecHeight = 16;
+
+ char raylib[8] = " "; // raylib text array, max 8 letters
+
+ int state = 0; // Tracking animation states (State Machine)
+
+ float alpha = 1.0;
+
+ InitWindow(screenWidth, screenHeight, "raylib example 06b - raylib logo animation");
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (state == 0) // State 0: Small box blinking
+ {
+ framesCounter++;
+
+ if (framesCounter == 120)
+ {
+ state = 1;
+ framesCounter = 0; // Reset counter... will be used later...
+ }
+ }
+ else if (state == 1) // State 1: Top and left bars growing
+ {
+ topSideRecWidth += 4;
+ leftSideRecHeight += 4;
+
+ if (topSideRecWidth == 256) state = 2;
+ }
+ else if (state == 2) // State 2: Bottom and right bars growing
+ {
+ bottomSideRecWidth += 4;
+ rightSideRecHeight += 4;
+
+ if (bottomSideRecWidth == 256) state = 3;
+ }
+ else if (state == 3) // State 3: Letters appearing (one by one)
+ {
+ framesCounter++;
+
+ if (framesCounter/12) // Every 12 frames, one more letter!
+ {
+ lettersCount++;
+ framesCounter = 0;
+ }
+
+ switch (lettersCount)
+ {
+ case 1: raylib[0] = 'r'; break;
+ case 2: raylib[1] = 'a'; break;
+ case 3: raylib[2] = 'y'; break;
+ case 4: raylib[3] = 'l'; break;
+ case 5: raylib[4] = 'i'; break;
+ case 6: raylib[5] = 'b'; break;
+ default: break;
+ }
+
+ if (lettersCount >= 10) // When all letters have appeared, just fade out everything
+ {
+ alpha -= 0.02;
+
+ if (alpha <= 0) alpha = 0;
+ }
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ if (state == 0)
+ {
+ if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
+ }
+ else if (state == 1)
+ {
+ DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
+ DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
+ }
+ else if (state == 2)
+ {
+ DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
+ DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
+
+ DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
+ DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
+ }
+ else if (state == 3)
+ {
+ DrawRectangle(logoPositionX, logoPositionY, 256, 256, Fade(BLACK, alpha));
+ DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
+
+ DrawText(raylib, 356, 273, 50, Fade(BLACK, alpha));
+ }
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/ex06b_logo_anim.exe b/examples/ex06b_logo_anim.exe
new file mode 100644
index 00000000..8b7ae888
--- /dev/null
+++ b/examples/ex06b_logo_anim.exe
Binary files differ
diff --git a/examples/ex06b_logo_anim.png b/examples/ex06b_logo_anim.png
new file mode 100644
index 00000000..103dfc4a
--- /dev/null
+++ b/examples/ex06b_logo_anim.png
Binary files differ
diff --git a/examples/ex06b_shape_select.c b/examples/ex06b_shape_select.c
deleted file mode 100644
index 1d0a6b19..00000000
--- a/examples/ex06b_shape_select.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************************
-*
-* raylib example 06b - Shape selection by mouse (collision detection)
-*
-* 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()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
-
- InitWindow(screenWidth, screenHeight, "raylib example 06b - shape selection");
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- // TODO: Update your variables here
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- // TODO: Comming soon...
-
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-} \ No newline at end of file
diff --git a/examples/ex06b_shape_select.png b/examples/ex06b_shape_select.png
deleted file mode 100644
index f18ae044..00000000
--- a/examples/ex06b_shape_select.png
+++ /dev/null
Binary files differ