-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (28 loc) · 1.09 KB
/
Copy pathmain.cpp
File metadata and controls
46 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "raylib.h"
int main() {
const int screenWidth = 800;
const int screenHeight = 600;
InitWindow(screenWidth, screenHeight, "Bouncing Ball Example");
float ballRadius = 20.0f;
Vector2 ballPosition = { screenWidth / 2.0f, screenHeight / 2.0f };
Vector2 ballSpeed = { 300.0f, 200.0f };
Color ballColor = RED;
SetTargetFPS(60);
while (!WindowShouldClose()) {
ballPosition.x += ballSpeed.x * GetFrameTime();
ballPosition.y += ballSpeed.y * GetFrameTime();
if ((ballPosition.x - ballRadius <= 0) || (ballPosition.x + ballRadius >= screenWidth)) {
ballSpeed.x *= -1;
}
if ((ballPosition.y - ballRadius <= 0) || (ballPosition.y + ballRadius >= screenHeight)) {
ballSpeed.y *= -1;
}
BeginDrawing();
ClearBackground(RAYWHITE);
DrawCircleV(ballPosition, ballRadius, ballColor);
DrawText("Bouncing Ball!", 10, 10, 20, DARKGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}