I was working on my collision detection for my DBZ clone of Liero today, and I was presented with a problem. For any of you who know Liero (which is much like Worms), you will know that the map is displayed like this:
Background bitmap
"Dirt" or deformable terrain bitmap
"Rocks" or impassibles
The background is a single bitmap blitted onto the screen. The "dirt" is also a single bitmap blitted onto the screen, but with several spots where it is transparent, so you can see the background, and the dirt can be deformed, so more of the background shows.
The rocks cannot be changed. That is also the order in which things are blitted onto the screen.
Now, keeping in mind how the map is displayed, here is how it is done in my DBZ clone:
Background
Foreground
My game does not have a deformable foreground as of yet like Liero does, but basically everything in the background is the background, and everything in the foreground can be collided against.
Now how would you do collision detection? Lets say you have a 20x25 character moving along who bumps into a wall while moving right along the screen.
You cannot just check the coordinate (20, 0) for a collision, because the collision could occur at (20, 24)...at the bottom of the guy....but you cant check just (20, 25), because the collision could occur at (20, 0), and you cannot just check (20, 13) (the middle right) because the collision could occur above or below that....
That means that you must check every coordinate of (20, x)...where "x" is greater than 0 and less than 25.....
That means you must make 25 comparisons every time the guy moves right or left.....which could be happening very often....doesnt that seem a bit taxing on the computer to make 25 comparisons every time the guy moves right or left.
Lets say you move to the right for 1 second...which is very likely and very possible....and lets say you are getting 50 fps...that means you must do 50x25 comparisons....which is 1250 comparisons in just 1 second of moving to the right....not to mention having to do all the other stuff like blitting graphics, etc...
How much do you think that would tax the game? Is there a better way to do the collision detection then that? I'd like any input I can get....thanx...