Code: Select all
Function obj_go_path(o As Integer) As Integer
If AStarObj <> o Then AStar__Setup(o)
With obj(o)
Dim As Integer csx = (CELL_W\2-1)
Dim As Integer csy = (CELL_H\2-1)
Dim As Single acx = ((.pa.x-(.x+.b.x)) / .pa.sw)
Dim As Single acy = ((.pa.y-(.y+.b.y)) / .pa.sh)
Dim As Integer cex = csx + acx
Dim As Integer cey = csy + acy
if cex < 0 then cex = 0
if cey < 0 then cey = 0
If cex > CELL_W-1 Then cex = CELL_W-1
If cey > CELL_H-1 Then cey = CELL_H-1
ASTAR_CellClearAll()
ASTAR_CellSetStart(csx,csy)
ASTAR_CellSetEnd(cex,cey)
For x as integer = 0 to CELL_W -1
For y as integer = 0 to CELL_H -1
Dim As Integer x1a,y1a,x2a,y2a,x1b,y1b,x2b,y2b
x1a = (-320+.x+.b.x+.pa.sw\2)+x*.pa.sw
y1a = (-240+.y+.b.y+.pa.sh\2)+y*.pa.sh
x2a = (-320+.x+.b.x+.pa.sw\2)+x*.pa.sw+.pa.sw-1
y2a = (-240+.y+.b.y+.pa.sh\2)+y*.pa.sh+.pa.sh-1
For n As Integer = 1 To n_o
If obj(n).ng.en Then
x1b = obj(n).x+obj(n).ng.x1
y1b = obj(n).y+obj(n).ng.y1
x2b = obj(n).x+obj(n).ng.x2
y2b = obj(n).y+obj(n).ng.y2
If inRange2(x1a,y1a,x2a,y2a,x1b,y1b,x2b,y2b) Then
ASTAR_CellSetSolid(x,y,TRUE)
EndIf
EndIf
Next
Next
Next
ASTAR_Compute()
AStar__GivePathTo(o)
Here's what I'm doing for the pathfinder.
.pa.sw and .pa.sh stand for path stepwidth and path stepheight, in other words grid cell dimensions.
.x+.b.x and .y+.b.y is just finding the base point of the object (its feet.)
.ng = nogo or bounding box.
inRange2 checks that no point of either box is within the four points of the other box. So each cell cannot have a point within a bounding box, and no bounding box point can be within a cell. Not sure how this will run with a couple dozen pathfinders... but I don't know of any more efficient way.