r/C_Programming • • Jul 09 '26

Code of the first game

This is the first code I wrote. What do you think?

#include "raylib.h"

int main(void) { InitWindow(800, 600, "Color Changing Ball Clicker"); SetTargetFPS(60);

int money = 0;
Color color = RED;

while (!WindowShouldClose())
{
    if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
    {
        money = money + 1;
    }

    if (money < 100)
    {
        color = RED;
    }
    else if (money < 200)
    {
        color = BLUE;
    }
    else if (money < 300)
    {
        color = GREEN;
    }
    else if (money < 400)
    {
        color = GOLD;
    }
    else if (money < 500)
    {
        color = PURPLE;
    }
    else
    {
        color = MAROON;
    }

    BeginDrawing();

    ClearBackground(RAYWHITE);

    DrawCircle(400, 300, 80, color);

    DrawText(TextFormat("money: %d", money), 20, 20, 30, BLACK);
    DrawText("Click to change the ball color!", 20, 60, 20, DARKGRAY);

    EndDrawing();
}

CloseWindow();

return 0;

}

2 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/sciencekm Jul 09 '26

I think a structure and a loop containing a condition seems like an overkill. Please see my reply to the OP.

2

u/mysticreddit Jul 10 '26

Game dev is always about balancing speed vs flexibility.

A simple mapping works until it doesn't.

I don't know what the future balance needs are for the game but if they don't need to balance then a linear solution is fine. If they DO need to tweak & balance then a table data-driven approach is far superior for flexibility.