I have been looking at doing some work on blowing things up now that I have laser fire in the Freeform Space engine. In order for the player to blow things up, I first have to create some collision detection code in order to detect when something has collided with something else. I figured that the easiest way to do this would be to create a test case with an asteroid field - after all, asteroids don't require all the clever AI that enemy star ships do.Thinking about asteroids led me to improving the planet that I had got in the online demo because I wanted my asteroids to spin and not be static. The planets also would look better if they rotated (and I don't mean the standard rotation in flash along the middle of the bitmap, rather, the centre of the sphere as planets are spheres). To create a believable 3D effect involved some clever actionscript, a class that replicates an infinite background (in the same way as the parralax starfields work) but using a circular mask that is created at runtime. Finally, to give the illusion of 3D, a radial gradiant masked black image is put on top, so the edges of the planet taper off into darkness.
All of this has been more difficult to program than I initially thought, mostly because the engine is frame rate independent. This means that if the frame drops, the speed of things does not. For example, the speed of the ship is constant whether you are running at 1FPS or 100FPS, but at 100FPS you get a much nicer, smoother display. This is what you normally get from a 3D engine and its fun (although time consuming) to add it to a 2D one.
The current online demo features a single asteroid and some pixel perfect collision. You can test this by flying the ship close to the asteroid, when it gets really close the shield will dim slightly (this is the radial distance check collision which is really fast to do) but when you get even close the shield will dim a lot (this is when the pixel perfect testing has picked up a real collision between pixels). You will notice that when the radial detection is triggered, the frame rate will drop as the expensive pixel perfect collision detection is switched on. In general, engines will approximate as much as they can for speed reasons and if you monitor the frame rate you will see why I have taken this approach.
I still have lots of issues to sort out, such as getting the laser shots into the collision detection tracking so that the asteroid could be destroyed. I've also been bug fixing an issue that could cause the X and Y coordinates to become infinite on a long load time but it seems I still have some inconsistencies in there - sometimes the planet shadow on the current demo is incorrectly place and a refresh of the page is required. Lots of fun.

No comments:
Post a Comment