Updated map flipping, fixed offset collision issue, added title safe overlay image.
More Bounds Checking
Noticed that the right bounds wasn’t symmetric with the left bounds. I had 200 pixels for each bounds, but forgot that I needed to subtract off 48 for the right bounds to account for the player’s width. This set the right bounds at a location that was not a multiple of 5 (1032 = 1280 – 200 – 48), which caused problems since the player’s walk speed is 5 pixels. Thefore, when the player’s location and velocity passes the right bounds, then I have to calculate the difference between the bounds and the new location. I set the player’s location to the right bounds, and add the difference to the level scroll offset.
The flipping between maps was working really well, but I forgot one case which is really noticeable when it happens. I am only checking for map flips when the player is at either the left or right bounds. However, it is possible for the player to backtrack and cross the boundary between rooms, when the boundary in the middle of the screen between the two bounds. However, this is fairly simple to calculate. If is between the two bounds, and the player’s X position is less than room offset, then flip back to the map on the left. If the player’s position and the negative offset are greater than the room size, then flip back to the map on the right.
Title Safe Overlay
Found a nice PNG layover on the XBox Creators Club forums which shows the title safe area for a 1280×720 screen, which can just be drawn over the game screen, since the center of the image is transparent.
Since the player falls at a rate of 5 pixels per update, there is a small problem when the user falls to the ground which may not be noticeable. Since the tiles are not multiples of 5, then the calculation of the next fall frame may indicate a collision and the player should stop falling. However, this will cause the player to stop at the multiple of 5, which may be a few pixels above the actual ground. This is not really noticeable until the hit box is drawn around the player graphic.
This is also a problem when running into blocks, since the player runs at 5 pixels per update. Turning up the run and jump speed to a higher value (like 20) makes this issue more noticeable.
To fix this, I went ahead and updated the player’s location to the block boundary in the collision method. Originally, I just had the collision method return true or false, based on if they have collided with a block. Updating the player’s location in the collision method probably isn’t the best programming style, but I really didn’t feel like calculating the number of offset pixels, making new variables, and passing out the number of offset pixels to the calling method which is bad style in itself. Probably the most elegant solution would be to return a Vector (x, y pair) containing the number of offset pixels, or null if the player has not collided with any blocks.