Here is the end result.
#include “raylib.h”
int main()
{
// window dimension
int Width{800};
int Height{450};
InitWindow( Width, Height, "Sanjay Lunayach" );
// circle coordinates
int circle_x{200};
int circle_y{200};
int circle_radius{25};
// circle edges
int l_circle_x{circle_x - circle_radius};
int r_circle_x{circle_x + circle_radius};
int u_circle_y{circle_y - circle_radius};
int b_circle_y{circle_y + circle_radius};
// axe coordinates
int axe_x{400};
int axe_y{0};
int axe_length{50};
// axe edges
int l_axe_x{axe_x};
int r_axe_x{axe_x + axe_length};
int u_axe_y{axe_y};
int b_axe_y{axe_y + axe_length};
int direction{10};
bool collition_with_axe =
(b_axe_y >= u_circle_y) &&
(u_axe_y <= b_circle_y) &&
(l_axe_x <= r_circle_x) &&
(r_axe_x >= l_circle_x);
SetTargetFPS(60);
while ( WindowShouldClose() != true )
{
BeginDrawing();
ClearBackground(WHITE);
if (collition_with_axe)
{
DrawText("Game Over", 400, 200, 20, VIOLET);
}
else
{
// Game Logic Begins
//update the edges
l_circle_x = circle_x - circle_radius;
r_circle_x = circle_x + circle_radius;
u_circle_y = circle_y - circle_radius;
b_circle_y = circle_y + circle_radius;
l_axe_x = axe_x;
r_axe_x = axe_x + axe_length;
u_axe_y = axe_y;
b_axe_y = axe_y + axe_length;
// update collision with axe
collition_with_axe =
(b_axe_y >= u_circle_y) &&
(u_axe_y <= b_circle_y) &&
(l_axe_x <= r_circle_x) &&
(r_axe_x >= l_circle_x);
DrawCircle( circle_x, circle_y, circle_radius, BLUE);
DrawRectangle( axe_x, axe_y, axe_length, axe_length, MAGENTA);
// move the axe
axe_y += direction;
if (axe_y > Height || axe_y < 0)
{
direction = -direction;
}
if (IsKeyDown(KEY_D) && circle_x < Width)
{
circle_x += 10;
}
if (IsKeyDown(KEY_A) && circle_x > 25)
{
circle_x -= 10;
}
// Game Logic Ends
}
EndDrawing();
}
}