added simple editing mode and pause feature
This commit is contained in:
parent
3b7fbb86e3
commit
71fc46f9ab
48
gol.c
48
gol.c
@ -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();
|
||||
ClearBackground((Color){ 0, 24, 24, 255 });
|
||||
for(int i = 0; i < SIZE; i++){
|
||||
@ -92,30 +92,23 @@ 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();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool gamestate = false;
|
||||
|
||||
bool grid[SIZE][SIZE];
|
||||
bool mirror[SIZE][SIZE];
|
||||
|
||||
initialize_grid(grid);
|
||||
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);
|
||||
SetTargetFPS(FPS);
|
||||
@ -125,8 +118,29 @@ int main()
|
||||
|
||||
while(!WindowShouldClose()){
|
||||
|
||||
simulate_grid(grid, mirror);
|
||||
draw_grid(grid, cellw, cellh);
|
||||
if(gamestate == true){
|
||||
simulate_grid(grid, mirror);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user