diff --git a/main.go b/main.go index 772ebf7..523ec49 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ const ( PATH_LIMIT = 1000 RENDER = true SHOW_RENDER = false - SHOW_PATHS = true + SHOW_PATHS = false HEARING_DISTANCE = 6 ) @@ -63,9 +63,15 @@ func (game *Game) DrawEntity(symbol rune, pos Position, color tcell.Color) { } func (game *Game) DrawMap() { + gray := tcell.StyleDefault.Foreground(tcell.ColorGray) + for y, line := range game.level { for x, cell := range line { - game.screen.SetContent(x, y, cell, nil, tcell.StyleDefault) + if cell == SPACE { + game.screen.SetContent(x, y, cell, nil, gray) + } else { + game.screen.SetContent(x, y, cell, nil, tcell.StyleDefault) + } } } } @@ -73,10 +79,16 @@ func (game *Game) DrawMap() { func (game *Game) DrawPaths() { for y, row := range game.paths { for x, path_num := range row { - if path_num <= 16 { - as_str := fmt.Sprintf("%x", path_num) - game.screen.SetContent(x, y, rune(as_str[0]), nil, tcell.StyleDefault) + if path_num == PATH_LIMIT { continue } + + as_str := fmt.Sprintf("%x", path_num % 16) + style := tcell.StyleDefault.Foreground(tcell.ColorGray) + + if path_num >= 0 && path_num <= 16 { + style = style.Reverse(true) } + + game.screen.SetContent(x, y, rune(as_str[0]), nil, style) } } } @@ -344,7 +356,8 @@ func (game *Game) PathAddNeighbors(neighbors []Position, closed Map, near Positi points := compass(near.x, near.y, 1) for _, pos := range points { - if !game.Occupied(pos.x, pos.y) && closed[pos.y][pos.x] == SPACE { + // NOTE: if you also add !game.Occupied(pos.x, pos.y) it ???? + if closed[pos.y][pos.x] == SPACE { closed[pos.y][pos.x] = WALL neighbors = append(neighbors, pos) } @@ -396,26 +409,28 @@ func (game *Game) PathEnemies() { for _, pos := range open_pixels { game.paths[pos.y][pos.x] = counter } - - dbg.Println("pathing is", game.paths) } func (game *Game) EnemyMovement() { + for enemy_at, _ := range game.enemies { + // get the four directions + dirs := compass(enemy_at.x, enemy_at.y, 1) - for pos, _ := range game.enemies { - p_enemy := game.paths[pos.y][pos.x] + // sort by closest path number + slices.SortFunc(dirs, func(a Position, b Position) int { + return game.paths[a.y][a.x] - game.paths[b.y][b.x] + }) - for _, path_at := range compass(pos.x, pos.y, 1) { - p_num := game.paths[path_at.y][path_at.x] + // 0 dir is now the best direction + move_to := dirs[0] - can_hear := p_num < HEARING_DISTANCE - is_open := !game.Occupied(path_at.x, path_at.y) - lower := p_num < p_enemy + // can we hear the player? occupied? + can_hear := game.paths[move_to.y][move_to.x] < HEARING_DISTANCE + occupied := game.Occupied(move_to.x, move_to.y) - if can_hear && is_open && lower { - game.MoveEnemy(pos, path_at) - break - } + if can_hear && !occupied { + // move the enemy in the best direction + game.MoveEnemy(enemy_at, move_to) } } }