Renamed Tile to TileType.

This commit is contained in:
Sander Schobers 2019-01-15 19:51:57 +01:00
parent 0bc84924c3
commit b2342235b3
6 changed files with 40 additions and 40 deletions

View File

@ -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 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) var content = geom.RectF32(contentCenter.X, contentCenter.Y, contentCenter.X, contentCenter.Y)
for idx, tile := range l.state.Level().Tiles { for idx, tile := range l.state.Level().Tiles {
if tile == soko.TileNothing || tile == soko.TileInvalid { if tile == soko.TileTypeNothing || tile == soko.TileTypeInvalid {
continue continue
} }
pos := level.IdxToPos(idx).ToF32() 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) pos := geom.Pt(i%level.Width, i/level.Width)
scr := entityLoc{pos.ToF32(), 0} scr := entityLoc{pos.ToF32(), 0}
switch t { switch t {
case soko.TileBasic: case soko.TileTypeBasic:
if l.state.IsNextToMagma(pos) { if l.state.IsNextToMagma(pos) {
l.drawSprite("lava_brick", "magma", scr) l.drawSprite("lava_brick", "magma", scr)
} else { } else {
l.drawSprite("lava_brick", "lava_brick", scr) l.drawSprite("lava_brick", "lava_brick", scr)
} }
case soko.TileMagma: case soko.TileTypeMagma:
l.drawSprite("magma", "magma", scr) l.drawSprite("magma", "magma", scr)
brick := l.state.FindSunkenBrick(pos) brick := l.state.FindSunkenBrick(pos)
if brick != nil { if brick != nil {

View File

@ -177,11 +177,11 @@ func (s *playLevelState) canMove(from, dir geom.Point) bool {
return true 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) 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) idx := s.level.PosToIdx(pos)
if idx == -1 { if idx == -1 {
return notFound return notFound
@ -200,33 +200,33 @@ func (s *playLevelState) findEntityAt(pos geom.Point) *entity {
return s.sunken.FindEntity(pos) 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 { if s.bricks.FindEntity(pos) != nil {
return true // brick return true // brick
} }
switch s.level.Tiles[idx] { switch s.level.Tiles[idx] {
case soko.TileMagma: case soko.TileTypeMagma:
return false return false
case soko.TileBasic: case soko.TileTypeBasic:
return false return false
} }
return true return true
} }
func (s *playLevelState) isMagma(pos geom.Point, idx int, t soko.Tile) bool { func (s *playLevelState) isMagma(pos geom.Point, idx int, t soko.TileType) bool {
return t == soko.TileMagma 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 { switch t {
case soko.TileBasic: case soko.TileTypeBasic:
return true return true
case soko.TileMagma: case soko.TileTypeMagma:
return s.sunken.FindEntity(pos) != nil return s.sunken.FindEntity(pos) != nil
} }
return false return false
} }
func (s *playLevelState) wouldBrickSink(pos geom.Point, idx int, t soko.Tile) bool { func (s *playLevelState) wouldBrickSink(pos geom.Point, idx int, t soko.TileType) bool {
return t == soko.TileMagma && s.sunken.FindEntity(pos) == nil return t == soko.TileTypeMagma && s.sunken.FindEntity(pos) == nil
} }

View File

@ -7,7 +7,7 @@ import (
type Level struct { type Level struct {
Width int Width int
Height int Height int
Tiles []Tile Tiles []TileType
Entities []EntityType Entities []EntityType
} }

View File

@ -59,16 +59,16 @@ func (c *levelContext) parseRow(p *gut.LineParser) gut.ParseLineFn {
} }
func (c *levelContext) addRow(p *gut.LineParser, line string) gut.ParseLineFn { func (c *levelContext) addRow(p *gut.LineParser, line string) gut.ParseLineFn {
var tiles []Tile var tiles []TileType
var entities []EntityType var entities []EntityType
for i := 0; i < len(line); i += 2 { 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])) entities = append(entities, EntityType(line[i+1]))
} }
for i, t := range tiles { for i, t := range tiles {
if !t.IsValid() { 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 { for i, e := range entities {

View File

@ -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
View 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
}