animation handling, screens, vp changes

This commit is contained in:
2019-11-01 17:51:55 +03:00
parent c6c6b6254d
commit 1ac6ae4665
16 changed files with 297 additions and 110 deletions

View File

@ -67,7 +67,7 @@ func TestPrecompShade(t *testing.T) {
if playerCoords.X == x && playerCoords.Y == y {
return "@"
}
result := level.GetTileByXY(x, y).Char
result := level.GetTileByXY(x, y).Glyph.GetGlyph()
if !level.GetTileByXY(x, y).Visible {
result = "?"
}

View File

@ -17,7 +17,7 @@ type Tile struct {
}
func (t *Tile) GetChar() string {
return t.Char
return t.Glyph.GetGlyph()
}
func (t *Tile) GetRawColor() uint32 {
@ -45,7 +45,7 @@ func NewWall() *Tile {
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: "#",
Glyph: &PlainGlyphHolder{"#"},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 130, 110, 150},
Bg: &PlainColorHolder{255, 172, 170, 173},
@ -65,7 +65,7 @@ func NewFloor() *Tile {
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: ".",
Glyph: &PlainGlyphHolder{"."},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &PlainColorHolder{255, 19, 19, 70},
@ -88,14 +88,14 @@ func NewWaterTile() *Tile {
Colordance: true,
Appearance: &Appearance{
Char: " ",
Glyph: &PlainGlyphHolder{" "},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &DanceColorHolder{
255,
SingleColorRing(19),
FillColorRing(19, 0, 15, 2),
FillColorRing(70, 120, 220, 12),
FillColorRing(127, 120, 176, 12),
},
DarkFg: &PlainColorHolder{255, 30, 20, 50},
DarkBg: &PlainColorHolder{255, 7, 7, 30},
@ -115,7 +115,7 @@ func NewDeepWaterTile() *Tile {
MustDraw: true, //fixme debug
Colordance: true,
Appearance: &Appearance{
Char: " ",
Glyph: &PlainGlyphHolder{" "},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &DanceColorHolder{

View File

@ -1,25 +0,0 @@
package mob
import (
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
)
type Mob struct {
*gamemap.Appearance
*types.Coords
BlocksPass bool
}
func (m *Mob) Walk(dx, dy int) {
}
func (m *Mob) Render() {
}
func (m *Mob) MoveToCoords(c types.Coords) {
}

View File

@ -0,0 +1,11 @@
package screens
type CharacterScreen struct {
}
func (ts *CharacterScreen) UseEcs() bool {return false}
func (ts *CharacterScreen) Enter() {}
func (ts *CharacterScreen) HandleInput(input string) {}
func (ts *CharacterScreen) Exit() {}
func (ts *CharacterScreen) Render() {}

60
engine/screens/game.go Normal file
View File

@ -0,0 +1,60 @@
package screens
import (
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
)
type GameScreen struct {
mw *mainwindow.MainWindow
state *types.GameState
vp *mainwindow.ViewPort
}
func NewGameScreen(mw *mainwindow.MainWindow, state *types.GameState, viewPort *mainwindow.ViewPort) *GameScreen {
return &GameScreen{mw: mw, state: state, vp: viewPort}
}
func (ts *GameScreen) UseEcs() bool { return true }
func (ts *GameScreen) Enter() {}
func (ts *GameScreen) HandleInput(input string) {
//ts.state.Do(func(){
switch input {
case "Up", "k", "8":
ts.state.Player.Walk(0, -1)
break
case "Down", "j", "2":
ts.state.Player.Walk(0, 1)
break
case "Left", "h", "4":
ts.state.Player.Walk(-1, 0)
break
case "Right", "l", "6":
ts.state.Player.Walk(1, 0)
break
case "y", "7":
ts.state.Player.Walk(-1, -1)
break
case "u", "9":
ts.state.Player.Walk(1, -1)
break
case "b", "1":
ts.state.Player.Walk(-1, 1)
break
case "n", "3":
ts.state.Player.Walk(-1, 3)
break
default:
ts.mw.GetLayer("base").ClearArea(0, 3, 40, 1)
ts.mw.GetLayer("base").Print(1, 3, "Key: "+input)
ts.mw.GetLayer("base").Print(1, 6, "█")
}
//})
}
func (ts *GameScreen) Exit() {}
func (ts *GameScreen) Render() {
ts.vp.Render(ts.state)
}

View File

@ -0,0 +1,11 @@
package screens
type InventoryScreen struct {
}
func (ts *InventoryScreen) UseEcs() bool {return true}
func (ts *InventoryScreen) Enter() {}
func (ts *InventoryScreen) HandleInput(input string) {}
func (ts *InventoryScreen) Exit() {}
func (ts *InventoryScreen) Render() {}

11
engine/screens/target.go Normal file
View File

@ -0,0 +1,11 @@
package screens
type TargetScreen struct {
}
func (ts *TargetScreen) UseEcs() bool {return true}
func (ts *TargetScreen) Enter() {}
func (ts *TargetScreen) HandleInput(input string) {}
func (ts *TargetScreen) Exit() {}
func (ts *TargetScreen) Render() {}

11
engine/screens/title.go Normal file
View File

@ -0,0 +1,11 @@
package screens
type TitleScreen struct {
}
func (ts *TitleScreen) UseEcs() bool {return false}
func (ts *TitleScreen) Enter() {}
func (ts *TitleScreen) HandleInput(input string) {}
func (ts *TitleScreen) Exit() {}
func (ts *TitleScreen) Render() {}

View File

@ -60,8 +60,21 @@ type TileColorSet struct {
DarkBg ColorHolder
}
type GlyphHolder interface {
GetGlyph() string
}
type PlainGlyphHolder struct {
Glyph string
}
func (pch *PlainGlyphHolder) GetGlyph() string {
return pch.Glyph
}
type Appearance struct {
Char string `json:"char"`
Glyph GlyphHolder `json:"char"`
ColorSet *TileColorSet `json:"colorSet"`
}
@ -80,7 +93,7 @@ func FillColorRing(colorValue uint8, minGlow, maxGlow, step int) *cdeque {
color = crng.Range(1, step) + color
}
color = crng.Range(0, step+minGlow)
q = append(q, uint8(color))
q = append(q, colorValue)
//for uint8(color) < uint8(colorValue) {
// q = append(q, uint8(color))
// color = crng.Range(1, step+minGlow)

View File

@ -7,6 +7,7 @@ type GameState struct {
RawInput chan int
FovRecompute chan struct{}
Redraw chan struct{}
Player *Player
}
// do runs f on the main thread.

19
engine/types/mob.go Normal file
View File

@ -0,0 +1,19 @@
package types
type Mob struct {
*Appearance
Coords
BlocksPass bool
}
func (m *Mob) Walk(dx, dy int) {
}
func (m *Mob) Render() {
}
func (m *Mob) MoveToCoords(c Coords) {
}

View File

@ -1,5 +1,5 @@
package mob
package types
type Player struct {
*Mob
Mob
}

88
engine/types/screen.go Normal file
View File

@ -0,0 +1,88 @@
package types
import (
"lab.zaar.be/thefish/alchemyst-go/util"
)
type Screen interface {
Enter()
Exit()
Render()
HandleInput(input string)
UseEcs() bool
}
type ScreenManager struct {
ctx util.ClientCtx
Screens map[string]Screen
CurrentScreen Screen
PreviousScreen Screen
}
// NewScreenManager is a convenience/constructor method to properly initialize a new ScreenManager
func NewScreenManager(ctx util.ClientCtx) *ScreenManager {
manager := ScreenManager{
ctx:ctx,
Screens: make(map[string]Screen),
CurrentScreen: nil,
}
return &manager
}
func (sm *ScreenManager) AddScreen(screenName string, screen Screen) {
// Check to see if a screen with the given screenName has already been added
if _, ok := sm.Screens[screenName]; !ok {
// A screen with the given name does not yet exist on the ScreenManager, go ahead and add it
sm.Screens[screenName] = screen
} else {
sm.ctx.Logger().Warn().Msgf("A screen with name %v was already added to the ScreenManager %v!", screenName, sm)
}
}
// RemoveScreen will remove a screen from the ScreenManager. This can be useful when a temporary screen needs to be
// created, as it can be quickly added (rather than registering at game creation), and then removed when it is no
// longer needed
func (sm *ScreenManager) RemoveScreen(screenName string, screen Screen) {
// Check if the given screenName exists in the ScreenManager
if _, ok := sm.Screens[screenName]; ok {
delete(sm.Screens, screenName)
} else {
// A screen with the given name does not exist
sm.ctx.Logger().Warn().Msgf("A screen with name %v was not found on ScreenManager %v!", screenName, sm)
}
}
// SetScreen will set the current screen property of the screen manager to the provided screen
func (sm *ScreenManager) SetScreen(screen Screen) {
// Call the exit function of the currentScreen, and set the currentScreen as the previousScreen
// Only do this if there is a currentScreen
if sm.CurrentScreen != nil {
sm.CurrentScreen.Exit()
sm.PreviousScreen = sm.CurrentScreen
}
// Set the provided screen as the currentScreen, and call the enter() function of the new currentScreen
sm.CurrentScreen = screen
sm.CurrentScreen.Enter()
}
// SetScreenByName takes a string representing the screen desired to navigate to. It will then transition the
// ScreenManager to the specified screen, if one is found.
func (sm *ScreenManager) SetScreenByName(screenName string) {
// Check if the given screenName exists in the ScreenManager
if _, ok := sm.Screens[screenName]; ok {
// Call the exit function of the currentScreen, and set the currentScreen as the previousScreen
// Only do this if there is a currentScreen
if sm.CurrentScreen != nil {
sm.CurrentScreen.Exit()
sm.PreviousScreen = sm.CurrentScreen
}
// Set the provided screen as the currentScreen, and call the enter() function of the new currentScreen
sm.CurrentScreen = sm.Screens[screenName]
sm.CurrentScreen.Enter()
} else {
// A screen with the given name does not exist
sm.ctx.Logger().Warn().Msgf("A screen with name %v was not found on ScreenManager %v!", screenName, sm)
}
}