I was somewhat getting into the same subject over in this thread. This might be a good time to differentiate screen space from world space, and implement a simple camera that is capable of mapping between the two.
In your current code, I'm guessing that player.x is a number that simply represents pixels on the screen. Your world space and screen space are identical, which makes it impossible to view different parts of your world within the same screen area. What you want to achieve instead is to get player.x to refer to some number that is specific to world space, in whatever units you prefer. Meters are common, but any unit of distance will work, even the completely fabricated unit "geeko". Whatever is easiest for you to conceptualize when thinking about distances within your game's world.
So if you know where your player is in the world, how do you determine where they should be drawn on the screen? You use the concept of a camera. The simplest 2D camera will store the position of the camera, preferably in world space. Additionally, it's best to also include a zoom factor, even if it never changes. This relates your world's unit of distance to the screen's unit of distance. Pixels per meter, for example.
So let's say your player's horizontal position in your level is 20 meters. If you also know that your camera's center is looking at the part of your level 18 meters in, then we know that the player is 2 meters to the right of the camera. If we further know that the camera is zoomed in such that there are 64 pixels per meter, then we can determine that in screen space, the player will be 128 pixels to the right of the camera's center. Assuming we have a fixed-size viewport, and the camera's center corresponds to the exact center of that viewport, we can then determine that the player should be drawn 128 pixels to the right of the viewport center.
In code, you might have this function (assuming Point2D, Camera, and Viewport are appropriately defined structs/classes with the necessary members):
Point2D ConvertWorldToScreen(Point2D world, Camera camera, Viewport viewport)
{
return new Point2D(
(world.x - camera.x) * camera.screenUnitsPerWorldUnit + viewport.width / 2,
(world.y - camera.y) * camera.screenUnitsPerWorldUnit + viewport.height / 2);
}
This can naturally work for any object in your world, not just your player.
Sometimes you'll need to also take a screen space position and convert it to world coordinates. If, for example, you handle mouse clicks. Alternatively if you need to know the world space position corresponding to one of the corners of your viewport. This function will handle that:
Point2D ConvertScreenToWorld(Point2D screen, Camera camera, Viewport viewport)
{
return new Point2D(
(screen.x - viewport.width / 2) / camera.screenUnitsPerWorldUnit + camera.x,
(screen.y - viewport.height / 2) / camera.screenUnitsPerWorldUnit + camera.y);
}
Once you have infrastructure like this, and all your objects are represented in world space, all you need to do now is figure out where your camera should be and redraw. The simplest method is to use a camera locked to your player. camera.x = player.x and camera.y = player.y. Your player will now always be in the exact middle of your viewport, no matter where in the level they are. This has some subjective disadvantages, though, so you might want to look into some more advanced systems of managing the camera. This page has a good overview of options and concerns to consider.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke