Move view to keep player on-screen
This commit is contained in:
10
app/main.c
10
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
|
||||
|
||||
Reference in New Issue
Block a user