I know there's a term for this - not sure what it is. Anyway, I have a 2d tile engine for a game. In the tile data, there is a single number for the collision data. Each quadrant of the tile has it's own collision detection, so all the flags are represented as one number.
Maybe it would be easier to understand if I pasted my code:
Code:
stringstream stream(buffer);
int collision;
//converts the hex value into an int
stream>>hex>>collision;
//if collision is 0 then it doesn't collide with anything
if (collision>0)
{
if (collision>=8)
{
collision-=8;
collideBR=true;
}
if (collision>=4)
{
collision-=4;
collideBL=true;
}
if (collision>=2)
{
collision-=2;
collideTR=true;
}
if (collision>=1)
{
collision-=1;
collideTL=true;
}
}
This works fine, does what I need. It just seems sloppy to me. The collideTL BL etc stands for top right, bottom left, etc. Is there a cleaner way to do this?