r/C_Programming • u/kor_danggeut • 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
View all comments
Show parent comment
1
u/mysticreddit Jul 09 '26
I'll second (third?) this. Move the if-else to its own function.
Also, one can data-drive this by putting this in a table to make it trivial to change/extend. A linear search is fine, can always optimize to a binary search or hashmap lookup later.