Move view to keep player on-screen

This commit is contained in:
Camden Dixie O'Brien 2024-12-28 12:43:27 +00:00
parent e5752a5fe7
commit 10bb223bdd

View File

@ -234,6 +234,16 @@ int main(int argc, char *argv[])
ppos.y += (double)dt / 1000.0 * pvel.y; 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); SDL_RenderClear(renderer);
// Draw map // Draw map