From 10bb223bdde6e664cf24b3b18ae9b20d1d1aa70b Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 28 Dec 2024 12:43:27 +0000 Subject: [PATCH] Move view to keep player on-screen --- app/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/main.c b/app/main.c index 699cca5..73fa03b 100644 --- a/app/main.c +++ b/app/main.c @@ -234,6 +234,16 @@ int main(int argc, char *argv[]) ppos.y += (double)dt / 1000.0 * pvel.y; } + // Update view + const dvec_t pvdisp = { + .x = ppos.x - (vpos.x + VIEWWIDTH / 2), + .y = ppos.y - (vpos.y + VIEWHEIGHT / 2), + }; + if (mag(pvdisp) > 72) { + vpos.x += (double)dt / 1000.0 * pvel.x; + vpos.y += (double)dt / 1000.0 * pvel.y; + } + SDL_RenderClear(renderer); // Draw map