IOCT Masters in Creative Technogies
Major Project
An augmented reality game based on "Breakout"

Wednesday 2 July 2008

Brick collision from above

Collision detection to the top edge of the brick when the ball is travelling from above.



y1 = previous ball posy – bricks1[0].posy – bricks1[0].halfheight – radius – 1
t = y1/vely
x1 = t*velx

tempballposx = previous ball posx – x1
tempballposy = previous ball posy – y1

for (i=0; i<12; i++)
if (tempballposx >= bricks1[i].posx – halfwidth && tempballposx =< bricks1[i].posx + halfwidth)
if (bricks1[i].numberhits < level) //Check brick still exists
bricks1[i].numberhits++ //Add one to hit count
vely = - vely //Reverse ball direction
ballposx = tempballposx + (1-t)* velx //Check final ball position
ballposy = tempballposy + (1-t)* vely //Check final ball position