Ball colliding with square
I am trying to make a brick breaker style game and cannot correctly make the ball bounce off the square. it'll sometimes bounce off, other times it'll go right through, and it never bounces off from the side. here's the code where b is the ball and k is the bricks:
if collision(b.x,b.y,b.width,b.height,k.x,k.y,k.width,k.height) then
if (k.y >= b.y+b.height/2 or k.y <= b.y-b.height/2)then
b.speedY -= b.speedY*2
elsif k.x >= b.x+b.width/2 or k.x <= b.x-b.width/2 then
b.speedX -= b.speedX*2
end
end