Renamed Tile to TileType.
This commit is contained in:
parent
cb81ced655
commit
1e9d3e9089
@ -125,7 +125,7 @@ func (l *playLevel) Layout(ctx *alui.Context, bounds geom.RectangleF32) {
|
||||
var contentCenter = l.posToScreenF32(geom.PtF32(.5*float32(level.Width), .5*float32(level.Height)), 0)
|
||||
var content = geom.RectF32(contentCenter.X, contentCenter.Y, contentCenter.X, contentCenter.Y)
|
||||
for idx, tile := range l.state.Level().Tiles {
|
||||
if tile == soko.TileNothing || tile == soko.TileInvalid {
|
||||
if tile == soko.TileTypeNothing || tile == soko.TileTypeInvalid {
|
||||
continue
|
||||
}
|
||||
pos := level.IdxToPos(idx).ToF32()
|
||||
@ -196,13 +196,13 @@ func (l *playLevel) Render(ctx *alui.Context, bounds geom.RectangleF32) {
|
||||
pos := geom.Pt(i%level.Width, i/level.Width)
|
||||
scr := entityLoc{pos.ToF32(), 0}
|
||||
switch t {
|
||||
case soko.TileBasic:
|
||||
case soko.TileTypeBasic:
|
||||
if l.state.IsNextToMagma(pos) {
|
||||
l.drawSprite("lava_brick", "magma", scr)
|
||||
} else {
|
||||
l.drawSprite("lava_brick", "lava_brick", scr)
|
||||
}
|
||||
case soko.TileMagma:
|
||||
case soko.TileTypeMagma:
|
||||
l.drawSprite("magma", "magma", scr)
|
||||
brick := l.state.FindSunkenBrick(pos)
|
||||
if brick != nil {
|
||||
|
@ -177,11 +177,11 @@ func (s *playLevelState) canMove(from, dir geom.Point) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *playLevelState) checkTile(pos geom.Point, check func(pos geom.Point, idx int, t soko.Tile) bool) bool {
|
||||
func (s *playLevelState) checkTile(pos geom.Point, check func(pos geom.Point, idx int, t soko.TileType) bool) bool {
|
||||
return s.checkTileNotFound(pos, check, false)
|
||||
}
|
||||
|
||||
func (s *playLevelState) checkTileNotFound(pos geom.Point, check func(pos geom.Point, idx int, t soko.Tile) bool, notFound bool) bool {
|
||||
func (s *playLevelState) checkTileNotFound(pos geom.Point, check func(pos geom.Point, idx int, t soko.TileType) bool, notFound bool) bool {
|
||||
idx := s.level.PosToIdx(pos)
|
||||
if idx == -1 {
|
||||
return notFound
|
||||
@ -200,33 +200,33 @@ func (s *playLevelState) findEntityAt(pos geom.Point) *entity {
|
||||
return s.sunken.FindEntity(pos)
|
||||
}
|
||||
|
||||
func (s *playLevelState) isObstructed(pos geom.Point, idx int, t soko.Tile) bool {
|
||||
func (s *playLevelState) isObstructed(pos geom.Point, idx int, t soko.TileType) bool {
|
||||
if s.bricks.FindEntity(pos) != nil {
|
||||
return true // brick
|
||||
}
|
||||
switch s.level.Tiles[idx] {
|
||||
case soko.TileMagma:
|
||||
case soko.TileTypeMagma:
|
||||
return false
|
||||
case soko.TileBasic:
|
||||
case soko.TileTypeBasic:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *playLevelState) isMagma(pos geom.Point, idx int, t soko.Tile) bool {
|
||||
return t == soko.TileMagma
|
||||
func (s *playLevelState) isMagma(pos geom.Point, idx int, t soko.TileType) bool {
|
||||
return t == soko.TileTypeMagma
|
||||
}
|
||||
|
||||
func (s *playLevelState) isSolidTile(pos geom.Point, idx int, t soko.Tile) bool {
|
||||
func (s *playLevelState) isSolidTile(pos geom.Point, idx int, t soko.TileType) bool {
|
||||
switch t {
|
||||
case soko.TileBasic:
|
||||
case soko.TileTypeBasic:
|
||||
return true
|
||||
case soko.TileMagma:
|
||||
case soko.TileTypeMagma:
|
||||
return s.sunken.FindEntity(pos) != nil
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *playLevelState) wouldBrickSink(pos geom.Point, idx int, t soko.Tile) bool {
|
||||
return t == soko.TileMagma && s.sunken.FindEntity(pos) == nil
|
||||
func (s *playLevelState) wouldBrickSink(pos geom.Point, idx int, t soko.TileType) bool {
|
||||
return t == soko.TileTypeMagma && s.sunken.FindEntity(pos) == nil
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
type Level struct {
|
||||
Width int
|
||||
Height int
|
||||
Tiles []Tile
|
||||
Tiles []TileType
|
||||
Entities []EntityType
|
||||
}
|
||||
|
||||
|
@ -59,16 +59,16 @@ func (c *levelContext) parseRow(p *gut.LineParser) gut.ParseLineFn {
|
||||
}
|
||||
|
||||
func (c *levelContext) addRow(p *gut.LineParser, line string) gut.ParseLineFn {
|
||||
var tiles []Tile
|
||||
var tiles []TileType
|
||||
var entities []EntityType
|
||||
for i := 0; i < len(line); i += 2 {
|
||||
tiles = append(tiles, Tile(line[i]))
|
||||
tiles = append(tiles, TileType(line[i]))
|
||||
entities = append(entities, EntityType(line[i+1]))
|
||||
}
|
||||
|
||||
for i, t := range tiles {
|
||||
if !t.IsValid() {
|
||||
return p.EmitErr(fmt.Errorf("level contains invalid Tile at (%d, %d)", i, c.level.Height))
|
||||
return p.EmitErr(fmt.Errorf("level contains invalid TileType at (%d, %d)", i, c.level.Height))
|
||||
}
|
||||
}
|
||||
for i, e := range entities {
|
||||
|
21
soko/tile.go
21
soko/tile.go
@ -1,21 +0,0 @@
|
||||
package soko
|
||||
|
||||
type Tile byte
|
||||
|
||||
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
|
||||
}
|
21
soko/tiletype.go
Normal file
21
soko/tiletype.go
Normal file
@ -0,0 +1,21 @@
|
||||
package soko
|
||||
|
||||
type TileType byte
|
||||
|
||||
const (
|
||||
TileTypeInvalid TileType = TileType(0)
|
||||
TileTypeNothing = '.'
|
||||
TileTypeBasic = '#'
|
||||
TileTypeMagma = '~'
|
||||
)
|
||||
|
||||
func (t TileType) IsValid() bool {
|
||||
switch t {
|
||||
case TileTypeNothing:
|
||||
case TileTypeBasic:
|
||||
case TileTypeMagma:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue
Block a user