Chap5 (Input and Output)
Chap5 (Input and Output)
Chapter 5
https://www.raylib.com/
Compile program:
g++ hello-raylib.cpp -lraylib
BeginDrawing();
DrawLine(100, 100, 500, 100, WHITE);
DrawLine(100, 100, 300, 100+c, WHITE);
DrawLine(300, 100+c, 500, 100, WHITE);
(𝑥𝑚𝑎𝑥, 𝑦𝑚𝑎𝑥)
CloseWindow();
}
Animation: bouncing ball
y
Ball has position (𝑥, 𝑦) and
constant velocity (𝑣𝑥, 𝑣𝑦).
y+vy
while (!WindowShouldClose()) {
x = x + vx; update ball position
y = y + vy;
if(x+r >= W || x-r <= 0) check collision with vertical wall
vx = -vx;
if(y+r >= H || y-r <= 0) check collision with horizontal wall
vy = -vy;
BeginDrawing();
ClearBackground(WHITE);
DrawCircle(x, y, r, BLUE);
EndDrawing();
}
CloseWindow();