flappychik

Silly SDL2 game
git clone git://bsandro.tech/flappychik
Log | Files | Refs

commit dfce13126b810d8981fb4c2536c731918c7fc0e0
parent 10466d2948dbe639e4089fd31aef75e25cc7666d
Author: bsandro <brian.drosan@gmail.com>
Date:   Mon, 14 Feb 2022 01:58:57 +0200

time-based event loop, platform-dependent render support

Diffstat:
Mmain.c | 15++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/main.c b/main.c @@ -13,7 +13,11 @@ int main(int argc, char *argv[]) { SDL_Event event; SDL_Init(SDL_INIT_VIDEO); +#ifdef __APPLE__ SDL_Window *screen = SDL_CreateWindow("flappychik", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_METAL | SDL_WINDOW_ALLOW_HIGHDPI); +#else + SDL_Window *screen = SDL_CreateWindow("flappychik", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI); +#endif assert(screen != NULL); SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); @@ -37,11 +41,12 @@ int main(int argc, char *argv[]) { SDL_RenderPresent(renderer); while (!quit) { - SDL_WaitEvent(&event); - switch (event.type) { - case SDL_QUIT: - quit = true; - break; + if (SDL_WaitEventTimeout(&event, 1000/60)) { + switch (event.type) { + case SDL_QUIT: + quit = true; + break; + } } SDL_RenderClear(renderer);