-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaxe_game.cpp
More file actions
99 lines (81 loc) · 2.47 KB
/
Copy pathaxe_game.cpp
File metadata and controls
99 lines (81 loc) · 2.47 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "raylib.h"
int main()
{
int width{800};
int height{450};
InitWindow(width, height, "Axe Game");
// 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};
SetTargetFPS(60);
bool collision_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);
while (WindowShouldClose() != true)
{
BeginDrawing();
ClearBackground(WHITE);
// axe collision
if (collision_with_axe == true)
{
DrawText("Game Over!", 400, 200, 20, RED);
}
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;
u_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
collision_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, RED);
// move the axe
axe_y += direction; //axe_y = axe_y + 10
if (axe_y > height || axe_y < 0)
{
direction = -direction;
}
// Move Left
if (IsKeyDown(KEY_D) && circle_x < width)
{
circle_x = circle_x + 10;
}
// Move Right
if (IsKeyDown(KEY_A) && circle_x > 0)
{
circle_x -= 10; //circle_x = circle_x - 10;
}
// Game Logic ends
}
EndDrawing();
}
}