Ball Movements

mitchmaj

Member
Joined
Dec 7, 2011
Messages
9
Programming Experience
1-3
Hey guys,
Right now i'm working on a project trying to design a game in visual basic 2008 where you control a ball with your mouse and must dodge other circular balls that bounce around the screen. However, I am having a small problem with the ball interactions. However, this presents a small problem: when the balls touch for instance, they bounce off in peculiar directions. Does anyone have a solution for this problem?
-Mitch​


 
I'll try to help you, but it is impossible to do so without seeing the code that has the problem. Could you please post the code which handles the interactions between the balls?
 
Sub EnemyMove(ByRef redball As PictureBox, ByVal intMoveX As Integer, ByVal intMoveY As Integer, ByVal intMultiplierX As Integer, ByVal intMultiplierY As Integer)


Dim intCX As Integer = redball.Location.X
Dim intCY As Integer = redball.Location.Y
'If intCX >= 707 Then

intCX += intMoveX * intMultiplierX 'Redball movement X
intCY += intMoveY * intMultiplierY 'Redball movement Y



redball.Location = New Point(intCX, intCY) 'setting new position


If redball.Bounds.IntersectsWith(UserPicBox1.Bounds) Or redball.Bounds.IntersectsWith(UserPicBox2.Bounds) Or redball.Bounds.IntersectsWith(UserPicBox3.Bounds) Then
CompMove.Enabled = False
MessageBox.Show("Hit")
btnReset.Enabled = True
Time.Enabled = False
intTime = 0
intDeaths += 1
Me.lblDeaths.Text = intDeaths
End If








End Sub



All of the multipliers are equal to one to start, but I change them then declare a temporary variable as shown below. However, the balls still cling together often and do not break apart.
If pctCompBall1.Bounds.IntersectsWith(pctCompBall2.Bounds) Then
intTemX = intCX1horizontal
intTemY = intCY1verticle
intCX1horizontal = intCX2horizontal
intCY1verticle = intCY2verticle
intCX2horizontal = intTemX
intCY2verticle = intTemY



screenshot.png
 
Most of your code looks pretty good.
I'd suspect the problem lies with the parameters you're calling the EnemyMove sub with, but I'm not sure what those are.
What is the difference between intMoveX and intMultiplierX? What values do they have? I presume that one of the two is intCX1horizontal (or intCX2horizontal for the other ball), what is the other?

Also, what are UserPicBox1 2 and 3?
 
Back
Top