Add moving circle example demonstrating basic animation
This commit is contained in:
parent
d892f3ba4a
commit
ada76157ff
70
examples/shapes/shapes_moving_circle.c
Normal file
70
examples/shapes/shapes_moving_circle.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
BIN
examples/shapes/shapes_moving_circle.png
Normal file
BIN
examples/shapes/shapes_moving_circle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Loading…
Reference in New Issue
Block a user