Pathing is working now to make enemies use it.

master
Zed A. Shaw 5 days ago
parent c22bef62c9
commit 6a6c3b9013
  1. 13
      main.go

@ -339,21 +339,23 @@ func (game *Game) CloneMap() Map {
return new_map
}
func (game *Game) PathAddNeighbors(neighbors []Position, closed Map, near Position) {
func (game *Game) PathAddNeighbors(neighbors []Position, closed Map, near Position) []Position {
points := compass(near.x, near.y, 1)
for _, pos := range points {
if !game.Occupied(pos.x, pos.y) {
if !game.Occupied(pos.x, pos.y) && closed[pos.y][pos.x] == SPACE {
closed[pos.y][pos.x] = WALL
neighbors = append(neighbors, pos)
}
}
return neighbors
}
func (game *Game) PathEnemies() {
in_grid := make([][]int, game.height, game.height)
game.FillPaths(in_grid, 1)
in_grid[game.player.y][game.player.x] = 1
in_grid[game.player.y][game.player.x] = 0
game.FillPaths(game.paths, PATH_LIMIT)
closed := game.CloneMap()
@ -376,14 +378,15 @@ func (game *Game) PathEnemies() {
}
for _, pos := range starting_pixels {
game.PathAddNeighbors(open_pixels, closed, pos)
open_pixels = game.PathAddNeighbors(open_pixels, closed, pos)
}
counter = 1
for counter < PATH_LIMIT && len(open_pixels) > 0 {
next_open := make([]Position, 0, 10)
for _, pos := range open_pixels {
game.paths[pos.y][pos.x] = counter
game.PathAddNeighbors(next_open, closed, pos)
next_open = game.PathAddNeighbors(next_open, closed, pos)
}
open_pixels = next_open
counter += 1

Loading…
Cancel
Save