Sprite collision using hit points & damage

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 :)

The collision detection works quite nice with slow down kept to a minimum. (I’m currently testing with around 100 sprites on screen). The JavaScript engines in the major browsers seem to hold up fine.

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.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: