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
}

View File

@ -18,7 +18,7 @@ func DefaultGen(l *gamemap.Level) *gamemap.Level {
//fill with walls
for i := 0; i < l.W; i ++ {
for j := 0; j < l.H; j++ {
l.Tiles[i][j] = gamemap.NewWall()
l.SetTileByXY(i, j, gamemap.NewWall())
}
}
@ -113,7 +113,7 @@ func digHTunnel(l *gamemap.Level, x1,x2,y int, fillage types.RectFill) {
}
for i := start; i <= finish; i++ {
if l.InBounds(types.Coords{i, y}) {
l.Tiles[i][y] = fillage.Body.(func() *gamemap.Tile)()
l.SetTileByXY(i, y, fillage.Body.(func() *gamemap.Tile)())
//l.Tiles[i][y] = gamemap.NewFloor()
}
}
@ -130,7 +130,7 @@ func digVTunnel(l *gamemap.Level, y1,y2,x int, fillage types.RectFill) {
}
for i := start; i <= finish; i++ {
if l.InBounds(types.Coords{x, i}) {
l.Tiles[x][i] = fillage.Body.(func() *gamemap.Tile)()
l.SetTileByXY(x, i, fillage.Body.(func() *gamemap.Tile)())
}
}
}

View File

@ -1,6 +1,9 @@
package gamemap
import "lab.zaar.be/thefish/alchemyst-go/util"
import (
"container/ring"
"lab.zaar.be/thefish/alchemyst-go/util"
)
import blt "lab.zaar.be/thefish/bearlibterminal"
type ColorHolder struct {
@ -24,6 +27,28 @@ type Appearance struct {
var crng = util.NewRNG()
func NewColorComponentRing(colorValue uint8, minGlow, maxGlow, step int) *ring.Ring {
q := make([]uint8, 0)
color := int(colorValue)
for color < maxGlow {
q = append(q, uint8(color))
color = crng.Range(0, step) + color
}
color = crng.Range(0, step + minGlow)
for uint8(color) < colorValue {
q = append(q, uint8(color))
color = crng.Range(0, step + minGlow)
}
r := ring.New(len(q))
for _, v := range q {
r.Next().Value = v
}
return r
}
func colordance(colorValue uint8, minGlow, maxGlow, step int) uint8 {
color := crng.Range(0, step) + int(colorValue)
if color > maxGlow {