Saturday, 21 April 2012

Final collisions

I have now put in the final collision detection functions. The beam will now know if it has hit the back of a mirror, and if it has, it will stop and the user has failed the level. The code uses the same idea as the detection for hitting the angled side of the mirror:

//Back of BR & TR mirror
if((getpixel(backBuffer,X-1,Y) == makecol(0,255,0)) && (getpixel(backBuffer,X-1,Y+10) == makecol(0,255,0)))
{
if(   (getpixel(backBuffer,X-21,Y+20) == makecol(0,255,0) || getpixel(backBuffer,X-21, Y+10) == makecol(0,255,0))
|| (getpixel(backBuffer,X-21,Y) == makecol(0,255,0) || getpixel(backBuffer,X-21, Y-10) == makecol(0,255,0))
)




{
directionx = 0;
directiony = 0;
}



I also pass the target to hit into the bounding box collision function, to see if the player has hit it. If the beam has hit the yellow target box, the level has been won. However, if the direction of the beam is = 0,0, and the target hasn't been hit, the user has failed the level.
















Level has been completed











Level has been failed



No comments:

Post a Comment