我想了一下,决定吧我现在程序的源代码发上来(以前没接触过多线程,看网上资料一脸懵逼,决定从代码本身出发,以降低资源消耗量的方式来达成目标)
我这个程序是一个小游戏,屏幕上出现300-1000的点(视难度而定),这些点会朝你所控制的大点袭来,你要躲避他们
这一段是每个点的移动算法,请各位大大帮忙改善一下,谢谢!
代码处于计时器当中,计时器的Inyerval值为50
程序代码:
Private Sub Timer1_Timer()
For i = 0 To JValue 'JValue为当前点的数量,所有点都是一个控件数组里的
If Abs(Shape1.Top - Shape(i).Top) < 100 And Abs(Shape1.Left - Shape(i).Left) < 100 Then
Open App.Path & "\高分榜\" & Replace(Replace(Replace(Replace(Speed, "1000", "VeryDifficult.sav"), "300", "Middle.sav"), "600", "Difficult.sav"), "100", "Easy.sav") For Input As #1
Input #1, a
Close #1
If a > Time Then
MsgBox "你死了!游戏结束!未破纪录。分数:" & CStr(Time): Debug.Print i: Timer1.Enabled = False: Unload Form2: Form1.Show: Exit Sub
Else
Open App.Path & "\高分榜\" & Replace(Replace(Replace(Replace(Speed, "1000", "VeryDifficult.sav"), "300", "Middle.sav"), "600", "Difficult.sav"), "100", "Easy.sav") For Output As #1 '输出分数,REPLACE函数负责模式检测
Print #1, Time
Close #1
MsgBox "你死了!游戏结束!你的分数是最高纪录!分数:" & CStr(Time): Debug.Print i: Timer1.Enabled = False: Unload Form2: Form1.Show: Exit Sub
End If
End If
Movement = Abs(Shape1.Left - Shape(i).Left) / Abs(Shape1.Top - Shape(i).Top) '计算移动比例
Debug.Print Movement
If Shape1.Left > Shape(i).Left Then
Shape(i).Left = Shape(i).Left + 20
ElseIf Shape1.Left < Shape(i).Left Then
Shape(i).Left = Shape(i).Left - 20
End If
On Error Resume Next
If Movement = 0 Then Movement = 1
If Shape1.Top > Shape(i).Top Then
Shape(i).Top = Shape(i).Top + 20 / Movement
ElseIf Shape1.Top < Shape(i).Top Then
Shape(i).Top = Shape(i).Top - 20 / Movement
End If
Next i
End Sub
在100到150点的时候并不卡顿,但是到200点以上明显卡顿,当1000点的时候已经慢到极致了。
各位能帮我改善一下么,谢谢啦
[此贴子已经被作者于2016-5-25 21:17编辑过]