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

@ -2,6 +2,8 @@ package screens
import (
"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"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
)
@ -21,28 +23,28 @@ func (ts *GameScreen) HandleInput(input string) {
//ts.state.Do(func(){
switch input {
case "Up", "k", "8":
ts.state.Player.Walk(ts.state.Level, 0, -1)
ts.walk(ts.state, 0, -1)
break
case "Down", "j", "2":
ts.state.Player.Walk(ts.state.Level,0, 1)
ts.walk(ts.state,0, 1)
break
case "Left", "h", "4":
ts.state.Player.Walk(ts.state.Level,-1, 0)
ts.walk(ts.state,-1, 0)
break
case "Right", "l", "6":
ts.state.Player.Walk(ts.state.Level,1, 0)
ts.walk(ts.state,1, 0)
break
case "y", "7":
ts.state.Player.Walk(ts.state.Level,-1, -1)
ts.walk(ts.state,-1, -1)
break
case "u", "9":
ts.state.Player.Walk(ts.state.Level,1, -1)
ts.walk(ts.state,1, -1)
break
case "b", "1":
ts.state.Player.Walk(ts.state.Level,-1, 1)
ts.walk(ts.state,-1, 1)
break
case "n", "3":
ts.state.Player.Walk(ts.state.Level,1, 1)
ts.walk(ts.state,1, 1)
break
default:
ts.mw.GetLayer("base").ClearArea(0, 3, 40, 1)
@ -56,3 +58,18 @@ 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)
newCoords := types.Coords{coords.X + dx, coords.Y + dy}
movable := controller.GetComponent(state.Player, movement.Moveable{}.TypeOf()).(movement.Moveable)
if !movable.IsBlocked(newCoords) {
controller.UpdateComponent(state.Player, types.Coords{}.TypeOf(), newCoords)
}
state.Redraw <- struct{}{}
state.FovRecompute <- struct{}{}
}