Axe Game showcase

Amazing course, simple to follow and easy to understand so far,
I’ve got experience with C# but I’m willing to learn C++ aswell since I love gamedev and UE5 is lookin pretty good these days.
Bought the course on sale and have 0 regrets, simply amazing!

I’ve made some changes and I wanted to share them and also give appreciation for your work.
Once again, amazing work!

Youtube video

#include "raylib.h"

int main()
{
    //window
    int width{1280};
    int height{720};
    InitWindow(width, height, "Axe Game");

    //circle
    int circle_x{640};
    int circle_y{360};
    int circle_radius{30};
    int circle_direction{10};
    //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
    int axe_x{1230};
    int axe_y{0};
    int axe_direction_h{10};
    int axe_direction_v{-10};
    int axe_length{50};
    //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};

    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)
    };
    bool game_started{false};

    int waitTimer{200};
    int currentWaitTimer{waitTimer};

    SetTargetFPS(60);
    while (!WindowShouldClose())
    {
        //edge update
        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;
        //collision update
        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);

        BeginDrawing();
        ClearBackground(RED);

        if (!game_started)
        {
            DrawText("Press SPACE to play!", width/2, height/2, 50, BLACK);
            if (IsKeyDown(KEY_SPACE))
            {
                game_started = true;
            }
        }
        else
        {
            if (collision_with_axe)
            {
                DrawText("Game Over!", width / 2, height / 2, 50, BLACK);
                if (currentWaitTimer > 0)
                {
                    currentWaitTimer--;
                }
                else
                {
                    game_started = false;
                    currentWaitTimer = waitTimer;
                    circle_x = 640;
                    circle_y = 360;
                    axe_x = 1230;
                    axe_y = 0;
                }
            }
            else
            {
                DrawCircle(circle_x, circle_y, circle_radius, WHITE);
                DrawRectangle(axe_x, axe_y, axe_length, axe_length, BLUE);

                //move axe
                axe_y += axe_direction_v;
                axe_x -= axe_direction_h;
                if (axe_y > height - axe_length || axe_y < 0)
                {
                    axe_direction_v = -axe_direction_v;
                }
                if (axe_x < 0 || axe_x > (width - axe_length))
                {
                    axe_direction_h = -axe_direction_h;
                }

                if (IsKeyDown(KEY_D) && circle_x < (width - circle_radius))
                {
                    circle_x += circle_direction;
                }

                if (IsKeyDown(KEY_A) && circle_x > circle_radius)
                {
                    circle_x -= circle_direction;
                }
            }
        }
        EndDrawing();
    }
}
4 Likes

Privacy & Terms