Initial commit
This commit is contained in:
commit
f26c478727
18 changed files with 621 additions and 0 deletions
42
world/level.go
Normal file
42
world/level.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue