animation handling, screens, vp changes
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/fov/precomputed_shade"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
var NotInViewError = errors.New("not in ViewPort")
|
||||
@ -19,26 +20,35 @@ type ViewPort struct {
|
||||
Fov fov.Fov
|
||||
PlayerCoords types.Coords
|
||||
PlayerTorchRadius int
|
||||
animateTiles *time.Ticker
|
||||
}
|
||||
|
||||
func NewViewPort(x, y, w, h int, level *gamemap.Level, layer *Layer) *ViewPort {
|
||||
//fixme
|
||||
fov := precomputed_shade.NewPrecomputedShade(15)
|
||||
fov.Init()
|
||||
computedFov := precomputed_shade.NewPrecomputedShade(15)
|
||||
computedFov.Init()
|
||||
vp := ViewPort{
|
||||
Rect: &types.Rect{x, y, w, h},
|
||||
level: level,
|
||||
layer: layer,
|
||||
Fov: fov,
|
||||
Fov: computedFov,
|
||||
}
|
||||
|
||||
vp.PlayerCoords = types.Coords{10, 10}
|
||||
vp.PlayerTorchRadius = 10
|
||||
vp.PlayerTorchRadius = 14
|
||||
vp.animateTiles = time.NewTicker(time.Second / 10)
|
||||
|
||||
return &vp
|
||||
}
|
||||
|
||||
func (vp *ViewPort) Move(c *types.Coords, state types.GameState) {
|
||||
func (vp *ViewPort) Close() {
|
||||
vp.animateTiles.Stop()
|
||||
vp.animateTiles = nil //free pointer to ticker
|
||||
}
|
||||
|
||||
func (vp *ViewPort) Move(state *types.GameState) {
|
||||
|
||||
c := &state.Player.Coords
|
||||
|
||||
x := c.X - vp.Rect.W/2
|
||||
y := c.Y - vp.Rect.H/2
|
||||
|
||||
@ -71,55 +81,6 @@ func (vp *ViewPort) ToVPCoords(c types.Coords) (newCoords types.Coords, err erro
|
||||
return types.Coords{x, y}, nil
|
||||
}
|
||||
|
||||
////call only from main thread
|
||||
//func (vp *ViewPort) Render() {
|
||||
// //fixme get these from state chan(s)
|
||||
// var fpsTicker int
|
||||
// var fovRecompute bool = true
|
||||
// redraw := false
|
||||
// //fixme get player instance
|
||||
//
|
||||
// vp.Move(&vp.PlayerCoords)
|
||||
// //fixme detect fovRecompute
|
||||
// if fovRecompute {
|
||||
// vp.layer.ClearRect(vp.Rect)
|
||||
// fovRecompute = false
|
||||
// redraw = true
|
||||
// //fixme
|
||||
//
|
||||
// vp.Fov.ComputeFov(vp.level, vp.PlayerCoords, vp.PlayerTorchRadius)
|
||||
// }
|
||||
// //increase ticker
|
||||
// fpsTicker++
|
||||
//
|
||||
// if redraw || fpsTicker%(FPS_LIMIT/10) == 0 {
|
||||
// fpsTicker = 0
|
||||
//
|
||||
// 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]
|
||||
// visible := vp.Fov.IsInFov(mapCoords)
|
||||
// if !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
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
var redraw = true
|
||||
var fovRecompute = true
|
||||
|
||||
@ -130,19 +91,21 @@ func (vp *ViewPort) Listen(state types.GameState) {
|
||||
fovRecompute = true
|
||||
case <-state.Redraw:
|
||||
redraw = true
|
||||
case <-vp.animateTiles.C:
|
||||
redraw = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (vp *ViewPort) Render(state types.GameState) {
|
||||
func (vp *ViewPort) Render(state *types.GameState) {
|
||||
|
||||
vp.Move(&vp.PlayerCoords, state)
|
||||
vp.Move(state)
|
||||
|
||||
if fovRecompute {
|
||||
vp.layer.ClearRect(vp.Rect)
|
||||
fovRecompute = false
|
||||
redraw = true
|
||||
vp.Fov.ComputeFov(vp.level, vp.PlayerCoords, vp.PlayerTorchRadius)
|
||||
vp.Fov.ComputeFov(vp.level, state.Player.Coords, vp.PlayerTorchRadius)
|
||||
}
|
||||
|
||||
if redraw {
|
||||
@ -154,24 +117,25 @@ func (vp *ViewPort) Render(state types.GameState) {
|
||||
if vp.level.InBounds(mapCoords) {
|
||||
tile := vp.level.GetTile(mapCoords)
|
||||
if tile.Explored || tile.MustDraw || tile.Visible {
|
||||
vp.layer.PutToBase(x + vp.X, y + vp.Y, tile.GetChar(), tile.GetRawColor(), tile.GetRawBgColor())
|
||||
vp.layer.PutToBase(x+vp.X, y+vp.Y, tile.GetChar(), tile.GetRawColor(), tile.GetRawBgColor())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//mobs
|
||||
pc,err := vp.ToVPCoords(vp.PlayerCoords)
|
||||
pc, err := vp.ToVPCoords(vp.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, "@")
|
||||
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
|
||||
//redraw = true
|
||||
redraw = false
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user