a Pathfinder, ClearList() problem
BlitzMax Forums/BlitzMax Programming/a Pathfinder, ClearList() problem
| ||
I've made a pathfinder (A* ?), but i have problem with ClearList(). If i use it then the engine will "flicker", works-doesn't work-works-doesn't work-works-doesn't work (see function FindPath()). If i don't use the ClearList() it finds the path, but not the smartest way :P and with a "little" memory leak. When i put the ClearList() in the beginning of the FindPath()function, et won't do anything at all. The engine has only 4 function so it should be pretty user friendly and it works almost fine, but this little problem :( and i haven't finished the 3rd dimension support. Example: SuperStrict Graphics(800, 600) SeedRnd(MilliSecs()) ' The engine file Include "pathfind.bmx" ' Create level Global map:Int[32, 32] For Local y:Int = 0 To 32 -1 For Local x:Int = 0 To 32 - 1 If Not Rand(0, 5) Then map[x, y] = PATH_ALL Next Next Global pathmap:TPathmap = CreatePathmap:TPathmap(32, 32) Global path:String = "" ' Copy level to pathmap For Local y:Long = 0 To 32 -1 For Local x:Long = 0 To 32 - 1 PathmapSlot(pathmap, map[x, y], x, y) Next Next While Not KeyHit(KEY_ESCAPE) Cls() ' Draw level For Local y:Int = 0 To 32 -1 For Local x:Int = 0 To 32 - 1 If CheckFlag(map[x, y], PATH_ALL) SetColor(255, 0, 0) Else SetColor(255, 255, 255) EndIf DrawRect(x * 10, y * 10, 10, 10) Next Next path = FindPath(pathmap, 0, 0, 0, MouseX() / 10, MouseY() / 10, 0) ' Draw the PATH If Len(path) > 0 SetColor(0, 0, 255) Local x:Long = 0, y:Long = 0 For Local i:Int = 1 To Len(path) DrawOval(x * 10, y * 10, 10, 10) Select Mid(path, i, 1) Case "1" y :- 1 Case "2" y :+ 1 Case "3" x :- 1 Case "4" x :+ 1 End Select Next EndIf Flip() Wend FreePathmap(pathmap) Engine: |