steel-lord/mapping/gamemap.go
2019-07-02 23:55:29 -07:00

39 lines
877 B
Go

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)
}
g.Tiles[30][22] = Tile {
BlockMovement: true,
BlockSight: true,
}
g.Tiles[31][22] = Tile{
BlockMovement: true,
BlockSight: true,
}
g.Tiles[32][22] = Tile{
BlockMovement: true,
BlockSight: true,
}
}
// 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
}