I am creating a 'frogger' like game. Essentially there are ten lanes each with an image array associated with it. The arrays are named from imglane0() to imglane9(). I was creating a piece of code that moved the img boxes in the array by random amounts whilst checking for collisions etc. and it worked, for one lane. I designed a module that would theoretically allow the movement of every lane without having to constantly repeat lines of code. The form passes on the lane number, the width of the images associated with that array and the number of controls within the array into a public sub within the module. the module uses these variables to do the above mentioned moving etc. in the specified lane. The problem is this, i am able to use a variable in place of an index in a control array name however i do not know how to use variables in a similar way to dynamically specify a control name without using needless amounts of select case statements.
That which is in bold causes me trouble, expects then or goto. essentially i need the syntax so that if ilane = 1 then the left property of control imglane1([i1]) would be used. using the variables to specify the index in these cases works fine.
Code:
Public Sub movement(ilane as integer, icount as integer, iwidth as integer)
'ilane = lane number, icount = number of controls in array, iwidth = width of control
For i = 1 To icount
'i 1 is effectively just the index number of the img box that is behind img box i
i1 = i
If i1 < 0 Then
i1 = icount
End If
'check for a collision between the images, what it does is irrelevant, only the syntax is troublesome
If imglane[B][ilane][/B]([i1]).Left >= imglane[ilane]([i]).Left + iwidth Then
imglane[ilane]([i]).Left = imglane[ilane]([i]).Left - 30
End If
imglane[ilane]([i]).Left = imglane[ilane]([i]).Left - Rnd * 10 + 1
Next i
For i = 0 To icount
If imglane0([i]).Left <= 720 Then
imglane0([i]).Left = 8280
End If
Next i
End Sub
Comment