Lazarus![]() Member Posts: 1668 From: USA Registered: 06-06-2006 |
Hey guys. ![]() I'm working on a program with a two dimensional maze.(GLBasic, btw) Now I have the keyboard controlled sprite - another image. Any ideas? (Yeah - GLBasic's built-in collision commands don't seem to be much use here - the two of them that there are.) |
|
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
well as long as you can get access to the raw image data in your background and the sprite you'll be set to do per-pixel collision detection. Now, best thing would be to make sure that the background image and the sprite are able to match up (as in if the background image is 800x600 that you don't stretch it to say 1024x768 or down to 400x300 (unless your willing to put in scaling code as well)). You'll have your offset for your sprite in screen coords, so all you need to do is check your sprite to the background image offset so that you only check sprite.width X sprite.height on both the sprite and the background image. I hope I'm explaining it well enough... Some pseudo/c++ code:
I don't know if that is like 'standard practice' for per-pixel collision detection, but it *should* would. I haven't compiled it or anything, so there could be some mistakes. So I hope that helped... I know it's not in GLBasic, but hopefully it'll guide you in the right way ------------------ |
|
Lazarus![]() Member Posts: 1668 From: USA Registered: 06-06-2006 |
Well, I'll try it out. Thanks Dart. ![]() |
|
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
No problem... just let me know how it goes, or if you need more explained... The pain will be the collision response, unless you just use the old position if the new position isn't good. ------------------ |
|
Lazarus![]() Member Posts: 1668 From: USA Registered: 06-06-2006 |
I've tried several different ways(including per-pixel collision detection - thanks again for your example, Dart) - still problems. Either GLBasic has a bug in its collision detection functions or I'm really messing up somewhere. Oh - with collision response, I just use the old position if the new one is invalid. |
|
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
What problems are you having? Have you looked into basic bounding box collision detection? ------------------ |
|
Lazarus![]() Member Posts: 1668 From: USA Registered: 06-06-2006 |
Well I'll be... I figured out the problem - just a simple if/then bug. *slaps forehead* Well, thanks Dart. |
|
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
yep, sounds good ![]() ------------------ |