Aloft Dev Log 4: A bit of background
So far I've mainly talked about the physics aspects of the game, but have been vague on what the game itself will look like - time to change that.
Part of the reason I decided to make Aloft a 2D game, aside from keeping the physics manageable, is that I've always really want to try my hand at a parallax scrolling background. For those not familiar with it, parallax scrolling in games is a technique where multiple 2D background layers are rendered and then scroll at different speeds in response to player movement, simulating a shifting 3D perspective. As a child I played lots of games that used this technique, and I still find it really effective at conveying forward motion and progress while remaining elegantly simple.
In most games however the parallax background would be relatively restricted - it would react to sideways movement, and a bit of vertical movement, but the changes would be slight. For Aloft the background will need to adapt to the altitude of your airship from ground level up to several kilometres high, it would have to change dynamically to show different kinds of terrain as you explore the world and it would need to display a full day night cycle.
To start with I used the 3D modelling program Blender to create an animation of a side on view of an airship flying vertically and horizontally against a background which was simple 3D representation of the world built to scale with the airship in Blender. This proved very valuable, as it immediately highlighted to me what the key variables for such a background would be - the simulated field of view of the game "camera", and the distance at which the 2D background "tiles" were placed from the airship.
Here is that animation:
After that, I got to work making a prototype. The first thing I needed to do with the prototype is come up with a dynamic system to position the background tiles on the screen - I wanted this to be as accurate as possible, so I set it up so that it works out the positions required for background tiles from first principles based on the radius of the Earth, airship altitude and desired virtual camera FOV. Here is a shot of my debug tool showing the output of that system (this is shown head-on to the airship, rather than the games side-on view); the white line is the surface of the Earth, the blue dot is the airship, the yellow lines represent the limits of camera field of view (yellow dots where it intersects the Earth) and the green dots are where the game has calculated it must place background layers of a given height in order to fully cover the "ground" in the 2D view from the base of the screen to the horizon:
This took some effort, but once this system was working it was a comparatively simple job to have the game properly fill the screen with some background tiles I created and have them respond to player movements. Here is a gif of the result (note the terrain sprites are just for testing - the game itself will have better assets):
If you are interested each layer here is spaced a simulated 50km apart, with the horizon being about 250km away. The airship is going much faster than it would in reality, to emphasise the scrolling effect.
After that I started thinking about day/night cycles. This was easy to do with some simple colour blending on the terrain - blend black onto the terrain at night, and darken the sky - but I wanted to push it a little further. Because I had made a 3D model of the terrain, I was able to extract some depth information of it from Blender very easily using a normal map. I took this information and created new rendered layers for the terrain showing which contained only the shadows at dawn/dusk, and then re-rendered the original terrain without shadows. By blending these elements together based on time of day, I was then able to simulate moving lighting on the 2D terrain.
Now before anyone points it out - yes, I know the Sun does not both rise and set in the same place and that the lighting in the "morning" is therefore wrong; I just have it setup like that at the moment so I can test both sunrise and sunset easily.
I think you can see, based on the above, how I can now easily go on to implement things like clouds layers at different heights, fog and other weather effects with relative ease. The major challenge left is transition from one tile set (say the desert) to another (like the sea) but I have quite a few ideas on how to do it.
Thanks for reading all that, hopefully it was interesting.