reorganize

This commit is contained in:
2019-11-01 18:21:27 +03:00
parent 1ac6ae4665
commit 529f5a5749
7 changed files with 56 additions and 49 deletions

View File

@ -5,7 +5,7 @@ import (
"fmt"
"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/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"time"
)
@ -15,7 +15,6 @@ var NotInViewError = errors.New("not in ViewPort")
type ViewPort struct {
*types.Rect
cameraCoords types.Coords
level *gamemap.Level
layer *Layer
Fov fov.Fov
PlayerCoords types.Coords
@ -23,19 +22,18 @@ type ViewPort struct {
animateTiles *time.Ticker
}
func NewViewPort(x, y, w, h int, level *gamemap.Level, layer *Layer) *ViewPort {
//fixme
func NewViewPort(x, y, w, h int, layer *Layer) *ViewPort {
computedFov := precomputed_shade.NewPrecomputedShade(15)
computedFov.Init()
vp := ViewPort{
Rect: &types.Rect{x, y, w, h},
level: level,
layer: layer,
Fov: computedFov,
}
vp.PlayerTorchRadius = 14
vp.animateTiles = time.NewTicker(time.Second / 10)
vp.PlayerTorchRadius = 9
vp.animateTiles = time.NewTicker(time.Second / 12)
return &vp
}
@ -45,10 +43,10 @@ func (vp *ViewPort) Close() {
vp.animateTiles = nil //free pointer to ticker
}
func (vp *ViewPort) Move(state *types.GameState) {
func (vp *ViewPort) Move(state *gamestate.GameState) {
c := &state.Player.Coords
x := c.X - vp.Rect.W/2
y := c.Y - vp.Rect.H/2
@ -58,11 +56,11 @@ func (vp *ViewPort) Move(state *types.GameState) {
if y < 0 {
y = 0
}
if x > vp.level.W-vp.W {
x = vp.level.W - vp.W - 1
if x > state.Level.W-vp.W {
x = state.Level.W - vp.W - 1
}
if y > vp.level.H-vp.H {
x = vp.level.H - vp.H - 1
if y > state.Level.H-vp.H {
x = state.Level.H - vp.H - 1
}
if x != vp.cameraCoords.X || y != vp.cameraCoords.Y {
state.FovRecompute <- struct{}{}
@ -84,7 +82,7 @@ func (vp *ViewPort) ToVPCoords(c types.Coords) (newCoords types.Coords, err erro
var redraw = true
var fovRecompute = true
func (vp *ViewPort) Listen(state types.GameState) {
func (vp *ViewPort) Listen(state gamestate.GameState) {
for {
select {
case <-state.FovRecompute:
@ -97,7 +95,7 @@ func (vp *ViewPort) Listen(state types.GameState) {
}
}
func (vp *ViewPort) Render(state *types.GameState) {
func (vp *ViewPort) Render(state *gamestate.GameState) {
vp.Move(state)
@ -105,7 +103,7 @@ func (vp *ViewPort) Render(state *types.GameState) {
vp.layer.ClearRect(vp.Rect)
fovRecompute = false
redraw = true
vp.Fov.ComputeFov(vp.level, state.Player.Coords, vp.PlayerTorchRadius)
vp.Fov.ComputeFov(state.Level, state.Player.Coords, vp.PlayerTorchRadius)
}
if redraw {
@ -114,8 +112,8 @@ func (vp *ViewPort) Render(state *types.GameState) {
for x := 0; x < vp.W; x++ {
mapCoords := types.Coords{vp.cameraCoords.X + x, vp.cameraCoords.Y + y}
if vp.level.InBounds(mapCoords) {
tile := vp.level.GetTile(mapCoords)
if state.Level.InBounds(mapCoords) {
tile := state.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())
}