Hello, I Have a Lag Problem With my Code My Snake Game
It Will Move With Timer Tick 100 interval
And Each Timer It Move
It Will Use A Lot Of Code In Procedure It LAGGY
My Touch Code Use This
Function Touched(ByVal obj1 As String, ByVal obj2 As String) As Boolean
If Me.Controls(obj1).Location = Me.Controls(obj2).Location Then
Touched = True
End If
If Me.Controls(obj1).Location.X > Me.Controls(obj2).Location.X - Me.Controls(obj1).Size.Width And Me.Controls(obj1).Location.X < _
Me.Controls(obj2).Location.X + Me.Controls(obj2).Size.Width Then
If Me.Controls(obj1).Location.Y > Me.Controls(obj2).Location.Y - Me.Controls(obj1).Size.Height And Me.Controls(obj1).Location.Y < _
Me.Controls(obj2).Location.Y + Me.Controls(obj2).Size.Height Then
Touched = True
End If
End If
Return Touched
End Function
It NorMally Work But My Code is So long . Cuz My Snake Game Have A Lot Of Thing
Each Move I Use This Code
Function moved()
If Touched("pictureBox1", "stone1") = True Or Touched("pictureBox1", "stone2") = True Or Touched("pictureBox1", "stone3") = True Then
DIE()
End If
If Touched("food", "stone1") = True Or Touched("food", "stone2") = True Or Touched("food", "stone3") = True Then
FoodReLoc()
End If
If Touched("PictureBox1", "Food") = True Then
Eated()
End If
If PillAp = False Then
If Touched("PictureBox1", "Pill") = True Then
Eated_Pill(1)
End If
If Touched("pictureBox1", "Pill2") Then
Eated_Pill(2)
End If
EXPBARRESIZE()
End If
LEVEL_UP()
Length = Collen
Do While Length > 1
Me.Controls("PictureBox" & Length).Location = Me.Controls("PictureBox" & Length - 1).Location
Length -= 1
Loop
Length = Collen
Select Case D
Case 1
PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - 10)
Case 2
PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 10)
Case 3
PictureBox1.Location = New Point(PictureBox1.Location.X - 10, PictureBox1.Location.Y)
Case 4
PictureBox1.Location = New Point(PictureBox1.Location.X + 10, PictureBox1.Location.Y)
End Select
If PictureBox1.Location.X >= Area.Location.X + Area.Size.Width Then
PictureBox1.Location = New Point(Area.Location.X, PictureBox1.Location.Y)
ElseIf PictureBox1.Location.X < Area.Location.X Then
PictureBox1.Location = New Point(Area.Location.X + Area.Size.Width - PictureBox1.Width, PictureBox1.Location.Y)
End If
If PictureBox1.Location.Y >= Area.Location.Y + Area.Size.Height Then
PictureBox1.Location = New Point(PictureBox1.Location.X, Area.Location.Y)
ElseIf PictureBox1.Location.Y < Area.Location.Y Then
PictureBox1.Location = New Point(PictureBox1.Location.X, Area.Location.Y + Area.Size.Height - PictureBox1.Height)
End If
Do While Length > 1
If PictureBox1.Location = Me.Controls("PictureBox" & Length).Location Then
DIE()
Return 0
Exit Function
End If
Length -= 1
Loop
Length = Collen
Return 0
End Function
It Have A Lot Of Thing In My Game SKill Pill Stone and Mapsize
Each Time It detect Touch Of Every Thing Pill Stone And Get Go Throught Map Will go to other size
Thanks For Help And Advice Me ...