VBGamer |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Personally I Use ..... Adam Hoult (3 replies, 0 views) (2000-Jul-29) Personally i use a region technique, this allows me to envelope certain areas of the sprite, i.e I can distinguish between what part(s) of a players body has been hit. This is done by creating REGIONS around the pixels for the parts of the body, and checking them with a simple region intersection technique which i spent ages inventing =) (well it's not that hard, but took me a while to figure it). There is NO (or so small that it doesn't even effect the frame rate counter) speed loss, for pixel perfect collision detection when using this technique, and you have the added advantage of being able to determine if the enemy sword hit your head (instant death, with heads falling off etc =), or your legs (in which case your leg just drops off, and you hobble around hehe =)
It's so simple it's unreal..
If you know anything about creating win32 regions, then just define a polygonal winding region around the body/car/ship/plane parts you want to seperate (or around the pixels you are interested in).
Now to test if two regions intersect is fairly simple. There is no RgnIntersect api call like we have with Rect's but it's just as simple, NOTE: This just shows how to test if two non rectangular Win32 Regions are intersecting, not how to create them.
'Firstly create a rectangular region to store our combined output.
combinedrgn = CreateRectRgn(0,0,640,480) 'Or ResolutionX / ResolutionY
'Now combine your two regions which you are testing (i.e his sword with
'your players head)
tempret = CombineRgn(combinedrgn,Region1,Region2,RGN_AND);
'Now test to see if the non rectangular regions intersected
if (tempret<>NULLREGION) And (tempret<>ERROR) Then Collided=True
'Now clean up
DeleteObject combinedrgn
Do this for each thing you want to check, and voila. You could also go that little bit further (if you think this is a lot to do) by doing the rect test first, then if the rects are intersecting, then you can check against the regions for each sprite part. This can also be used very effectively for testing against tiles too. Create non rectangular regions on your maps which cannot be walked on (not just make a tile walkable/non walkable) that way, you can check collisions with just a rock on a tile, against the feet of your player etc.
Experiment, it's all good fun =)
Adam
Sysop
|