tags:

views:

43

answers:

1

I have a UIImage. There are 3 colors, white (=sky), black (=player) and green (=floor). When the black player collides with the white sky only, i make him fall down. When he collides with the white sky AND with the green floor, i stop him.

The Image: http://img39.imageshack.us/img39/4290/colormapb.jpg

Now my question: How can i read the colours and make the player colliding with it?

The programmers of 30 day game made the color map collision too.

thanks, domp

A: 

Is the layout random? If not, just make a list of the bounding boxes of the "fall" areas, and check the black "player" box against that list of "fall" boxes.

Let's say you are storing your full list of "fall" boxes in a C array "fallBoxes" with size fallBoxCount. // You could use an NSArray but the code is easier this way.

// playerBox is the rect for the current position of the black "player" box.

for (int i = 0; i < fallBoxCount; ++i)
{
    CGRect testBox = fallBox[i];
    if (CGRectContainsRect(textBox, playerBox)
    {
        // Fall!
        break;
    }
}
Amagrammer