From 92756db816a6e0fc7ff06c6fd83d512ecb4d61f6 Mon Sep 17 00:00:00 2001 From: tcsullivan Date: Sun, 25 Aug 2019 15:49:06 -0400 Subject: added SDL key events --- src/main.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 707c912..778ae73 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,8 +77,24 @@ void renderLoop(void) void logicLoop(void) { - // TODO handle logic - SDL_Delay(1000); - shouldRun.store(false); + using namespace std::chrono_literals; + + std::cout << "Press escape to exit." << std::endl; + + while (shouldRun.load()) { + for (SDL_Event event; SDL_PollEvent(&event);) { + switch (event.type) { + case SDL_KEYUP: + // Exit game on escape + if (event.key.keysym.sym == SDLK_ESCAPE) + shouldRun.store(false); + break; + default: + break; + } + } + + std::this_thread::sleep_for(100ms); + } } -- cgit v1.2.3