refactor level, getting to tiles
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user