flappychik

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

commit ce79c14674a867237d45c54431e05f3efb3acfda
parent f1b185e337cc83f0bdee4708a2a7f8066862f4cb
Author: bsandro <brian.drosan@gmail.com>
Date:   Mon, 14 Feb 2022 03:52:57 +0200

variable speed & framerate

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

diff --git a/main.c b/main.c @@ -11,6 +11,9 @@ #define WINDOW_FLAGS SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI #endif +#define FPS 60 +#define SPEED 240 // pixels per second + int main(int argc, char *argv[]) { (void)argc; (void)argv; @@ -55,16 +58,19 @@ int main(int argc, char *argv[]) { uint64_t t1 = SDL_GetTicks64(); - if (t1 - t >= 1000/60) { + if (t1 - t >= 1000/FPS) { SDL_RenderClear(renderer); + uint64_t ftime = t1 - t; + int offset = round(ftime * SPEED / 1000.0f); + printf("offset: %d\n", offset); - knife_rect.x += 1; - knife_rect.y += 1; + knife_rect.x += offset; + knife_rect.y += offset; SDL_RenderCopy(renderer, tex_bg, NULL, NULL); SDL_RenderCopy(renderer, tex_knife, NULL, &knife_rect); SDL_RenderPresent(renderer); - printf("frame time: %llu\n", t1 - t); + printf("frame time: %llu\n", ftime); t = t1; } }