last_light/game/game.go

42 lines
556 B
Go
Raw Normal View History

2024-04-24 17:11:33 +03:00
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)
}