How can I random my pipes like in flappy bird? These code I've used, but my problem is, the pipes are not random. Where P1 - Picturebox2 are pictureboxes for pipes. Pipe1 to Pipe5 are boolean these will check the pipes if it's inside the screen.
Private Sub ObsM_Tick(sender As Object, e As EventArgs) Handles ObsM.Tick
Dim rndom As Integer
Randomize()
rndom = CInt(5 * Rnd()) + 1
P1.Left = P1.Left - pspeed
P2.Left = P2.Left - pspeed
S1.Left = S1.Left - pspeed
If rndom = 1 Then
If P1.Left < 0 And P2.Left < 0 Then
If pipe1 = True Then
P1.Left = P1.Left + lpipes
P2.Left = P2.Left + lpipes
S1.Left = S1.Left + lpipes
b1 = True
pipe1 = False
End If
End If
End If
P3.Left = P3.Left - pspeed
P4.Left = P4.Left - pspeed
S2.Left = S2.Left - pspeed
If rndom = 2 Then
If P3.Left < 0 And P4.Left < 0 Then
If pipe2 = True Then
P3.Left = P3.Left + lpipes
P4.Left = P4.Left + lpipes
S2.Left = S2.Left + lpipes
b2 = True
pipe2 = False
End If
End If
End If
P5.Left = P5.Left - pspeed
P6.Left = P6.Left - pspeed
S3.Left = S3.Left - pspeed
If rndom = 3 Then
If P5.Left < 0 And P6.Left < 0 Then
If pipe3 = True Then
P5.Left = P5.Left + lpipes
P6.Left = P6.Left + lpipes
S3.Left = S3.Left + lpipes
b3 = True
pipe3 = False
End If
End If
End If
P7.Left = P7.Left - pspeed
P8.Left = P8.Left - pspeed
S4.Left = S4.Left - pspeed
If rndom = 4 Then
If P7.Left < 0 And P8.Left < 0 Then
If pipe4 = True Then
P7.Left = P7.Left + lpipes
P8.Left = P8.Left + lpipes
S4.Left = S4.Left + lpipes
b4 = True
pipe4 = False
End If
End If
End If
P9.Left = P9.Left - pspeed
PictureBox2.Left = PictureBox2.Left - pspeed
If rndom = 5 Then
If P9.Left < 0 And PictureBox2.Left < 0 Then
If pipe5 = True Then
P9.Left = P9.Left + lpipes
PictureBox2.Left = PictureBox2.Left + lpipes
pipe5 = False
End If
End If
End If
If Scorep.Text > 9 Then
pspeed += 0.5
ElseIf Scorep.Text > 29 Then
pspeed += 0.6
ElseIf Scorep.Text > 49 Then
pspeed += 0.7
End If
'P9.Left = P9.Left - pspeed
'PictureBox2.Left = PictureBox2.Left - pspeed
'If P9.Left < 0 And P10.Left < 0 Then
'P9.Left = P9.Left + 920
'P10.Left = P10.Left + 920
'End If
End Sub
Aucun commentaire:
Enregistrer un commentaire