dev menu, buffs

This commit is contained in:
anton.gurov 2019-11-12 15:57:20 +03:00
parent 7837051e80
commit 6197e3be8e
9 changed files with 94 additions and 76 deletions

View File

@ -9,6 +9,29 @@
"default_item_legend": {}, "default_item_legend": {},
"prefabs": [ "prefabs": [
{"name": "test_room_3",
"size":{"x":20, "y":17},
"body": [
"##########+#########",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#........#.........#",
"#.....#............#",
"#...#.....#........#",
"+.....#..#.........+",
"#......#...........#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"##########+#########"
]
},
{"name": "test_room_2", {"name": "test_room_2",
"tile_legend": { "tile_legend": {
"D": "decorated_wall" "D": "decorated_wall"
@ -56,30 +79,6 @@
"???DDDD#.#DDDD??", "???DDDD#.#DDDD??",
"???????#+#??????" "???????#+#??????"
] ]
},
{"name": "test_room_3",
"size":{"x":20, "y":17},
"body": [
"##########+#########",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#........#.........#",
"#.....#............#",
"#...#.....#........#",
"+.....#..#.........+",
"#......#...........#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"##########+#########"
]
} }
] ]
} }

View File

@ -150,6 +150,7 @@ func main() {
screenMgr.AddScreen("devmenu", screens.NewDevmenuScreen( screenMgr.AddScreen("devmenu", screens.NewDevmenuScreen(
mw, mw,
controller,
screenMgr, screenMgr,
&State, &State,
types.NewCenteredRect(mw.Rect, 70, 25), types.NewCenteredRect(mw.Rect, 70, 25),

9
effects/buffs.go Normal file
View File

@ -0,0 +1,9 @@
package effects
const BuffPassWall = "pass_wall"
type PassWall struct {}
func (PassWall) Type() string {
return BuffPassWall
}

View File

@ -78,7 +78,7 @@ Pre-Computed Visiblity Trees on RogueBasin
Adam Milazzo's FOV Method Roundup where a similar method described as 'permissive' is detailed Adam Milazzo's FOV Method Roundup where a similar method described as 'permissive' is detailed
*/ */
const MIN_LIT_TO_BE_VISIBLE = 0 const MIN_LIT_TO_BE_VISIBLE = 3
const MIN_WALL_LIT_TO_BE_VISIBLE = 4 const MIN_WALL_LIT_TO_BE_VISIBLE = 4
var errNotFoundCell = errors.New("Cell not found") var errNotFoundCell = errors.New("Cell not found")
@ -264,8 +264,8 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co
for _, cell := range ps.CellList { for _, cell := range ps.CellList {
//fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit) //fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit)
cs, err := ps.toLevelCoords(level, initCoords, cell.Coords) cs, err := ps.toLevelCoords(level, initCoords, cell.Coords)
//if cell.lit > 0 && cell.lit > MIN_LIT_TO_BE_VISIBLE { if cell.lit > 0 && cell.lit > MIN_LIT_TO_BE_VISIBLE {
if cell.lit > 0 && cell.lit / (ps.MaxTorchRadius - int(cell.distance -1)) > MIN_LIT_TO_BE_VISIBLE { //if cell.lit > 0 && cell.lit / (ps.MaxTorchRadius - int(cell.distance - 0.4) - 1) > MIN_LIT_TO_BE_VISIBLE {
if err != nil { if err != nil {
continue continue
} }

View File

@ -39,7 +39,7 @@ func NewWall() *Tile {
return &Tile{ return &Tile{
Name: "Wall", Name: "Wall",
Description: "A dull rock wall", Description: "A dull rock wall",
BlocksPass: false, BlocksPass: true,
BlocksSight: true, BlocksSight: true,
Explored: false, Explored: false,
MustDraw: false, MustDraw: false,
@ -57,8 +57,8 @@ func NewWall() *Tile {
func NewDecoratedWall() *Tile { func NewDecoratedWall() *Tile {
return &Tile{ return &Tile{
Name: "Wall", Name: "Decorated Wall",
Description: "A dull rock wall", Description: "A rock wall covered with paintings",
BlocksPass: true, BlocksPass: true,
BlocksSight: true, BlocksSight: true,
Explored: false, Explored: false,

View File

@ -3,6 +3,7 @@ package movement
import ( import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs" "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap" "lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/mob" "lab.zaar.be/thefish/alchemyst-go/engine/mob"
"lab.zaar.be/thefish/alchemyst-go/engine/types" "lab.zaar.be/thefish/alchemyst-go/engine/types"
) )
@ -45,3 +46,23 @@ func (mov Moveable) IsBlocked(c types.Coords) bool {
} }
return false return false
} }
func Walk(entity ecs.Entity, state *gamestate.GameState, dx, dy int) {
controller := state.Controller
coords := controller.GetComponent(state.Player, ecs.CoordsComponent).(types.Coords)
newCoords := types.Coords{coords.X + dx, coords.Y + dy}
if !state.Level.InBounds(newCoords) {
return
}
movable := controller.GetComponent(entity, ecs.MoveableComponent)
if movable == nil {
return
}
if !movable.(Moveable).IsBlocked(newCoords) ||
controller.GetComponent(entity, "pass_wall") != nil {
controller.UpdateComponent(state.Player, ecs.CoordsComponent, newCoords)
}
state.Redraw <- struct{}{}
state.FovRecompute <- struct{}{}
}

View File

@ -2,6 +2,8 @@ package screens
import ( import (
"fmt" "fmt"
"lab.zaar.be/thefish/alchemyst-go/effects"
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/gamestate" "lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/types" "lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow" "lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
@ -9,23 +11,24 @@ import (
) )
type DevmenuScreen struct { type DevmenuScreen struct {
mw *mainwindow.MainWindow mw *mainwindow.MainWindow
scm *types.ScreenManager controller *ecs.Controller
state *gamestate.GameState scm *types.ScreenManager
state *gamestate.GameState
types.Rect types.Rect
renderParent bool renderParent bool
bgColor string bgColor string
fgColor string fgColor string
} }
func NewDevmenuScreen(mw *mainwindow.MainWindow, scm *types.ScreenManager, state *gamestate.GameState, rect types.Rect, renderParent bool) *DevmenuScreen { func NewDevmenuScreen(mw *mainwindow.MainWindow, controller *ecs.Controller, scm *types.ScreenManager, state *gamestate.GameState, rect types.Rect, renderParent bool) *DevmenuScreen {
return &DevmenuScreen{ return &DevmenuScreen{
mw: mw, mw: mw,
scm: scm, controller: controller,
state: state, scm: scm,
state: state,
Rect: rect, Rect: rect,
renderParent: renderParent, renderParent: renderParent,
@ -65,6 +68,12 @@ func (devm *DevmenuScreen) HandleInput(input string) {
fmt.Printf("making everything visible!") fmt.Printf("making everything visible!")
devm.scm.SetScreen(devm.scm.PreviousScreen) devm.scm.SetScreen(devm.scm.PreviousScreen)
break break
case "p":
if devm.controller.HasComponent(devm.state.Player, effects.BuffPassWall) {
devm.controller.RemoveComponent(devm.state.Player, effects.BuffPassWall)
} else {
devm.controller.AddComponent(devm.state.Player, effects.PassWall{})
}
case "Escape": case "Escape":
fallthrough fallthrough
case "Space": case "Space":
@ -72,7 +81,7 @@ func (devm *DevmenuScreen) HandleInput(input string) {
break break
} }
} }
func (devm *DevmenuScreen) Exit() { func (devm *DevmenuScreen) Exit() {
if devm.renderParent { if devm.renderParent {
devm.scm.PreviousScreen.Render() devm.scm.PreviousScreen.Render()
} }
@ -95,10 +104,12 @@ func (devm *DevmenuScreen) Render() {
"Dev Menu:", "Dev Menu:",
"[color=green]v[/color] - set all tiles visible", "[color=green]v[/color] - set all tiles visible",
"[color=green]i[/color] - set all tiles invisible", "[color=green]i[/color] - set all tiles invisible",
fmt.Sprintf("[color=green]p[/color] - toggle passwall: %v",
devm.controller.HasComponent(devm.state.Player, effects.BuffPassWall),
),
}, "\n"), }, "\n"),
1, 1,
) )
menuLayer.Print(devm.X+2, devm.Y+devm.H-1, "[color=green]Space[/color] to close") menuLayer.Print(devm.X+2, devm.Y+devm.H-1, "[color=green]Space[/color] to close")
} }

View File

@ -39,28 +39,28 @@ func (ts *GameScreen) HandleInput(input string) {
//ts.state.Do(func(){ //ts.state.Do(func(){
switch input { switch input {
case "Up", "k", "KP_8": case "Up", "k", "KP_8":
ts.walk(ts.state, 0, -1) movement.Walk(ts.state.Player, ts.state, 0, -1)
break break
case "Down", "j", "KP_2": case "Down", "j", "KP_2":
ts.walk(ts.state, 0, 1) movement.Walk(ts.state.Player, ts.state, 0, 1)
break break
case "Left", "h", "KP_4": case "Left", "h", "KP_4":
ts.walk(ts.state, -1, 0) movement.Walk(ts.state.Player, ts.state, -1, 0)
break break
case "Right", "l", "KP_6": case "Right", "l", "KP_6":
ts.walk(ts.state, 1, 0) movement.Walk(ts.state.Player, ts.state, 1, 0)
break break
case "y", "KP_7": case "y", "KP_7":
ts.walk(ts.state, -1, -1) movement.Walk(ts.state.Player, ts.state, -1, -1)
break break
case "u", "KP_9": case "u", "KP_9":
ts.walk(ts.state, 1, -1) movement.Walk(ts.state.Player, ts.state, 1, -1)
break break
case "b", "KP_1": case "b", "KP_1":
ts.walk(ts.state, -1, 1) movement.Walk(ts.state.Player, ts.state, -1, 1)
break break
case "n", "KP_3": case "n", "KP_3":
ts.walk(ts.state, 1, 1) movement.Walk(ts.state.Player, ts.state, 1, 1)
break break
case "Shift+/": case "Shift+/":
ts.scm.SetScreenByName("help") ts.scm.SetScreenByName("help")
@ -76,7 +76,6 @@ func (ts *GameScreen) HandleInput(input string) {
ts.mw.GetLayer("base").ClearArea(0, 3, 40, 1) ts.mw.GetLayer("base").ClearArea(0, 3, 40, 1)
ts.mw.GetLayer("base").Print(1, 3, "Key: "+input) ts.mw.GetLayer("base").Print(1, 3, "Key: "+input)
ts.mw.GetLayer("base").Print(1, 6, "█") ts.mw.GetLayer("base").Print(1, 6, "█")
} }
//}) //})
} }
@ -85,16 +84,4 @@ func (ts *GameScreen) Render() {
ts.vp.Render(ts.state) ts.vp.Render(ts.state)
} }
func (ts *GameScreen) walk(state *gamestate.GameState, dx, dy int) {
controller := state.Controller
coords := controller.GetComponent(state.Player, ecs.CoordsComponent).(types.Coords)
newCoords := types.Coords{coords.X + dx, coords.Y + dy}
movable := controller.GetComponent(state.Player, ecs.MoveableComponent).(movement.Moveable)
if !movable.IsBlocked(newCoords) {
controller.UpdateComponent(state.Player, ecs.CoordsComponent, newCoords)
}
state.Redraw <- struct{}{}
state.FovRecompute <- struct{}{}
}

View File

@ -35,22 +35,12 @@ func (ts *TitleScreen) Render() {
} }
var logo = ` var logo = `
.ddxo. .c c xlx Precomputed shade test
.kd. .0o:O, c0uO'
xc 0; x: ko ,,
;l Y; c, .Yct;
.. .. .......
:o: :k; .cxloOo x0. kO .olldk; do .;k lO. dO 'xllxk; ocokk:dl
.lKO, .kl 'dl c l0l..;dK lkx..;d: dOx .cOx ,0o c0 kk. .Y .Oo
.l0.k0. .0l lK. l0oxxxOK OK;xxx kKOklOkx ,kO;'do. ;xO: .Oo
:OoooxO .Ol ;Xc , cK' dK xX. , Ox YY xx ,O0. . .oKx. .0o
;k. .Ox Ok..'.,l ;Kk:;dk cKl lX: dKc,;oc kx kk OO dKl;lk: .0O
l; ,o .kK0KKK; :Ok; c; l: .oxc. x: Ol xl .dk: .o
` `
var menu = ` var menu = `
Alchemyst (c) 2011-2014 thefish <thefish@zaar.be> (c) 2019 thefish <thefish@zaar.be>