mirror of
https://github.com/mvvasilev/last_light.git
synced 2025-04-19 12:49:52 +03:00
42 lines
556 B
Go
42 lines
556 B
Go
|
package game
|
||
|
|
||
|
import (
|
||
|
"mvvasilev/last_light/game/state"
|
||
|
|
||
|
"github.com/gdamore/tcell/v2"
|
||
|
"github.com/gdamore/tcell/v2/views"
|
||
|
)
|
||
|
|
||
|
type Game struct {
|
||
|
state state.GameState
|
||
|
}
|
||
|
|
||
|
func CreateGame() *Game {
|
||
|
game := new(Game)
|
||
|
|
||
|
game.state = state.NewMainMenuState()
|
||
|
|
||
|
return game
|
||
|
}
|
||
|
|
||
|
func (g *Game) Input(ev *tcell.EventKey) {
|
||
|
g.state.OnInput(ev)
|
||
|
}
|
||
|
|
||
|
func (g *Game) Tick(dt int64) bool {
|
||
|
s := g.state.OnTick(dt)
|
||
|
|
||
|
switch s.(type) {
|
||
|
case *state.QuitState:
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
g.state = s
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
func (g *Game) Draw(v views.View) {
|
||
|
g.state.OnDraw(v)
|
||
|
}
|