'For all collisions in this example, we'll imagine a CoR of 80%
...
Ball.Mass = 10
Wall.Mass = 99999
Floor.Mass = 99999
Ball.VelocityX = 50
Ball.VelocityY = 20
Wall.VelocityX = 0
Wall.VelocityY = 0
Floor.VelocityX = 0
Floor.VelocityY = 0
...
'Collision detection: the Ball hits the Wall from the left (x-axis).
If (Ball.Left + Ball.Width) > Wall.Left Then
Ball.Left = (Wall.Left - Ball.Width)
Ball.VelocityX = PostCollisionVelocity(Ball.VelocityX, Wall.VelocityX, Ball.Mass, Wall.Mass, 0.8)
End If
'Collision detection: the Ball hits the Wall from the right (x-axis).
If Ball.Left < (Wall.Left + Wall.Width) Then
Ball.Left = (Wall.Left + Wall.Width)
Ball.VelocityX = PostCollisionVelocity(Ball.VelocityX, Wall.VelocityX, Ball.Mass, Wall.Mass, 0.8)
End If
'Collision detection: the Ball hits the top of the Wall (y-axis).
If (Ball.Top + Ball.Height) > Wall.Top Then
Ball.Top = (Wall.Top - Ball.Height)
Ball.VelocityY = PostCollisionVelocity(Ball.VelocityY, Wall.VelocityY, Ball.Mass, Wall.Mass, 0.8)
End If
'Collision detection: the Ball hits the Floor (y-axis).
If (Ball.Top + Ball.Height) > Floor.Top Then
Ball.Top = (Floor.Top - Ball.Height)
Ball.VelocityY = PostCollisionVelocity(Ball.VelocityY, Floor.VelocityY, Ball.Mass, Wall.Mass, 0.8)
End If
'Apply Gravity
Ball.VelocityY = Ball.VelocityY + Gravity
'Update Ball Position
Ball.Left = Ball.Left + Ball.VelocityX
Ball.Top = Ball.Top + Ball.VelocityY
...