I just have a question about how to implement collision on the bricks in the game breakout. I have come up with a system for the Y axis but everytime I try something for the X asist the ball just goes inside the brick and comes out on the other side. Does anyone have a way to do this, i saw on the community procject of breakout that they used gradients but it just confused me.
`get the distance between ball centre, and brick centre
dx#=(Balls.X+Balls.radius)-(Bricks(a).X+ Image Width(Bricks(a).Image))
dy#=(Balls.Y+Balls.radius)-(Bricks(a).Y+ Image Height(Bricks(a).Image))
dx2#=(Bricks(a).X+Image Width(Bricks(a).Image)*0.5)-(Bricks(a).Y+Image Height(Bricks(a).Image)*0.5)
dy2#=(Bricks(a).X+Image Width(Bricks(a).Image))-(Bricks(a).Y+ Image Height(Bricks(a).Image))
`get gradient of the line centre of brick to top right corner of brick
brickgradient#= dy2#/ dx2#
`get the gradient of the line joining the centre of brick to centre of ball
ballgradient#=dy#/dx#
`compare gradients - if ball gradient is between -brickgradient and + brickgradient, collision is with sides of brick, so reverse x-direction
If (ballgradient#)>=-brickgradient# And (ballgradient#)<=brickgradient#
Balls.MoveX=Balls.MoveX*-1
Else
Balls.Speed# = Balls.Speed#*-1
Endif
Thats the community project code but I have no idea how to change that so it applies my project at least the gradient part. Got it, i just had to wrap my head around what they ment by gradients. updated code to make more sense.
Thanks, Stefan