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

Wednesday 2 July 2008

Brick collision from below

Collision detection to the base edge of the brick when the ball is travelling from below.

y1=(bricks1[0].posy-bricks1[0].halfheight) – previous ball position – 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].number hits++ //Add one to hit count
vely = - vely //Reverse the ball direction
ballposx = tempballposx + (1-t)* velx //Check final ball position
ballposy = tempballposy + (1-t)* vely //Check final ball position