bool pixelcollision(BITMAP * backBuffer, int x, int y, int width, int height, int color)
{
if (getpixel(backBuffer, x - 1, y) == color || getpixel(backBuffer, x, y -1 ) == color ||
getpixel(backBuffer, x + width + 1, y) == color || getpixel(backBuffer, x, y + height + 1) == color)
return true;
return false;
}
So if the function returns true, the direction of the beam will change. I'm still trying to work out the trigonometry for the angle of changing the direction, so for the moment I'm just reversing the x and y coordinates of it.
if(pixelcollision(backBuffer, X, Y,width,height,makecol(0,255,0)))
{
directionx = directionx*(-1);
directiony = directiony*( -1);
}
This just makes the beam hit a green object and then reverse the direction it's heading in.
Blue box has hit the green box, so now the direction is x = 1, y = -1
No comments:
Post a Comment