This fortnight I am going to take a look at episode 8 of Twelve Months of Doomsday. It shared a fair bit of code with an earlier episode in the series (I'll leave determining which episode as a challenge to you) so development was fairly quick. The big thing with this episode was the addition of gravity. Some people who have played this game didn't think I made the gravity strong enough, but at the same time I didn't want it too overwhelming. If there is a future release of this game, I may tweak it a bit more.
In physics, gravity is actually the weakest of the known forces in the universe. It, however, acts across the length of the universe. The further away from an object the less gravitational influence that object will have. The formula for determining this is Force = Gravitational_constant * (object_1_mass * object_2_mass) / distance^2. For the game this is simplified. The planet's gravity is divided by distance squared of the ship from the planet in question resulting in the attraction to the planet. This is treated as acceleration. All five moons and planets are calculated and applied before any ship motion is done. The nice thing is that simply changing a planet or moon's gravity value is all that is needed to alter the gravity.
Originally, gravity was also applied to the alien ships as well. The problem is that the alien ship adjusts it's course every interval so it automatically corrects it's course. While there may have been a slight slowing down of the alien ships due to this correction vector being applied, the amount was not really noticeable. As this is a lot of calculating for no real result, I removed the gravity from the aliens. The result is a bit faster of a game, but on most systems this wouldn't be noticeable anyway.
The only other issue that really came up with the development of this game was the zooming in issue. My idea was that when the player came too close to a planet, there would be a crash animation. This was coded as the planet zooming towards the player. The problem was that the zoom animation code would for some strange reason zoom up and to the left of the planet. It took me a while to realize that I was pre-calculating the screen-offsets from the ship to keep the ship centred. While the zoomed play field scales, the size of the screen does not so the centring of the screen have to be done after the scaled coordinates of the ship are calculated. A simple enough mistake that should not of taken the hour it took find. A debugger may be your friend, but when the calculations look correct it is sometimes hard to see what the tool is showing you.
Other than playing around with gravity and alien shooting accuracy, about the only other change I would consider making to this game would be to rework the alien movement system so that alien ships appear to also be affected by gravity. Not quite sure how I would go about doing this but if I revisit this game I will try to come up with something.
Post a Comment