Hi,
I'm working in a simple physics simulation game, but my only problem is when i try to calculate the collision of each object in the arraylist.
In other sites, i found few other solutions like this:
but when i try to put this on my code, i get a OutOfRange exception...
I tried to make the program obtain an item behind the current, so I tried to do the collision check from the two objects. the current and the previous to the current one.
But doesn't worked so good, the objects only collided with the floor.
Here is the code responsible for updating objects (in my case, particles):
what I want is that the objects collide with each other, only the type of Powder and Solid
I had already achieved a similar type of collision, but it was not used an array.
Thanks for help.
/>
I'm working in a simple physics simulation game, but my only problem is when i try to calculate the collision of each object in the arraylist.
In other sites, i found few other solutions like this:
For ItemA = 0 to 59
For ItemB = ItemA to 60
'Checkcollision here!
Next
Next
but when i try to put this on my code, i get a OutOfRange exception...
I tried to make the program obtain an item behind the current, so I tried to do the collision check from the two objects. the current and the previous to the current one.
But doesn't worked so good, the objects only collided with the floor.
Here is the code responsible for updating objects (in my case, particles):
'This code is part of the xWorld class.
Public Sub UpdateWorld(ByVal g As Graphics)
For i As Integer = 0 To particles.Count - 1
Dim p As Particle = particles(i)
If p.particle_type = PType.Powder Then
g.FillRectangle(Brushes.Red, p.particle_X, p.particle_Y, gridsize, gridsize)
'Here is the code responsible for updating the objects
p.particle_yVel += gravity
p.particle_yVel *= friction
p.particle_Y += p.particle_yVel
'snap to grid
Dim iy As Integer = CInt(p.particle_Y / gridsize)
p.particle_Y = iy * gridsize
ElseIf p.particle_type = PType.Solid Then
g.FillRectangle(Brushes.Gray, p.particle_X, p.particle_Y, gridsize, gridsize)
End If
Next
End Sub
what I want is that the objects collide with each other, only the type of Powder and Solid
I had already achieved a similar type of collision, but it was not used an array.
Thanks for help.