Add non-diagonal movement

This commit is contained in:
Ketchetwahmeegwun T. Southall 2024-02-03 02:00:04 -08:00
parent 182214c6d0
commit 547f9ab382

View File

@ -49,7 +49,8 @@ func FindPath(w *World, fromX, fromY int, toX, toY int) ([]Node, bool) {
// Get neighbors.
var neighbors []*Node
for x := -1; x <= 1; x++ {
// diagonal
/*for x := -1; x <= 1; x++ {
for y := -1; y <= 1; y++ {
if x == 0 && y == 0 {
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})
}
}*/
// 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.