I put some arbitrary collision detection in place for my sprite library. As you can see from the post times I’m using this Bank Holiday to put some real coding effort in :)
I put the demo on line. Please feel free to take a look.
You can see that I’m using a simple box model and I put borders around each object to highlight.
I also wanted to highlight the damage flags that I placed on each object. Currently the player’s ship acts as a destroyer of all aliens. When an alien collides it depletes its hit points by however much damage the player’s ship can inflict. For illustration purposes I set the alien hit points to around 6 and the player’s ship damage to around 1. (i.e. it will take 6 strikes to destroy the alien!)
To further illustrate I coloured the alien’s border in line with how much damage it has taken. You can see quite clearly which alien has taken the most hits. Red is the final colour before destruction.
There are a number of things gained from performing these tests.
First and foremost I get to see the impact that collision detection (albeit basic) has on the actual sprite engine. I’m currently satisfied that this level of detection is enough for most simple sprite based games.
Secondly I can see just what kind of action I can design each game around. Ultimately the ship and aliens will be able to fire bombs and missiles at one another. Rather than “one hit and your dead” I can now consider Energy Shields and Power Ups. Such items can be implemented with great ease.