first item, render order? redraw? broken

This commit is contained in:
thefish 2019-11-16 05:15:02 +03:00
parent 768426a316
commit 685dfeeeb1
4 changed files with 49 additions and 24 deletions

View File

@ -8,6 +8,7 @@ import (
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap/mapgens"
"lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/items"
"lab.zaar.be/thefish/alchemyst-go/engine/mob"
"lab.zaar.be/thefish/alchemyst-go/engine/mob/movement"
"lab.zaar.be/thefish/alchemyst-go/engine/screens"
@ -174,6 +175,18 @@ func main() {
controller.AddComponent(player, rooms[0].Center) //implicit Coords
controller.AddComponent(player, moveable)
potion := controller.CreateEntity([]ecs.Component{})
controller.AddComponent(potion, types.Appearance{
Glyph: types.PlainGlyphHolder{"!"},
ColorSet: types.TileColorSet{
Fg: types.PlainColorHolder{255, 55, 255, 222},
},
})
controller.AddComponent(potion, rooms[1].Center) //implicit Coords
controller.AddComponent(potion, items.Carried{})
controller.AddComponent(potion, items.Usable{})
controller.AddComponent(potion, items.Consumable{})
State.Player = player
State.Controller = controller

View File

@ -1,8 +1,8 @@
package systems
import (
"fmt"
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/fov"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
@ -12,26 +12,34 @@ type MobRenderSystem struct {
Controller *ecs.Controller
Layer *mainwindow.Layer
Viewport *mainwindow.ViewPort
Fov fov.Fov
*gamemap.Level
}
func (mrs MobRenderSystem) Process(){
for e := range mrs.Controller.GetEntities() {
if mrs.Controller.HasComponent(e, ecs.CoordsComponent) &&
mrs.Controller.HasComponent(e, ecs.AppearanceComponent) {
func (mrs MobRenderSystem) Process() {
//if redraw {
for e := range mrs.Controller.GetEntities() {
if mrs.Controller.HasComponent(e, ecs.CoordsComponent) &&
mrs.Controller.HasComponent(e, ecs.AppearanceComponent) {
pos := mrs.Controller.GetComponent(e, ecs.CoordsComponent).(types.Coords)
appearance := mrs.Controller.GetComponent(e, ecs.AppearanceComponent).(types.Appearance)
pos := mrs.Controller.GetComponent(e, ecs.CoordsComponent).(types.Coords)
appearance := mrs.Controller.GetComponent(e, ecs.AppearanceComponent).(types.Appearance)
vpc, err := mrs.Viewport.ToVPCoords(pos)
if err != nil {
fmt.Printf("Err: " , err)
//fixme fov check
//if !mrs.Fov.IsInFov(pos) {
// continue
//}
vpc, err := mrs.Viewport.ToVPCoords(pos)
if err != nil {
continue //we cant see it? no problem.
}
mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(vpc.X, vpc.Y, appearance.Glyph.GetGlyph())
}
mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(vpc.X, vpc.Y, appearance.Glyph.GetGlyph())
}
}
//}
}
func (mrs MobRenderSystem) SystemType() string {
return ecs.MobRenderSystem
}
}

View File

@ -3,7 +3,6 @@ package systems
import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/fov"
"lab.zaar.be/thefish/alchemyst-go/engine/fov/precomputed_shade"
"lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
@ -18,34 +17,29 @@ type TerrainRenderSystem struct {
Viewport *mainwindow.ViewPort
state *gamestate.GameState
layer *mainwindow.Layer
animateTiles *time.Ticker
fov fov.Fov
animateTiles *time.Ticker
TorchRadius int
redraw bool
fovRecompute bool
}
func NewTerrainRenderSystem(
state *gamestate.GameState,
vp *mainwindow.ViewPort,
layer *mainwindow.Layer,
fov fov.Fov,
) TerrainRenderSystem {
trs := TerrainRenderSystem{
Viewport:vp,
layer: layer,
state: state,
redraw: true,
fovRecompute: true,
fov: fov,
}
computedFov := precomputed_shade.NewPrecomputedShade(15)
computedFov.Init()
trs.TorchRadius = 12 //fixme move to sight component
trs.animateTiles = time.NewTicker(time.Second / 12)
trs.fov = computedFov
return trs
}
@ -76,9 +70,9 @@ func (trs TerrainRenderSystem) Process() {
if fovRecompute {
trs.layer.ClearRect(trs.Viewport.Rect)
trs.fov.ComputeFov(trs.state.Level, playerCoords, trs.TorchRadius)
fovRecompute = false
redraw = true
trs.fov.ComputeFov(trs.state.Level, playerCoords, trs.TorchRadius)
}
if redraw {

View File

@ -3,6 +3,8 @@ package screens
import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/ecs/systems"
"lab.zaar.be/thefish/alchemyst-go/engine/fov"
"lab.zaar.be/thefish/alchemyst-go/engine/fov/precomputed_shade"
"lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/mob/movement"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
@ -15,18 +17,26 @@ type GameScreen struct {
vp *mainwindow.ViewPort
controller *ecs.Controller
scm *types.ScreenManager
fov fov.Fov
}
func NewGameScreen(mw *mainwindow.MainWindow, state *gamestate.GameState, viewPort *mainwindow.ViewPort, controller *ecs.Controller, scm *types.ScreenManager) *GameScreen {
ts := &GameScreen{mw: mw, state: state, vp: viewPort, controller: controller, scm: scm}
//fixme move this to fov system
computedFov := precomputed_shade.NewPrecomputedShade(15)
computedFov.Init()
ts.fov = computedFov
renderMobs := systems.MobRenderSystem{
Controller: ts.controller,
Layer: ts.mw.GetLayer("base"),
Viewport: ts.vp,
Level: state.Level,
Fov: ts.fov,
}
ts.controller.AddSystem(renderMobs, 10)
renderTerrain := systems.NewTerrainRenderSystem(state, viewPort, ts.mw.GetLayer("base"))
renderTerrain := systems.NewTerrainRenderSystem(state, viewPort, ts.mw.GetLayer("base"), ts.fov)
go renderTerrain.Listen()
ts.controller.AddSystem(renderTerrain, 5)