Ok... I am making a frogger game and I have 3 Timers... 2 of them have 1 cars and 1 timer with 2 cars. Each time the timer goes through its cycle it declares the position of the car. Then Calls a function. The timer with the two cars Calls it twice, once for each car.
The problem I am having is that the timer with the 2 cars is not detecting a crash.
Here is how the Sub is declared:

``````Sub Collision(ByVal Top As String, ByVal Left As String, ByVal Bottom As String, ByVal Right As String)
Dim FrogRight As Integer
Dim FrogBottom As Integer
Dim FrogTop As Integer
Dim FrogLeft As Integer
FrogTop = imgfrogU.Top
FrogLeft = imgfrogU.Left
FrogRight = imgfrogU.Left + imgfrogU.Width
FrogBottom = imgfrogU.Top + imgfrogU.Height
If FrogTop > Top And FrogLeft > Left And FrogBottom < Bottom And FrogRight < Right Then
imgfrogU.Top = 6120
imgfrogD.Top = 6120
imgfrogR.Top = 6120
imgfrogL.Top = 6120
imgfrogU.Left = 4440
imgfrogD.Left = 4440
imgfrogR.Left = 4440
imgfrogL.Left = 4440
End If
End Sub``````

Also here are the codes for the 3 timers:

``````Private Sub tmrCar1_Timer()
Dim Car1Top As String
Dim Car1Left As String
Dim Car1Height As String
Dim Car1Width As String
imgcar1.Left = imgcar1.Left + 50
If imgcar1.Left > 9500 Then
imgcar1.Left = -100
End If
Car1Top = imgcar1.Top
Car1Left = imgcar1.Left
Car1Height = imgcar1.Height + imgcar1.Top
Car1Width = imgcar1.Width + imgcar1.Left
Call Collision(Car1Top, Car1Left, Car1Height, Car1Width)
End Sub
Private Sub tmrCar2_Timer()
Dim Car2Top As String
Dim Car2Left As String
Dim Car2Height As String
Dim Car2Width As String
imgcar2.Left = imgcar2.Left + 100
If imgcar2.Left > 9500 Then
imgcar2.Left = -100
End If
Car2Top = imgcar2.Top
Car2Left = imgcar2.Left
Car2Height = imgcar2.Height + imgcar2.Top
Car2Width = imgcar2.Width + imgcar2.Left
Call Collision(Car2Top, Car2Left, Car2Height, Car2Width)
End Sub
Private Sub tmrCar3_Timer()
Dim Car3Top As String
Dim Car3Left As String
Dim Car3Height As String
Dim Car3Width As String
Dim Car4Top As String
Dim Car4Left As String
Dim Car4Height As String
Dim Car4Width As String
imgcar3.Left = imgcar3.Left - 75
imgcar4.Left = imgcar4.Left - 75
If imgcar3.Left < -15000 Then
imgcar3.Left = 9500
ElseIf imgcar4.Left < -2000 Then
imgcar4.Left = 10000
End If
Car3Top = imgcar3.Top
Car3Left = imgcar3.Left
Car3Height = imgcar3.Height + imgcar3.Top
Car3Width = imgcar3.Width + imgcar3.Left
Call Collision(Car3Top, Car3Left, Car3Height, Car3Width)
Car4Top = imgcar4.Top
Car4Left = imgcar4.Left
Car4Height = imgcar4.Height + imgcar4.Top
Car4Width = imgcar4.Width + imgcar4.Left
Call Collision(Car4Top, Car4Left, Car4Height, Car4Width)
End Sub``````

honestly i dont have time to think more abt ur problem coz im busy right now.. but seeing this condition , i think this wont work... try to look for a collition detection code in vbcode.com theres a lot there..

ill post the right code when i got mine.. hope it helps

go with your code ithink you can do it..

``If FrogTop > Top And FrogLeft > Left And FrogBottom < Bottom And FrogRight < Right``

honestly i dont have time to think more abt ur problem coz im busy right now.. but seeing this condition , i think this wont work... try to look for a collition detection code in vbcode.com theres a lot there..

ill post the right code when i got mine.. hope it helps

go with your code ithink you can do it..

``If FrogTop > Top And FrogLeft > Left And FrogBottom < Bottom And FrogRight < Right``

See I tried that before hand... and the whole frog would have to be under the car... which can pose as a problem when only half of it is...

See I tried that before hand... and the whole frog would have to be under the car... which can pose as a problem when only half of it is...

Are you saying that the frog must be under the car for a collision to occur only for the timer with two cars, or for all cars?

all of the cars

I see. Please take this into consideration. Let's say a frog is in front of a car going left. The moment the frog's right touches the car's left, then a collision should already occur. So the code should say that `frogright > left` , right? Theoretically, the same goes for top, bottom and right of the frog and the car.

Ahhhh Thank you... a simple mistake can cause havok... one character wrong can crash a system

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.