diff --git a/examples/shapes/shapes_moving_circle.c b/examples/shapes/shapes_moving_circle.c new file mode 100644 index 000000000..6dc75f9d1 --- /dev/null +++ b/examples/shapes/shapes_moving_circle.c @@ -0,0 +1,70 @@ +/******************************************************************************************* +* +* raylib [shapes] example - moving circle +* +* Example complexity rating: [★☆☆☆] 1/4 +* +* This example demonstrates basic animation by moving a circle horizontally. +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - moving circle"); + + float x = 100.0f; + float speed = 200.0f; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) + { + // Update + //---------------------------------------------------------------------------------- + // Move circle based on frame time (smooth movement) + x += speed * GetFrameTime(); + + if (x > screenWidth - 50 || x < 50) speed *= -1; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Title + DrawText("Moving Circle Example", 10, 10, 20, DARKGRAY); + + // Subtitle + DrawText("Circle moves horizontally using frame time", 10, 40, 10, GRAY); + + // FPS (separate, non-overlapping) + DrawFPS(10, 70); + + // Circle (main visual focus) + DrawCircle((int)x, screenHeight/2, 50, BLUE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/shapes/shapes_moving_circle.png b/examples/shapes/shapes_moving_circle.png new file mode 100644 index 000000000..f169bdb15 Binary files /dev/null and b/examples/shapes/shapes_moving_circle.png differ