Hello! I follow each step of the tutorial but apparently, it is not detecting the colission. Here is the code:
#include
#include <raylib.h>
int main(){
int width = 800; //Window Width
int height = 450; //Window Height
int circle_x = 200; //Circle X Position
int circle_y = 200; //Circle Y Position
int circle_radius = 25; //Circle Radius
int l_circle_x = circle_x - circle_radius; //Circle X Left Edge
int r_circle_x = circle_y + circle_radius; //Circle X Right Edge
int u_circle_y = circle_y - circle_radius; //Circle Y UP Edge
int b_circle_y = circle_y + circle_radius; //Circle Y Bottom Edge
int axe_x = 400; //Axis X Position
int axe_y = 0; //Axis Y Position
int axe_length = 50; //Length of
int l_axe_x = axe_x; //X cordinate of Left Edge of the Axe
int r_axe_x = axe_x + axe_length; //X cordinate of Right Edge of the Axe
int u_axe_y = axe_y; //Y cordinate of the UP Edge of the Axe
int b_axe_y = axe_y + axe_length; //Y cordinate of the Bottom Edge of the Axe
int direction = 10;
bool collision_with_axe = (b_axe_y >= u_circle_y) &&
(u_axe_y <= b_circle_y) &&
(r_axe_x >= l_circle_x) &&
(l_axe_x <= r_circle_x);
InitWindow(width, height, "Probando esta gran Creacion");
SetTargetFPS(60);
while(WindowShouldClose()== false){
BeginDrawing(); //Starts drawing the screen
ClearBackground(BLUE); //Clears the canvas, must do this (otherwhise we get flickering)
if (collision_with_axe){
DrawText("GAME OVER", 400, 200, 20,WHITE);
}
else{
//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 collsion_with_axe
collision_with_axe = (b_axe_y >= u_circle_y) &&
(u_axe_y <= b_circle_y) &&
(r_axe_x <= l_circle_x) &&
(l_axe_x >= r_circle_x);
DrawCircle(circle_x, circle_y, circle_radius, WHITE);
DrawRectangle(axe_x, axe_y, axe_length, axe_length,RED);
axe_y += direction; //axe_y = axe_y +10;
if (axe_y>height|| axe_y<0){
direction = -direction;
}
if(IsKeyDown(KEY_D) && circle_x < width){
circle_x =circle_x+10;
}
if(IsKeyDown(KEY_A) && circle_x > 25){
circle_x = circle_x-10;
}
if(IsKeyDown(KEY_W) && circle_y > 25){
circle_y = circle_y-10;
}
if(IsKeyDown(KEY_S)&& circle_y < height){
circle_y = circle_y+10;
}
if(IsKeyDown(KEY_Q)){
circle_radius = circle_radius+10;
}
if(IsKeyDown(KEY_E)){
circle_radius = circle_radius-10;
}
}
EndDrawing(); //Ends drawing the screen
}
}