alchemyst/engine/ecs/systems/terrain_render_system.go

65 lines
1.6 KiB
Go

package systems
import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
)
type TerrainRenderSystem struct {
Viewport mainwindow.ViewPort
Level gamemap.Level
}
func (trs TerrainRenderSystem) Process() {
playerCoords := state.Controller.GetComponent(state.Player, ecs.CoordsComponent).(types.Coords)
vp.Move(state, playerCoords)
if fovRecompute {
vp.layer.ClearRect(vp.Rect)
fovRecompute = false
redraw = true
vp.Fov.ComputeFov(state.Level, playerCoords, vp.TorchRadius)
}
//vp.layer.ClearArea(0, 7, 20, 1)
//vp.layer.Print(0,7, fmt.Sprintf("pcds: %v", playerCoords))
if redraw {
//terrain
for y := 0; y < vp.H; y++ {
for x := 0; x < vp.W; x++ {
mapCoords := types.Coords{vp.cameraCoords.X + x, vp.cameraCoords.Y + y}
if state.Level.InBounds(mapCoords) {
tile := state.Level.GetTile(mapCoords)
if tile.Explored || tile.Visible {
vp.layer.PutToBase(x+vp.X, y+vp.Y, tile.GetChar(), tile.GetRawColor(), tile.GetRawBgColor())
}
}
}
}
/*
//mobs
pc, err := vp.ToVPCoords(playerCoords)
_ = pc
if err != nil {
fmt.Println("error on getting player position")
} else {
vp.layer.WithColor("white").Put(pc.X+vp.X, pc.Y+vp.Y, "@")
//mw.GetLayer("base").WithColor("white").Put(42, 10, "B")
//mw.GetLayer("overlay").WithColor("white").Put(59, 10, "O")
}
*/
//redraw = true
redraw = false
}
}
func (trs TerrainRenderSystem) Type() string {
return ecs.TerrainRenderSystem
}