From e9e6160f9eb2f217c457e6aa1b67f0fb3fea6fc8 Mon Sep 17 00:00:00 2001 From: "anton.gurov" Date: Thu, 7 Nov 2019 13:30:37 +0300 Subject: [PATCH] fixed lit thresholds --- cmd/game/main.go | 39 +++++++++---------- .../precomputed_shade/precomputed_shade.go | 6 +-- engine/gamemap/level.go | 16 ++++++++ engine/screens/game.go | 35 ++++++++++------- ui/mainwindow/mainwindow.go | 2 + ui/mainwindow/viewport.go | 2 +- 6 files changed, 61 insertions(+), 39 deletions(-) diff --git a/cmd/game/main.go b/cmd/game/main.go index baebb51..0d546ea 100644 --- a/cmd/game/main.go +++ b/cmd/game/main.go @@ -4,7 +4,6 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" "lab.zaar.be/thefish/alchemyst-go/engine/ecs" - "lab.zaar.be/thefish/alchemyst-go/engine/ecs/systems" "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" @@ -76,13 +75,29 @@ func main() { State.Level = level //Set up viewport - vp := mainwindow.NewViewPort(30, 0, 70, 47, mw.GetLayer("base")) + vp := mainwindow.NewViewPort(30, 0, (mw.W - 30), (mw.H - 0), mw.GetLayer("base")) go vp.Listen(State) + + //set up controller + + controller := ecs.NewController() + + controller.MapComponentClass("coords", types.Coords{}) + controller.MapComponentClass("appearance", types.Appearance{}) + controller.MapComponentClass("mob", mob.Mob{}) + controller.MapComponentClass("moveable", movement.Moveable{}) + + moveable := movement.Moveable{ + Controller: controller, + Level: level, + } + + //Set up Screen Manager screenMgr := types.NewScreenManager(mainCtx) screenMgr.AddScreen("title", &screens.TitleScreen{}) - screenMgr.AddScreen("game", screens.NewGameScreen(mw, &State, vp)) + screenMgr.AddScreen("game", screens.NewGameScreen(mw, &State, vp, controller)) screenMgr.SetScreenByName("game") @@ -104,19 +119,6 @@ func main() { //vp.PlayerCoords = player.Coords //vp.Render(&State) - //set up controller - - controller := ecs.NewController() - - controller.MapComponentClass("coords", types.Coords{}) - controller.MapComponentClass("appearance", types.Appearance{}) - controller.MapComponentClass("mob", mob.Mob{}) - controller.MapComponentClass("moveable", movement.Moveable{}) - - moveable := movement.Moveable{ - Controller: controller, - Level: level, - } //fixme set up (load / generate) player player := controller.CreateEntity([]ecs.Component{}) @@ -131,11 +133,6 @@ func main() { controller.AddComponent(player, rooms[0].Center) //implicit Coords controller.AddComponent(player, moveable) - - render := systems.MobRenderSystem{EntityController: controller} - - controller.AddSystem(render, 1) - State.Player = player State.Controller = controller diff --git a/engine/fov/precomputed_shade/precomputed_shade.go b/engine/fov/precomputed_shade/precomputed_shade.go index 4013009..e55e498 100644 --- a/engine/fov/precomputed_shade/precomputed_shade.go +++ b/engine/fov/precomputed_shade/precomputed_shade.go @@ -21,8 +21,6 @@ import ( // - Only lighting walls with light from the player (cheap trick, dutch) // - Match light value for walls with the highest light value in adjacent floor cell visible to player (seems costly) - - /* Why am I here? Well, I just don't know what to call it - I'm sure it's an established method, and I'm aware there are probably optimisations to be had. I thought if I roughed out the algorithm here, the r/roguelikedev community would @@ -258,7 +256,7 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co for _, cell := range ps.CellList { //fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit) cs, err := ps.toLevelCoords(level, initCoords, cell.Coords) - if cell.lit > 0 { + if cell.lit > 2 { if err != nil { continue } @@ -275,7 +273,7 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co if //int(maybeNb.distance) == int(cell.distance-1) && maybeNb.IsAdjacentTo(&cell.Coords) && //(maybeNb.X == cell.X || maybeNb.Y == cell.Y) && - maybeNb.lit > 0 { //magic constant! + maybeNb.lit > 5 { //magic constant! level.GetTile(cs).Visible = true level.GetTile(cs).Explored = true } diff --git a/engine/gamemap/level.go b/engine/gamemap/level.go index 89f4a6c..2ca205f 100644 --- a/engine/gamemap/level.go +++ b/engine/gamemap/level.go @@ -25,6 +25,22 @@ func (l *Level) GetTile (coords types.Coords) *Tile { return l.Tiles[coords.Y*l.W+coords.X] } +func (l *Level) GetTileNbs (coords types.Coords) []*Tile { + result := make([]*Tile,0) + for i := coords.X-1; i < coords.X+1; i++ { + for j := coords.Y-1; j < coords.Y+1; j++ { + nbc := types.Coords{i,j} + if l.InBounds(nbc){ + if nbc == coords { + continue + } + result = append(result, l.GetTileByXY(i,j)) + } + } + } + return result +} + func (l *Level) GetTileByXY (x,y int) *Tile { return l.Tiles[y*l.W+x] } diff --git a/engine/screens/game.go b/engine/screens/game.go index 0a6b285..8e73ae2 100644 --- a/engine/screens/game.go +++ b/engine/screens/game.go @@ -1,6 +1,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/gamestate" "lab.zaar.be/thefish/alchemyst-go/engine/mob/movement" "lab.zaar.be/thefish/alchemyst-go/engine/types" @@ -11,14 +13,22 @@ type GameScreen struct { mw *mainwindow.MainWindow state *gamestate.GameState vp *mainwindow.ViewPort + controller *ecs.Controller } -func NewGameScreen(mw *mainwindow.MainWindow, state *gamestate.GameState, viewPort *mainwindow.ViewPort) *GameScreen { - return &GameScreen{mw: mw, state: state, vp: viewPort} +func NewGameScreen(mw *mainwindow.MainWindow, state *gamestate.GameState, viewPort *mainwindow.ViewPort, controller *ecs.Controller) *GameScreen { + return &GameScreen{mw: mw, state: state, vp: viewPort, controller: controller} } func (ts *GameScreen) UseEcs() bool { return true } -func (ts *GameScreen) Enter() {} +func (ts *GameScreen) Enter() { + renderMobs := systems.MobRenderSystem{EntityController: ts.controller} + ts.controller.AddSystem(renderMobs, 1) +} +func (ts *GameScreen) Exit() { + //remove what we dont need +} + func (ts *GameScreen) HandleInput(input string) { //ts.state.Do(func(){ switch input { @@ -26,25 +36,25 @@ func (ts *GameScreen) HandleInput(input string) { ts.walk(ts.state, 0, -1) break case "Down", "j", "2": - ts.walk(ts.state,0, 1) + ts.walk(ts.state, 0, 1) break case "Left", "h", "4": - ts.walk(ts.state,-1, 0) + ts.walk(ts.state, -1, 0) break case "Right", "l", "6": - ts.walk(ts.state,1, 0) + ts.walk(ts.state, 1, 0) break case "y", "7": - ts.walk(ts.state,-1, -1) + ts.walk(ts.state, -1, -1) break case "u", "9": - ts.walk(ts.state,1, -1) + ts.walk(ts.state, 1, -1) break case "b", "1": - ts.walk(ts.state,-1, 1) + ts.walk(ts.state, -1, 1) break case "n", "3": - ts.walk(ts.state,1, 1) + ts.walk(ts.state, 1, 1) break default: ts.mw.GetLayer("base").ClearArea(0, 3, 40, 1) @@ -54,12 +64,11 @@ func (ts *GameScreen) HandleInput(input string) { } //}) } -func (ts *GameScreen) Exit() {} + func (ts *GameScreen) Render() { ts.vp.Render(ts.state) } - func (ts *GameScreen) walk(state *gamestate.GameState, dx, dy int) { controller := state.Controller coords := controller.GetComponent(state.Player, types.Coords{}.TypeOf()).(types.Coords) @@ -72,4 +81,4 @@ func (ts *GameScreen) walk(state *gamestate.GameState, dx, dy int) { state.Redraw <- struct{}{} state.FovRecompute <- struct{}{} -} \ No newline at end of file +} diff --git a/ui/mainwindow/mainwindow.go b/ui/mainwindow/mainwindow.go index 1d7147a..12c5ecd 100644 --- a/ui/mainwindow/mainwindow.go +++ b/ui/mainwindow/mainwindow.go @@ -8,6 +8,7 @@ import ( ) type MainWindow struct { + *types.Rect ctx util.ClientCtx layers map[string]types.Renderable } @@ -52,6 +53,7 @@ func (mw *MainWindow) Open() { config.FontSize, ), ) + mw.Rect = types.NewRect(0,0, config.MainWindowSizeX, config.MainWindowSizeY) } func (mw *MainWindow) Close() { diff --git a/ui/mainwindow/viewport.go b/ui/mainwindow/viewport.go index e43ad92..5920e20 100644 --- a/ui/mainwindow/viewport.go +++ b/ui/mainwindow/viewport.go @@ -105,7 +105,7 @@ func (vp *ViewPort) Render(state *gamestate.GameState) { vp.Fov.ComputeFov(state.Level, playerCoords, vp.TorchRadius) } - vp.layer.ClearArea(0, 7, 40, 1) + vp.layer.ClearArea(0, 7, 20, 1) vp.layer.Print(0,7, fmt.Sprintf("pcds: %v", playerCoords))