krampus19/soko/level.go
2019-01-15 19:03:52 +01:00

63 lines
1.0 KiB
Go

package soko
import (
"opslag.de/schobers/geom"
)
type EntityType byte
type Tile byte
const (
EntityTypeInvalid EntityType = EntityType(0)
EntityTypeNone = '_'
EntityTypeCharacter = '@'
EntityTypeEgg = 'X'
EntityTypeBrick = 'B'
)
func (e EntityType) IsValid() bool {
switch e {
case EntityTypeNone:
case EntityTypeCharacter:
case EntityTypeEgg:
case EntityTypeBrick:
default:
return false
}
return true
}
const (
TileInvalid Tile = Tile(0)
TileNothing = '.'
TileBasic = '#'
TileMagma = '~'
)
func (t Tile) IsValid() bool {
switch t {
case TileNothing:
case TileBasic:
case TileMagma:
default:
return false
}
return true
}
type Level struct {
Width int
Height int
Tiles []Tile
Entities []EntityType
}
func (l Level) IdxToPos(i int) geom.Point { return geom.Pt(i%l.Width, i/l.Width) }
func (l Level) PosToIdx(p geom.Point) int {
if p.X < 0 || p.Y < 0 || p.X >= l.Width || p.Y >= l.Height {
return -1
}
return p.Y*l.Width + p.X
}