diff options
Diffstat (limited to 'examples/web/shapes/shapes_bouncing_ball.c')
| -rw-r--r-- | examples/web/shapes/shapes_bouncing_ball.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/examples/web/shapes/shapes_bouncing_ball.c b/examples/web/shapes/shapes_bouncing_ball.c index 8f5ebbb..cd416ae 100644 --- a/examples/web/shapes/shapes_bouncing_ball.c +++ b/examples/web/shapes/shapes_bouncing_ball.c @@ -28,7 +28,7 @@ Vector2 ballPosition = { 0.0f }; Vector2 ballSpeed = { 5.0f, 4.0f }; int ballRadius = 20; -bool pause = 0; +static bool pause = 0; int framesCounter = 0; //---------------------------------------------------------------------------------- @@ -37,22 +37,22 @@ int framesCounter = 0; void UpdateDrawFrame(void); // Update and Draw one frame //---------------------------------------------------------------------------------- -// Main Enry Point +// Program Main Entry Point //---------------------------------------------------------------------------------- -int main() +int main(void) { // Initialization //--------------------------------------------------------- InitWindow(screenWidth, screenHeight, "raylib [shapes] example - bouncing ball"); - - ballPosition = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; + + ballPosition = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawFrame, 0, 1); #else SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { @@ -64,7 +64,7 @@ int main() //--------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //---------------------------------------------------------- - + return 0; } @@ -76,33 +76,33 @@ void UpdateDrawFrame(void) // Update //----------------------------------------------------- if (IsKeyPressed(KEY_SPACE)) pause = !pause; - + if (!pause) { ballPosition.x += ballSpeed.x; ballPosition.y += ballSpeed.y; - + // Check walls collision for bouncing if ((ballPosition.x >= (GetScreenWidth() - ballRadius)) || (ballPosition.x <= ballRadius)) ballSpeed.x *= -1.0f; if ((ballPosition.y >= (GetScreenHeight() - ballRadius)) || (ballPosition.y <= ballRadius)) ballSpeed.y *= -1.0f; } else framesCounter++; //----------------------------------------------------- - + // Draw //----------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + DrawCircleV(ballPosition, ballRadius, MAROON); DrawText("PRESS SPACE to PAUSE BALL MOVEMENT", 10, GetScreenHeight() - 25, 20, LIGHTGRAY); - + // On pause, we draw a blinking message if (pause && ((framesCounter/30)%2)) DrawText("PAUSED", 350, 200, 30, GRAY); DrawFPS(10, 10); - + EndDrawing(); //----------------------------------------------------- } |
