Hello,
I am trying to make my own version of dx ball the code was written from scratch, and i'm having problems with the collision detection, it works when the ball hits the bottom of the brick, but it doesn't work with any other side, here is the code i'm using:
vb
Dim vmom As Integer
Dim hmom As Integer
Dim img1_top As Integer
Dim img1_left As Integer
Dim img1_right As Integer
Dim img1_bottom As Integer
Dim img2_top As Integer
Dim img2_left As Integer
Dim img2_right As Integer
Dim img2_bottom As Integer
Private Sub Form_Load()
vmom = 50
hmom = 50
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpPlayer.Left = X - (shpPlayer.Width / 2)
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub mnuStart_Click()
shpBall.Top = 6100
shpBall.Left = 9200
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
shpBall.Top = shpBall.Top - vmom
shpBall.Left = shpBall.Left - hmom
If (shpBall.Top + shpBall.Height) > shpPlayer.Top Then
If shpBall.Left + shpBall.Width >= shpPlayer.Left And shpBall.Left <= shpPlayer.Left + shpPlayer.Width Then
vmom = -vmom
End If
End If
img1_top = shpBall.Top
img1_left = shpBall.Left
img1_right = shpBall.Left + shpBall.Width
img1_bottom = shpBall.Top + shpBall.Height
img2_top = shpBrick(0).Top
img2_left = shpBrick(0).Left
img2_right = shpBrick(0).Width + shpBrick(0).Left
img2_bottom = shpBrick(0).Top + shpBrick(0).Height
If shpBrick(0).Visible = True And ((img1_top = img2_bottom And img1_left > img2_left And img1_left < img2_right) Or (img1_bottom = img2_top And img1_left > img2_left And img1_left < img2_right) Or (img1_left = img2_right And img1_top > img2_top And img1_top < img2_bottom) Or (img1_right = img2_left And img1_top > img2_top And img1_top < img2_bottom)) Then
vmom = -vmom
hmom = -hmom
shpBrick(0).Visible = False
End If
img2_top = shpBrick(1).Top
img2_bottom = shpBrick(1).Top + shpBrick(1).Height
If shpBrick(1).Visible = True And (img1_top = img2_bottom) Then
vmom = -vmom
hmom = -hmom
shpBrick(1).Visible = False
End If
If (shpBall.Left + shpBall.Width) > Form1.Width Then
shpBall.Left = Form1.Width - shpBall.Width
hmom = -hmom
ElseIf shpBall.Left < 0 Then
shpBall.Left = 0
hmom = -hmom
ElseIf shpBall.Top < 0 Then
shpBall.Top = 0
vmom = -vmom
ElseIf shpBall.Top > Form1.Height Then
MsgBox "You lost!"
Timer1.Enabled = False
End If
End Sub
Thank you in advance for your help.
Kind Regards,
Gabriel
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>

Thanks,
PsychoCoder