Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FUNCTION findpath:Vector2d(xPos:INT, yPos:INT, targetX:INT, targetY:INT, w:World)
- LOCAL beginX:INT = (xPos+Block.SIZE/2)/Block.SIZE
- LOCAL beginY:INT = (yPos+Block.SIZE/2)/Block.SIZE
- LOCAL finishX:INT = (targetX+Block.SIZE/2)/Block.SIZE
- LOCAL finishY:INT = (targetY+Block.SIZE/2)/Block.SIZE
- LOCAL possibleX:INT[8]
- LOCAL possibleY:INT[8]
- LOCAL moveX:INT
- LOCAL moveY:INT
- LOCAL simpledistance:INT
- LOCAL counter:INT = 0
- FOR LOCAL yi:INT = -1 TO 1
- FOR LOCAL xi:INT = -1 TO 1
- IF NOT (xi = 0 AND yi = 0)
- IF NOT w.ar[beginX+xi,beginY+yi].isWall
- possibleX[counter] = beginX+xi
- possibleY[counter] = beginY+yi
- counter:+1
- EndIf
- EndIf
- Next
- Next
- moveX = beginX
- moveY = beginY
- simpledistance = Abs(moveX - finishX) + Abs (moveY - finishY)
- FOR LOCAL i:INT = 0 TO counter
- LOCAL testdistance:INT = Abs(possibleX[i] - finishX) + Abs (possibleY[i] - finishY)
- IF testdistance < simpledistance
- moveX = possibleX[i]
- moveY = possibleY[i]
- simpledistance = testdistance
- EndIf
- Next
- RETURN Vector2d.spawn(moveX - beginX, moveY - beginY).normalize()
- END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement