last_light/game/game.go

52 lines
693 B
Go
Raw Normal View History

2024-04-24 17:11:33 +03:00
package game
import (
2024-05-06 20:43:35 +03:00
"mvvasilev/last_light/engine"
2024-04-24 17:11:33 +03:00
"mvvasilev/last_light/game/state"
"github.com/gdamore/tcell/v2"
)
type Game struct {
state state.GameState
quitGame bool
2024-04-24 17:11:33 +03:00
}
func CreateGame() *Game {
game := new(Game)
game.state = state.NewMainMenuState()
return game
}
func (g *Game) Input(ev *tcell.EventKey) {
if ev.Key() == tcell.KeyCtrlC {
g.quitGame = true
}
2024-04-24 17:11:33 +03:00
g.state.OnInput(ev)
}
func (g *Game) Tick(dt int64) bool {
if g.quitGame {
return false
}
2024-04-24 17:11:33 +03:00
s := g.state.OnTick(dt)
switch s.(type) {
case *state.QuitState:
return false
}
g.state = s
return true
}
2024-05-06 20:43:35 +03:00
func (g *Game) CollectDrawables() []engine.Drawable {
return g.state.CollectDrawables()
2024-04-24 17:11:33 +03:00
}