I’ve been sitting with this silly issue for a while. It’s stupid, and I hope it helps to get some other eyes on it.
I want the map indentation to move as fast as the player, if the player is near the edge of the screen.
Currently, I can outrun the scroll. It should be scrolling at the same speed as the player, so the player can never touch the edge of the screen.
/* moving the player */
float newX = player.x, newY = player.y;
if(input.isKeyDown(Input.KEY_UP)) {
newY -= player.movementSpeed;
} else if(input.isKeyDown(Input.KEY_DOWN)) {
newY += player.movementSpeed;
} else if(input.isKeyDown(Input.KEY_LEFT)) {
newX -= player.movementSpeed;
} else if(input.isKeyDown(Input.KEY_RIGHT)) {
newX += player.movementSpeed;
}
if (newX + mapIndentX <= 16 * 4) { // four tiles from the border
mapIndentX += player.movementSpeed;
}
/* do collision detection here, roughly. */
player.x = newX;
player.y = newY;