From 21f71be7e7872176d7aac102f5da2614d8c9b287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 13 Aug 2022 20:42:28 -0300 Subject: Fix bug making program unable to quit --- .gitignore | 1 + Makefile | 2 ++ life.c | 9 ++++++--- readme.md | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile mode change 100755 => 100644 life.c mode change 100755 => 100644 readme.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b10a05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +life diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3204b73 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +life: + gcc -o life -lSDL2 life.c diff --git a/life.c b/life.c old mode 100755 new mode 100644 index de8e1b8..b9a4971 --- a/life.c +++ b/life.c @@ -1,4 +1,3 @@ -#define SDL_DISABLE_IMMINTRIN_H #include #include #include "SDL2/SDL.h" @@ -67,8 +66,9 @@ int main(int argc, char **argv) { int rendertime = 0; char cells[WIDTH * HEIGHT]; init(cells, 1); - SDL_Event e; - while (e.type != SDL_QUIT) { + SDL_Event e = {0}; + int exit = 0; + while (!exit) { SDL_Delay(SPF); while (SDL_PollEvent(&e)) { if (e.window.event == SDL_WINDOWEVENT_RESIZED) @@ -87,6 +87,9 @@ int main(int argc, char **argv) { if (e.key.keysym.sym == SDLK_g) { grid ^= 1; } + if (e.key.keysym.sym == SDLK_q) { + exit = 1; + } } int mx, my; int mstate = SDL_GetMouseState(&mx, &my); diff --git a/readme.md b/readme.md old mode 100755 new mode 100644 index f251d95..2e85c42 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -Compilation: gcc -o life -lSDL2 life.c +Compilation: issue the ```make``` command Usage: life B S @@ -25,3 +25,5 @@ Keybindings: left mouse button draw right mouse button erase + + q quit -- cgit v1.2.3