move to terrain render system
This commit is contained in:
@ -2,19 +2,33 @@ package ecs
|
||||
|
||||
// ECS system by jcerise, github.com/jcerise/gogue
|
||||
|
||||
const AmmoComponent = "ammo"
|
||||
const AppearanceComponent = "appearance"
|
||||
const ArmorComponent = "armor"
|
||||
const ArmsComponent = "arms"
|
||||
const BackpackComponent = "backpack"
|
||||
const CarriedComponent = "carried"
|
||||
const ConsumableComponent = "consumable"
|
||||
const CoordsComponent = "coords"
|
||||
const MobComponent = "mob"
|
||||
const MoveableComponent = "movable"
|
||||
const CarriedComponent = "carried"
|
||||
const NamedComponent = "named"
|
||||
const RangedComponent = "ranged"
|
||||
const UsableComponent = "usable"
|
||||
const WearableComponent = "usable"
|
||||
const ArmsComponent = "arms"
|
||||
const RangedComponent = "ranged"
|
||||
const AmmoComponent = "ammo"
|
||||
const ArmorComponent = "armor"
|
||||
const BackpackComponent = "backpack"
|
||||
|
||||
type Component interface {
|
||||
Type() string
|
||||
}
|
||||
}
|
||||
|
||||
type Named struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (n Named) Type() string {
|
||||
return NamedComponent
|
||||
}
|
||||
|
||||
func (n Named) GetName() string {
|
||||
return n.Name
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ecs
|
||||
// ECS system by jcerise, github.com/jcerise/gogue
|
||||
|
||||
const MobRenderSystem = "mobrender"
|
||||
const TerrainRenderSystem = "terrainrender"
|
||||
|
||||
type System interface {
|
||||
Process()
|
||||
|
@ -7,27 +7,34 @@ import (
|
||||
)
|
||||
|
||||
type MobRenderSystem struct {
|
||||
EntityController *ecs.Controller
|
||||
Layer *mainwindow.Layer
|
||||
Controller *ecs.Controller
|
||||
Layer *mainwindow.Layer
|
||||
Viewport *mainwindow.ViewPort
|
||||
}
|
||||
|
||||
func (mrs MobRenderSystem) Process(){
|
||||
for e := range mrs.EntityController.GetEntities() {
|
||||
if mrs.EntityController.HasComponent(e, ecs.CoordsComponent) &&
|
||||
mrs.EntityController.HasComponent(e, ecs.AppearanceComponent) {
|
||||
for e := range mrs.Controller.GetEntities() {
|
||||
if mrs.Controller.HasComponent(e, ecs.CoordsComponent) &&
|
||||
mrs.Controller.HasComponent(e, ecs.AppearanceComponent) {
|
||||
|
||||
pos := mrs.EntityController.GetComponent(e, ecs.CoordsComponent).(types.Coords)
|
||||
appearance := mrs.EntityController.GetComponent(e, ecs.AppearanceComponent).(types.Appearance)
|
||||
pos := mrs.Controller.GetComponent(e, ecs.CoordsComponent).(types.Coords)
|
||||
appearance := mrs.Controller.GetComponent(e, ecs.AppearanceComponent).(types.Appearance)
|
||||
|
||||
//fixme
|
||||
// if vp.Rect.InBounds(pos) {
|
||||
// Clear the cell this entity occupies, so it is the only glyph drawn there
|
||||
for i := 0; i <= 2; i++ {
|
||||
mrs.Layer.ClearArea(pos.X, pos.Y,1,1)
|
||||
|
||||
//for i := 0; i <= 2; i++ {
|
||||
//mrs.Layer.ClearArea(pos.X, pos.Y,1,1) //WHY?!
|
||||
//gogue.ClearArea(pos.X, pos.Y, 1, 1, i)
|
||||
}
|
||||
//}
|
||||
|
||||
//fixme
|
||||
mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(pos.X, pos.Y, appearance.Glyph)
|
||||
mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(pos.X, pos.Y, appearance.Glyph.GetGlyph())
|
||||
mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(pos.X, pos.Y, appearance.Glyph.GetGlyph())
|
||||
//gogue.PrintGlyph(pos.X, pos.Y, appearance.Glyph, "", appearance.Layer)
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
engine/ecs/systems/terrain_render_system.go
Normal file
65
engine/ecs/systems/terrain_render_system.go
Normal file
@ -0,0 +1,65 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user