added simple editing mode and pause feature

This commit is contained in:
Marcelina Szostak 2025-07-01 13:57:26 +02:00
parent 3b7fbb86e3
commit 71fc46f9ab
Signed by: kapcioszek
GPG Key ID: 5B07EB46181A963B

46
gol.c
View File

@ -82,7 +82,7 @@ void simulate_grid(bool grid[SIZE][SIZE], bool mirror[SIZE][SIZE]){
} }
void draw_grid(bool grid[SIZE][SIZE], int cellw, int cellh){ void draw_grid(bool grid[SIZE][SIZE], int cellw, int cellh, bool gamestate){
BeginDrawing(); BeginDrawing();
ClearBackground((Color){ 0, 24, 24, 255 }); ClearBackground((Color){ 0, 24, 24, 255 });
for(int i = 0; i < SIZE; i++){ for(int i = 0; i < SIZE; i++){
@ -92,31 +92,24 @@ void draw_grid(bool grid[SIZE][SIZE], int cellw, int cellh){
} }
} }
} }
if(gamestate == false){
DrawRectangle((GetMouseX()/cellw)*cellw, (GetMouseY()/cellh)*cellh, cellw, cellh, WHITE);
DrawText("LMB: Draw, RMB: Erase, Space: Start/Stop the game, ESC: Exit", WIDTH*0.15, HEIGHT*0.9, 20, WHITE);
}
EndDrawing(); EndDrawing();
} }
int main() int main()
{ {
bool gamestate = false;
bool grid[SIZE][SIZE]; bool grid[SIZE][SIZE];
bool mirror[SIZE][SIZE]; bool mirror[SIZE][SIZE];
initialize_grid(grid); initialize_grid(grid);
mirror_grid(grid, mirror); mirror_grid(grid, mirror);
grid[SIZE/2][SIZE/2] = true; //drawing famous glider
grid[(SIZE/2)+1][(SIZE/2)+1] = true;
grid[(SIZE/2)-1][(SIZE/2)+2] = true;
grid[(SIZE/2)+0][(SIZE/2)+2] = true;
grid[(SIZE/2)+1][(SIZE/2)+2] = true;
//grid[(SIZE/2)][(SIZE/2)] = true; //funny pattern
//grid[(SIZE/2)+1][(SIZE/2)] = true;
//grid[(SIZE/2)+1][(SIZE/2)-1] = true;
//grid[(SIZE/2)+1][(SIZE/2)-2] = true;
//grid[(SIZE/2)-1][(SIZE/2)] = true;
//grid[(SIZE/2)-1][(SIZE/2)-1] = true;
//grid[(SIZE/2)-1][(SIZE/2)-2] = true;
InitWindow(WIDTH, HEIGHT, TITLE); InitWindow(WIDTH, HEIGHT, TITLE);
SetTargetFPS(FPS); SetTargetFPS(FPS);
@ -125,8 +118,29 @@ int main()
while(!WindowShouldClose()){ while(!WindowShouldClose()){
if(gamestate == true){
simulate_grid(grid, mirror); simulate_grid(grid, mirror);
draw_grid(grid, cellw, cellh); draw_grid(grid, cellw, cellh, gamestate);
}
else{
if(IsMouseButtonDown(0)){
grid[GetMouseX()/10][GetMouseY()/10] = true;
}
if(IsMouseButtonDown(1)){
grid[GetMouseX()/10][GetMouseY()/10] = false;
}
draw_grid(grid, cellw, cellh, gamestate);
mirror_grid(grid, mirror);
}
if(IsKeyPressed(KEY_SPACE)){
gamestate = gamestate == true ? false : true;
}
if(IsKeyPressed(KEY_ESCAPE)){
CloseWindow();
}
} }