I have been banging my head on a wall for two days now. All I have is a
picbox bouncing around the form, and I want it to react when it hits
the block (another picbox). Everything works correctly except when the
"ball" hits the "block" right in the ball's center, it reacts
incorrectly. I know this should not be this hard. Can anyone clear this
up any??? Thanks. BTW I'm working on a Breakout-type game. Here's my
code: (*P.S. Nevermind the overkill properties*)
Dim intMoveX As Integer = 2
Dim intMoveY As Integer = 2
Dim blnZero As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
DetectWalls()
DetectTopBottomObject()
End Sub
Public Sub DetectWalls()
picBall.Top += intMoveY
picBall.Left += intMoveX
If picBall.Left + picBall.Width > Me.Width - 5 Then
intMoveX = -intMoveX
End If
If picBall.Left = 0 Then
intMoveX = 2
End If
If picBall.Top = 1 Then
intMoveY = -intMoveY
End If
If picBall.Top + picBall.Height + 30 > Me.Height Then
intMoveY = -2
End If
End Sub
Public Sub DetectTopBottomObject()
'Top and Bottom
If BallLeft > picBlock1.Left And _
BallRight < picBlock1.Left + picBlock1.Width And _
BallTop < picBlock1.Top + picBlock1.Height And _
BallBottom > picBlock1.Top Then
intMoveY = -intMoveY
End If
'Sides
If BallTop > picBlock1.Top And _
BallBottom < picBlock1.Top + picBlock1.Height And _
BallRight > picBlock1.Left And _
BallLeft < picBlock1.Left + picBlock1.Width Then
intMoveX = -intMoveX
End If
End Sub
Public Property BallLeft()
Get
Return picBall.Left()
End Get
Set(ByVal Value)
picBall.Left = Value
End Set
End Property
Public Property BallRight()
Get
Return picBall.Left + picBall.Width
End Get
Set(ByVal Value)
End Set
End Property
Public Property BallTop()
Get
Return picBall.Top
End Get
Set(ByVal Value)
picBall.Top = Value
End Set
End Property
Public Property BallBottom()
Get
Return picBall.Top + picBall.Height
End Get
Set(ByVal Value)
End Set
End Property