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

@ -32,3 +32,11 @@ func ReadKey() (string, int) {
return pressed, key
}
func ReadKeyCode() int {
if !blt.HasInput() {
return blt.TK_NONE
}
return blt.Read()
}

View File

@ -10,11 +10,6 @@ type Layer struct {
defaultColor uint32
}
func AddLayer(idx int, colorName string) Layer {
c := blt.ColorFromName(colorName)
return Layer{idx: idx, defaultColor: c}
}
func (layer *Layer) before() *Layer {
blt.Layer(layer.idx)
return layer

View File

@ -9,16 +9,32 @@ import (
type MainWindow struct {
ctx util.ClientCtx
layers []types.Renderable
layers map[string]types.Renderable
}
func Init(ctx util.ClientCtx) *MainWindow {
ctx.Logger().Info().Msgf("Opening main window...")
mw := MainWindow{ctx: ctx}
mw := MainWindow{ctx: ctx, layers: make(map[string]types.Renderable, 0)}
mw.Open()
return &mw
}
func (mw *MainWindow) AddLayer(name string, idx int, colorName string) *MainWindow {
c := blt.ColorFromName(colorName)
mw.layers[name] = &Layer{idx: idx, defaultColor: c}
return mw
}
func (mw *MainWindow) GetLayer(name string) *Layer {
if layer, ok := mw.layers[name]; ok {
return layer.(*Layer)
}
mw.ctx.Logger().Fatal().Msgf("No layer with such name %s", name)
return nil
}
func (mw *MainWindow) Open() {
config := mw.ctx.Config()
blt.Open()
@ -46,8 +62,4 @@ func (mw *MainWindow) Render() {
for _, l := range mw.layers {
l.Render()
}
}
func (mw *MainWindow) AddLayer(li types.Renderable) {
mw.layers = append(mw.layers, li)
}
}

View File

@ -129,30 +129,47 @@ func (vp *ViewPort) Render() {
vp.Fov.ComputeFov(vp.level, vp.playerCoords, vp.playerTorchRadius)
}
//for y := 0; y < vp.H; y++ {
// for x := 0; x < vp.W; x++ {
// mapCoords := types.Coords{vp.X + x, vp.Y + y}
// tile := vp.level.Tiles[mapCoords.X][mapCoords.Y]
//
// if tile.Visible {
// if tile.MustDraw {
// //darkened version of landscape
// vp.layer.WithRawColor(tile.ColorSet.DarkFg()).
// PutWithRawBackground(mapCoords.X, mapCoords.Y, tile.Char, tile.ColorSet.DarkBg())
// }
// } else {
// if redraw == true || tile.Colordance {
// vp.layer.WithRawColor(tile.ColorSet.Fg()).
// PutWithRawBackground(mapCoords.X, mapCoords.Y, tile.Char, tile.ColorSet.Bg())
// tile.Explored = true
// tile.MustDraw = true
// }
// }
// }
//}
for y := 0; y < vp.H; y++ {
for x := 0; x < vp.W; x++ {
mapCoords := types.Coords{vp.X + x, vp.Y + y}
tile := vp.level.Tiles[mapCoords.X][mapCoords.Y]
tile := vp.level.GetTile(mapCoords)
if tile.Visible {
if tile.MustDraw {
//darkened version of landscape
vp.layer.WithRawColor(tile.ColorSet.DarkFg()).
PutWithRawBackground(mapCoords.X, mapCoords.Y, tile.Char, tile.ColorSet.DarkBg())
vp.layer.WithColor("green").
Put(mapCoords.X, mapCoords.Y, tile.Char)
}
} else {
if redraw == true || tile.Colordance {
vp.layer.WithRawColor(tile.ColorSet.Fg()).
PutWithRawBackground(mapCoords.X, mapCoords.Y, tile.Char, tile.ColorSet.Bg())
vp.layer.WithColor("white").
Put(mapCoords.X, mapCoords.Y, tile.Char)
tile.Explored = true
tile.MustDraw = true
}
}
//fg := tile.ColorSet.Fg()
//bg := tile.ColorSet.Bg()
//vp.layer.WithRawColor(fg).
// PutWithRawBackground(mapCoords.X, mapCoords.Y, tile.Char, bg)
}
}