working prototype with ecs

This commit is contained in:
anton.gurov
2019-11-05 17:55:38 +03:00
parent 096ff2b182
commit a195e335eb
7 changed files with 120 additions and 52 deletions

View File

@ -6,7 +6,6 @@ import (
"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"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"time"
)
@ -18,7 +17,6 @@ type ViewPort struct {
cameraCoords types.Coords
layer *Layer
Fov fov.Fov
Player mob.Player
TorchRadius int
animateTiles *time.Ticker
}
@ -44,12 +42,10 @@ func (vp *ViewPort) Close() {
vp.animateTiles = nil //free pointer to ticker
}
func (vp *ViewPort) Move(state *gamestate.GameState) {
func (vp *ViewPort) Move(state *gamestate.GameState, newCoords types.Coords) {
c := &state.Level.Player.HasComponent(types.Coords{}).Coords
x := c.X - vp.Rect.W/2
y := c.Y - vp.Rect.H/2
x := newCoords.X - vp.Rect.W/2
y := newCoords.Y - vp.Rect.H/2
if x < 0 {
x = 0
@ -98,16 +94,22 @@ func (vp *ViewPort) Listen(state gamestate.GameState) {
func (vp *ViewPort) Render(state *gamestate.GameState) {
vp.Move(state)
playerCoords := state.Controller.GetComponent(state.Player, types.Coords{}.TypeOf()).(types.Coords)
vp.Move(state, playerCoords)
if fovRecompute {
vp.layer.ClearRect(vp.Rect)
fovRecompute = true
fovRecompute = false
redraw = true
vp.Fov.ComputeFov(state.Level, state.Level.Player.Coords, vp.TorchRadius)
vp.Fov.ComputeFov(state.Level, playerCoords, vp.TorchRadius)
}
//if redraw {
vp.layer.ClearArea(0, 7, 40, 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++ {
@ -122,7 +124,7 @@ func (vp *ViewPort) Render(state *gamestate.GameState) {
}
}
//mobs
pc, err := vp.ToVPCoords(state.Level.Player.Coords)
pc, err := vp.ToVPCoords(playerCoords)
_ = pc
if err != nil {
fmt.Println("error on getting player position")
@ -133,8 +135,7 @@ func (vp *ViewPort) Render(state *gamestate.GameState) {
}
//redraw = true
//redraw = false
//}
redraw = false
}
}