|
|
@ -18,7 +18,7 @@ const ( |
|
|
|
SPACE = '.' |
|
|
|
SPACE = '.' |
|
|
|
PATH_LIMIT = 1000 |
|
|
|
PATH_LIMIT = 1000 |
|
|
|
RENDER = true |
|
|
|
RENDER = true |
|
|
|
SHOW_RENDER = true |
|
|
|
SHOW_RENDER = false |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type Position struct { |
|
|
|
type Position struct { |
|
|
@ -91,11 +91,13 @@ func (game *Game) Exit() { |
|
|
|
func (game *Game) Occupied(x int, y int) bool { |
|
|
|
func (game *Game) Occupied(x int, y int) bool { |
|
|
|
pos := Position{x, y} |
|
|
|
pos := Position{x, y} |
|
|
|
_, is_enemy := game.enemies[pos] |
|
|
|
_, is_enemy := game.enemies[pos] |
|
|
|
|
|
|
|
is_player := pos == game.player |
|
|
|
|
|
|
|
|
|
|
|
// Inbounds comes first to prevent accessing level with bad x,y
|
|
|
|
// Inbounds comes first to prevent accessing level with bad x,y
|
|
|
|
return !game.Inbounds(pos, 1) || |
|
|
|
return !game.Inbounds(pos, 1) || |
|
|
|
game.level[y][x] == WALL || |
|
|
|
game.level[y][x] == WALL || |
|
|
|
is_enemy |
|
|
|
is_enemy || |
|
|
|
|
|
|
|
is_player |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (game *Game) MovePlayer(x_delta int, y_delta int) { |
|
|
|
func (game *Game) MovePlayer(x_delta int, y_delta int) { |
|
|
@ -291,6 +293,24 @@ func (game *Game) CarveRoom(pos Position, size int) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (game *Game) MoveEnemy(from Position, to Position) { |
|
|
|
|
|
|
|
enemy, ok := game.enemies[from] |
|
|
|
|
|
|
|
if !ok { log.Fatal("no enemy at", from, "wtf") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete(game.enemies, from) |
|
|
|
|
|
|
|
game.enemies[to] = enemy |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (game *Game) PathEnemies() { |
|
|
|
|
|
|
|
for pos, _ := range game.enemies { |
|
|
|
|
|
|
|
possible := compass(pos.x, pos.y, 1) |
|
|
|
|
|
|
|
move_to := possible[rand.Int() % len(possible)] |
|
|
|
|
|
|
|
if !game.Occupied(move_to.x, move_to.y) { |
|
|
|
|
|
|
|
game.MoveEnemy(pos, move_to) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (game *Game) AddRooms(dead_ends []Position, size int) { |
|
|
|
func (game *Game) AddRooms(dead_ends []Position, size int) { |
|
|
|
rand.Shuffle(len(dead_ends), func(i, j int) { |
|
|
|
rand.Shuffle(len(dead_ends), func(i, j int) { |
|
|
|
dead_ends[i], dead_ends[j] = dead_ends[j], dead_ends[i] |
|
|
|
dead_ends[i], dead_ends[j] = dead_ends[j], dead_ends[i] |
|
|
@ -304,16 +324,16 @@ func (game *Game) AddRooms(dead_ends []Position, size int) { |
|
|
|
|
|
|
|
|
|
|
|
func (game *Game) MakeMap() []Position { |
|
|
|
func (game *Game) MakeMap() []Position { |
|
|
|
game.ClearMap() |
|
|
|
game.ClearMap() |
|
|
|
dead_ends := game.HuntAndKill() |
|
|
|
|
|
|
|
game.Status("FIRST MAZE") |
|
|
|
game.Status("FIRST MAZE") |
|
|
|
|
|
|
|
dead_ends := game.HuntAndKill() |
|
|
|
|
|
|
|
|
|
|
|
game.ClearMap() |
|
|
|
game.ClearMap() |
|
|
|
game.AddRooms(dead_ends, game.height / 8) |
|
|
|
game.AddRooms(dead_ends, game.height / 8) |
|
|
|
game.Status("SECOND MAZE") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
game.Status("SECOND MAZE") |
|
|
|
dead_ends = game.HuntAndKill() |
|
|
|
dead_ends = game.HuntAndKill() |
|
|
|
game.Status("FINISHED") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
game.Status("FINISHED") |
|
|
|
return dead_ends |
|
|
|
return dead_ends |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -336,6 +356,7 @@ func main() { |
|
|
|
game.Render() |
|
|
|
game.Render() |
|
|
|
|
|
|
|
|
|
|
|
for game.HandleEvents() { |
|
|
|
for game.HandleEvents() { |
|
|
|
|
|
|
|
game.PathEnemies() |
|
|
|
game.Render() |
|
|
|
game.Render() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|