I wanted to make a breakout game, the game is almost complete but I'm struggling to figure out how to code in side collisions for the game. I want to make it so that if the ball hits the left or right side of a block, it will change the horizontal direction (whether it goes right or left) but wont change the vertical direction (whether it goes up or down), and if the ball hits the top or bottom of the block its vertical direction will change, but its horizontal wont.
This is roughly what I have for those collisions right now, but the if statement is never true (the ball is never at the correct x position when it hits a block)
if GetSpriteCollision(gBall.id,gBlock[i].id)
if gBall.x = gBlock[i].x + blockx or gBall.x = gBlock[i].x - gBall.size //not working, code to check if ball hits the left and right side of a block
gBall.dirx = gBall.dirx *-1
else
gBall.diry = gBall.diry *-1
endif
endif
If anyone could help me out, it'd be greatly appreciated.