Archived

This topic is now archived and is closed to further replies.

2D collision detection using color collision map

This topic is 5579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I really want to use a collision map for collision detection for the background. Basically using 2 backgrounds 1 the background picture and the other all white with black areas where you can not go. I would load the second map into an HDC or something. On this second map I plan on using GetColor(...) at the point of my character to recieve the RGB and if its black i know i hit. The problem is that I am writing my 2D game using direct 3D and the character moves in screen quardinates and GetColor(...) asks for a pixel point. My objects are 10z away from the camera and the screen resolution is 800 by 600. "What is the formula to convert screen quardinates into pixel quardinates or is there a better way to do a collision map like I explained" or better yet "Is there a GetColor(...) formula for recieving color from a texture at a certain point?" Thanx!

Share this post


Link to post
Share on other sites
everyone seems to think its a bad idea . I think i figured out a way to do it but put it to me straight...

In terms of easy use of collision detection by drawing a collision map background vs speed on a newer decent computer ( 400mhz and up )... is it really that bad? By doing this I would be able to easily pump out levels and collision detection as fast as I can draw the level.

What are my other options since boxes, circles and so on are not much of an option since im doing 2D backgrounds that cant be mapped with bounding boxes or bounding circles very accurately.

With the exception of writing my out a GetColor() function in assembly is there a faster way. How do people do collision detection on 2D backgrounds with wierd shapes that dont fit bounding boxes...



[edited by - goomyman on September 6, 2002 2:40:54 AM]

Share this post


Link to post
Share on other sites
I had a similar problem, but I did like this, I read the color map and then stored it into a bool array of
[screen_width][screen_height], then you preload the map and for every black you encounter, you set the [x][y] of the bool to true.

Share this post


Link to post
Share on other sites
Maybe you can use something like this pseudo-code

bool Collision[x][y];
int x;
int y;
COLOR value

for (x=0; x<800;x++)
{
for (y=0;y<600;y++)
{
//getcolor here
value = GetColor(x, y);

switch (value)
{
//collision = true
case BLACK:
{
Collision[x][y] = 1;
break;
}

case WHITE:
{
Collision[x][y] = 0;
}
}
}


Of course i don''t know the syntax of getcolor() and such, but i am sure you catch the idea. For the colo switches you just use a couple of #defines.


Succ6

Share this post


Link to post
Share on other sites
quote:
Original post by goomyman
How do people do collision detection on 2D backgrounds with wierd shapes that dont fit bounding boxes...



this is how i did it. bah! now i remebered that got deleted, so i can''t show it to you anymore. but i can show you an article i got a few ideas from. here you go; it''s pdf format.

---
shurcool
wwdev

Share this post


Link to post
Share on other sites
preloading the bitmap into an array will work... good idea. So when i preload it.. i use GetColor() on every pixel and load it into a bool of true/false. Alright guys thanks a lot I like the it.


ok now what about the problem of screen quardinates vs pixels.

Since my collision map will be in pixels and my character moves across the screen in screen quardinates how do i convert them? Whats the formula.

edit- hey wow im linked to the front page.. no wonder i got so many replys.

[edited by - goomyman on September 7, 2002 7:55:48 PM]

[edited by - goomyman on September 7, 2002 8:00:09 PM]

Share this post


Link to post
Share on other sites