42 lines
682 B
Go
42 lines
682 B
Go
package world
|
|
|
|
import "github.com/pnx/go-raytracer/math"
|
|
|
|
const TileSize = 64
|
|
|
|
type Special byte
|
|
|
|
const (
|
|
Empty Special = 0
|
|
PlayerStart Special = 'S'
|
|
)
|
|
|
|
type Level struct {
|
|
W, H int
|
|
Grid []byte
|
|
Specials []Special
|
|
}
|
|
|
|
func (m Level) Wall(x, y int) bool {
|
|
return m.Grid[(y*m.W)+x] > 0
|
|
}
|
|
|
|
func (m Level) Cell(x, y int) byte {
|
|
return m.Grid[(y*m.W)+x]
|
|
}
|
|
|
|
func (m Level) PosToCell(x, y float64) (int, int) {
|
|
return int(x) / TileSize, int(y) / TileSize
|
|
}
|
|
|
|
func (m Level) PlayerStart() math.Vec2[int] {
|
|
for k, v := range m.Specials {
|
|
if v == PlayerStart {
|
|
return math.Vec2[int]{
|
|
X: k % m.W,
|
|
Y: k / m.W,
|
|
}
|
|
}
|
|
}
|
|
return math.Vec2[int]{X: -1, Y: -1}
|
|
}
|