I now have the functions for detecting if a mirror is hit by the beam, and if so, what kind of mirror it is and how the direction of the beam should change.
Each mirror position (bottom left, top left, bottom right, top right) has its own function that detects if the beam has hit it. It knows what kind of mirror it has hit by checking he coordinates around it and matching them to the function. he function is passed in the bitmap, x coordinate, y coordinate and the colour so it knows exactly what kind of mirror it has collided with.
bool bottomleft(BITMAP * backBuffer,int x, int y, int colour)
{
if(getpixel(backBuffer, x - 10, y) == colour && (getpixel(backBuffer, x + 10, y + 20) == colour))
{
if(((getpixel(backBuffer, x - 10, y + 20) == colour) && (getpixel(backBuffer, x, y + 11) == colour )))
{
return true;
}
else return false;
}
else return false;
}
In main():
if(bottomleft(backBuffer,X,Y,makecol(255,0,0)))
{
directionx = 0;
directiony = -1;
}
No comments:
Post a Comment