refactor level, getting to tiles

This commit is contained in:
anton.gurov
2019-10-31 14:01:54 +03:00
parent e0bab00a23
commit c372670953
11 changed files with 189 additions and 180 deletions

View File

@ -18,7 +18,23 @@ type Level struct {
Branch string
Depth int
Objects []ecs.Entity
Tiles [][]*Tile
Tiles []*Tile
}
func (l *Level) GetTile (coords types.Coords) *Tile {
return l.Tiles[coords.Y*l.W+coords.X]
}
func (l *Level) GetTileByXY (x,y int) *Tile {
return l.Tiles[y*l.W+x]
}
func (l *Level) SetTile (coords types.Coords, tile *Tile) {
l.Tiles[coords.Y*l.W+coords.X] = tile
}
func (l *Level) SetTileByXY (x,y int, tile *Tile) {
l.Tiles[y*l.W+x] = tile
}
func (l *Level) Put (x, y int, tileFunc interface{}) {
@ -27,7 +43,7 @@ func (l *Level) Put (x, y int, tileFunc interface{}) {
l.ctx.Logger().Fatal().Msgf("Got non-tile type to put into level: %v", tf)
}
if l.InBounds(types.Coords{x, y}) {
l.Tiles[x][y] = tf
l.Tiles[y*l.W+x] = tf
}
}
@ -38,11 +54,7 @@ func NewLevel(ctx util.ClientCtx, branch string, depth int) *Level {
Rect: types.NewRect(0,0, mapWidth, mapHeight),
}
l.Tiles = make([][]*Tile, l.W)
for i := range l.Tiles {
l.Tiles[i] = make([]*Tile, l.H)
}
l.Tiles = make([]*Tile, l.W*l.H)
return l
}