Add non-diagonal movement
This commit is contained in:
parent
182214c6d0
commit
547f9ab382
|
@ -49,7 +49,8 @@ func FindPath(w *World, fromX, fromY int, toX, toY int) ([]Node, bool) {
|
||||||
|
|
||||||
// Get neighbors.
|
// Get neighbors.
|
||||||
var neighbors []*Node
|
var neighbors []*Node
|
||||||
for x := -1; x <= 1; x++ {
|
// diagonal
|
||||||
|
/*for x := -1; x <= 1; x++ {
|
||||||
for y := -1; y <= 1; y++ {
|
for y := -1; y <= 1; y++ {
|
||||||
if x == 0 && y == 0 {
|
if x == 0 && y == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -60,6 +61,28 @@ func FindPath(w *World, fromX, fromY int, toX, toY int) ([]Node, bool) {
|
||||||
}
|
}
|
||||||
neighbors = append(neighbors, &Node{Coord: coord, parent: current, g: math.MaxUint16, f: math.MaxUint16})
|
neighbors = append(neighbors, &Node{Coord: coord, parent: current, g: math.MaxUint16, f: math.MaxUint16})
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
// non-diagonal
|
||||||
|
for x := -1; x <= 1; x++ {
|
||||||
|
if x == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
coord := Coord{current.X + int16(x), current.Y}
|
||||||
|
if cell := w.At(int(coord.X), int(coord.Y)); cell == nil || cell.Hueristic == 255 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
neighbors = append(neighbors, &Node{Coord: coord, parent: current, g: math.MaxUint16, f: math.MaxUint16})
|
||||||
|
|
||||||
|
}
|
||||||
|
for y := -1; y <= 1; y++ {
|
||||||
|
if y == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
coord := Coord{current.X, current.Y + int16(y)}
|
||||||
|
if cell := w.At(int(coord.X), int(coord.Y)); cell == nil || cell.Hueristic == 255 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
neighbors = append(neighbors, &Node{Coord: coord, parent: current, g: math.MaxUint16, f: math.MaxUint16})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over neighbors.
|
// Iterate over neighbors.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user