After reading the recent article on cameras in sidescrolling games I thought I may as well share how the camera works in Sol. I'm going to use some terms from that article so consider reading it first if you haven't already.
First of all, some remarks:
- Screen coordinates are given relative to the center of the screen (not the top left corner) because of the way resolution handling works for different aspect ratios. Horizontal coordinates increment to the right, vertical coordinates increment downwards.
- The "player origin" is 16 pixels above the ground vertically (the character is 40 pixels high, for context).
The camera works differently depending on whether zooming is enabled or not, so I'm going to describe both modes separately.
The game simply uses a normal camera window in this mode. The margins are -8 to 8 horizontally, and -32 to -16 vertically.
When the camera shakes (i.e. a quake effect), a vertical offset is added to its current position. This offset is calculated the moment rendering happens and is not stored, i.e. the shaking isn't accounted for the camera window.
When zooming is enabled the camera behaves completely different to account for the smaller viewport.
For starters there isn't a camera window at all, it just aims for the player position directly. Then it applies a horizontal offset, to give some extra room to see forwards. This offset changes depending on the direction the player is facing, when the player turns around the offset is shifted until it reaches its new intended position. Pressing up or down also applies a vertical offset in a similar way, allowing the player to look more vertically.
The third boss (the helicopter one) is problematic, since the helicopter would end up completely off-screen using this behavior. What happens then is that during the fight against that boss another vertical offset is applied, which puts the camera right in the middle point between the helicopter's height and the previously computed camera position. This gives enough room to see the helicopter.
Finally, shaking is disabled unconditionally when zooming is enabled, since the effect is too strong and would severely get in the way.