Source File: curse-you-go-rogue/01_the_screen/map.go
package main
import (
"slices"
)
func compass(near Position, offset int) []Position {
return []Position{
Position{near.X, near.Y - offset},
Position{near.X, near.Y + offset},
Position{near.X + offset, near.Y},
Position{near.X - offset, near.Y},
}
}
func (game *Game) Inbounds(pos Position, offset int) bool {
return pos.X >= offset &&
pos.X < game.Width - offset &&
pos.Y >= offset &&
pos.Y < game.Height - offset
}
func (game *Game) Occupied(pos Position) bool {
is_player := pos == game.Player.Pos
// Inbounds comes first to prevent accessing level with bad x,y
return !game.Inbounds(pos, 1) ||
game.Level[pos.Y][pos.X] == WALL ||
is_player
}
func (game *Game) FillMap(target Map, setting rune) {
for y := 0 ; y < game.Height; y++ {
target[y] = slices.Repeat([]rune{setting}, game.Width)
}
}