steel-lord/mapping/gamemap.go

34 lines
780 B
Go
Raw Normal View History

2019-07-02 23:55:29 -07:00
package mapping
// GameMap is our map data type.
type GameMap struct {
Width, Height int
Tiles [][]Tile
}
// Initialize initializes a GameMap's Tiles to match its Width and Height. It also sets up some coordinates to block movement and sight.
func (g *GameMap) Initialize() {
g.Tiles = make([][]Tile, g.Width)
for x := range g.Tiles {
g.Tiles[x] = make([]Tile, g. Height)
2019-07-10 19:44:16 -07:00
for y := range g.Tiles[x] {
g.Tiles[x][y] = Tile{
BlockSight: true,
BlockMovement: true,
}
}
2019-07-02 23:55:29 -07:00
}
2019-07-10 19:44:16 -07:00
2019-07-02 23:55:29 -07:00
}
// IsBlocked returns if the given coordinates are blocking movement.
func (g *GameMap) IsBlocked(x, y int) bool {
// Always block if ourside our GameMap's bounds.
if x < 0 || x >= g.Width || y < 0 || y >= g.Height {
return true
}
return g.Tiles[x][y].BlockMovement
}