java game collision algo
hello , i'm a computer science student and we have a machine project on making a java game. Well , our game is mostly a mixed bomberman-finalfantasy tactics type of 2d game. However , i couldnt seem to figure out the algorithm behind the object collision/interaction (for example , how will the character attack a box or another character) i used an x,y coordinate system and any help is gladly appreciated.
This is a non-trivial topic. If you look at gamasutra.com or other game programming sites you can find whole articles written about it.
But here's a quick version: for any character, keep a bounding rectangle around it. Then to see if any two characters collide, check their bounding boxes. If their bounding boxes do not collide, then the characters do not -- this will be the case most of the time, and it's less expensive to compare boxes. If the boxes do collide, then you can use a more subtle collision detection mechanism to see if the characters themselves collide.
HTH.
I would generate a bitmap, where the bitmap position (x,y) is one when the two characters collide when character b is x to the right and y below character a. Then, it's merely a case of calculating the relative distance between the two characters, and looking up that index in the bitmap to see if there's a collision. You can make this bitmap a multibit bitmap if you'd like different levels of collision damage, depending on how the two objects interact.
The nice thing is that this bitmap can be created offline