Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
DIV 1.14 KB | None | 0 0
  1.     FUNCTION findpath:Vector2d(xPos:INT, yPos:INT, targetX:INT, targetY:INT, w:World)
  2.         LOCAL beginX:INT = (xPos+Block.SIZE/2)/Block.SIZE
  3.         LOCAL beginY:INT = (yPos+Block.SIZE/2)/Block.SIZE
  4.         LOCAL finishX:INT = (targetX+Block.SIZE/2)/Block.SIZE
  5.         LOCAL finishY:INT = (targetY+Block.SIZE/2)/Block.SIZE
  6.         LOCAL possibleX:INT[8]
  7.         LOCAL possibleY:INT[8]
  8.         LOCAL moveX:INT
  9.         LOCAL moveY:INT
  10.         LOCAL simpledistance:INT
  11.         LOCAL counter:INT = 0
  12.         FOR LOCAL yi:INT = -1 TO 1
  13.             FOR LOCAL xi:INT = -1 TO 1
  14.                 IF NOT (xi = 0 AND yi = 0)
  15.                     IF NOT w.ar[beginX+xi,beginY+yi].isWall
  16.                         possibleX[counter] = beginX+xi
  17.                         possibleY[counter] = beginY+yi
  18.                         counter:+1
  19.                     EndIf
  20.                 EndIf
  21.             Next
  22.         Next
  23.         moveX = beginX
  24.         moveY = beginY
  25.         simpledistance = Abs(moveX - finishX) + Abs (moveY - finishY)
  26.         FOR LOCAL i:INT = 0 TO counter
  27.             LOCAL testdistance:INT = Abs(possibleX[i] - finishX) + Abs (possibleY[i] - finishY)
  28.             IF testdistance < simpledistance
  29.                 moveX = possibleX[i]
  30.                 moveY = possibleY[i]
  31.                 simpledistance = testdistance
  32.             EndIf
  33.         Next
  34.         RETURN Vector2d.spawn(moveX - beginX, moveY - beginY).normalize()
  35.        
  36.     END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement