refactor level, getting to tiles
This commit is contained in:
@ -37,7 +37,7 @@ func (f *FieldOfVision) SetTorchRadius(radius int) {
|
||||
func (f *FieldOfVision) SetAllInvisible(level *gamemap.Level) {
|
||||
for x := 0; x < level.W; x++ {
|
||||
for y := 0; y < level.H; y++ {
|
||||
level.Tiles[x][y].Visible = false
|
||||
level.GetTileByXY(x,y).Visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,7 @@ func (f *FieldOfVision) RayCast(playerCoords types.Coords, level *gamemap.Level)
|
||||
y := float64(playerCoords.Y)
|
||||
|
||||
// Mark the players current position as explored
|
||||
tile := level.Tiles[playerCoords.X][playerCoords.Y]
|
||||
tile := level.GetTile(playerCoords) //[playerCoords.X][playerCoords.Y]
|
||||
tile.Explored = true
|
||||
tile.Visible = true
|
||||
|
||||
@ -73,12 +73,12 @@ func (f *FieldOfVision) RayCast(playerCoords types.Coords, level *gamemap.Level)
|
||||
break
|
||||
}
|
||||
|
||||
tile := level.Tiles[roundedX][roundedY]
|
||||
tile := level.GetTileByXY(roundedX, roundedY)
|
||||
|
||||
tile.Explored = true
|
||||
tile.Visible = true
|
||||
|
||||
if level.Tiles[roundedX][roundedY].BlocksSight == true {
|
||||
if level.GetTileByXY(roundedX, roundedY).BlocksSight == true {
|
||||
// The ray hit a wall, go no further
|
||||
break
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
|
||||
radius = ps.MaxTorchRadius //fixme
|
||||
}
|
||||
|
||||
level.Tiles[initCoords.X][initCoords.Y].Visible = true
|
||||
level.GetTile(initCoords).Visible = true
|
||||
|
||||
var fullShade = make([]byte, 360)
|
||||
for i := range fullShade {
|
||||
@ -226,7 +226,7 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
|
||||
//fmt.Printf("\n level coords: %v", lc)
|
||||
for _, angle := range cell.occludedAngles {
|
||||
|
||||
if level.Tiles[lc.X][lc.Y].BlocksSight {
|
||||
if level.GetTile(lc).BlocksSight {
|
||||
nextShade[angle] = 1
|
||||
}
|
||||
|
||||
@ -236,8 +236,8 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
|
||||
|
||||
}
|
||||
|
||||
if level.Tiles[lc.X][lc.Y].BlocksSight {
|
||||
level.Tiles[lc.X][lc.Y].Visible = true
|
||||
if level.GetTile(lc).BlocksSight {
|
||||
level.GetTile(lc).Visible = true
|
||||
}
|
||||
|
||||
}
|
||||
@ -254,7 +254,7 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
level.Tiles[cs.X][cs.Y].Visible = true
|
||||
level.GetTile(cs).Visible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,7 @@ func TestPrecompShade(t *testing.T) {
|
||||
Rect: types.NewRect(0, 0, 20, 20),
|
||||
}
|
||||
|
||||
level.Tiles = make([][]*gamemap.Tile, level.W)
|
||||
for i := range level.Tiles {
|
||||
level.Tiles[i] = make([]*gamemap.Tile, level.H)
|
||||
}
|
||||
level.Tiles = make([]*gamemap.Tile, level.W * level.H)
|
||||
|
||||
var tile func() (*gamemap.Tile)
|
||||
|
||||
@ -43,21 +40,21 @@ func TestPrecompShade(t *testing.T) {
|
||||
} else {
|
||||
tile = gamemap.NewFloor
|
||||
}
|
||||
level.Tiles[x][y] = tile()
|
||||
level.SetTileByXY(x, y, tile())
|
||||
}
|
||||
}
|
||||
|
||||
playerCoords := types.Coords{10, 10}
|
||||
|
||||
level.Tiles[8][12] = gamemap.NewWall()
|
||||
level.Tiles[10][8] = gamemap.NewWall()
|
||||
level.SetTileByXY(8, 12, gamemap.NewWall())
|
||||
level.SetTileByXY(10, 8, gamemap.NewWall())
|
||||
|
||||
level.Tiles[7][9] = gamemap.NewWall()
|
||||
level.Tiles[7][11] = gamemap.NewWall()
|
||||
level.Tiles[5][10] = gamemap.NewWall()
|
||||
level.SetTileByXY(7, 9, gamemap.NewWall())
|
||||
level.SetTileByXY(7, 11, gamemap.NewWall())
|
||||
level.SetTileByXY(5, 10, gamemap.NewWall())
|
||||
|
||||
level.Tiles[10][11] = gamemap.NewWall()
|
||||
level.Tiles[11][10] = gamemap.NewWall()
|
||||
level.SetTileByXY(10, 11, gamemap.NewWall())
|
||||
level.SetTileByXY(11, 10, gamemap.NewWall())
|
||||
|
||||
ppFov.ComputeFov(level, playerCoords, 12)
|
||||
|
||||
@ -67,8 +64,8 @@ func TestPrecompShade(t *testing.T) {
|
||||
if playerCoords.X == x && playerCoords.Y == y {
|
||||
return "@"
|
||||
}
|
||||
result := level.Tiles[x][y].Char
|
||||
if !level.Tiles[x][y].Visible {
|
||||
result := level.GetTileByXY(x, y).Char
|
||||
if !level.GetTileByXY(x, y).Visible {
|
||||
result = "?"
|
||||
}
|
||||
return result
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user