66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package game
|
|
|
|
import (
|
|
"mountain/internal/scenes"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
// SceneType represents the different scenes in the game.
|
|
type SceneType int
|
|
|
|
const (
|
|
SceneMainMenu SceneType = iota
|
|
ScenePlay
|
|
)
|
|
|
|
// Scene interface defines standard methods a state/scene must have.
|
|
type Scene interface {
|
|
Update() error
|
|
Draw(screen *ebiten.Image)
|
|
}
|
|
|
|
// Game implements ebiten.Game interface.
|
|
type Game struct {
|
|
currentScene Scene
|
|
currentSceneType SceneType
|
|
}
|
|
|
|
func NewGame() *Game {
|
|
g := &Game{}
|
|
g.ChangeScene(SceneMainMenu)
|
|
return g
|
|
}
|
|
|
|
func (g *Game) Update() error {
|
|
// Handle global input for scene switching maybe?
|
|
if g.currentSceneType == SceneMainMenu && ebiten.IsKeyPressed(ebiten.KeyEnter) {
|
|
g.ChangeScene(ScenePlay)
|
|
}
|
|
|
|
if g.currentScene != nil {
|
|
return g.currentScene.Update()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (g *Game) Draw(screen *ebiten.Image) {
|
|
if g.currentScene != nil {
|
|
g.currentScene.Draw(screen)
|
|
}
|
|
}
|
|
|
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
|
|
return 800, 600
|
|
}
|
|
|
|
func (g *Game) ChangeScene(s SceneType) {
|
|
g.currentSceneType = s
|
|
switch s {
|
|
case SceneMainMenu:
|
|
g.currentScene = scenes.NewMenuScene()
|
|
case ScenePlay:
|
|
g.currentScene = scenes.NewPlayScene()
|
|
}
|
|
}
|