59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package game
|
|
|
|
import (
|
|
"fmt"
|
|
"openquell/assets"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type LevelScene struct {
|
|
Game *Game
|
|
CurrentLevel int
|
|
Levels []*Level
|
|
Next int
|
|
Whoami int
|
|
UseCache bool
|
|
}
|
|
|
|
// Implements the actual playing Scene
|
|
func NewLevelScene(game *Game, startlevel int) Scene {
|
|
scene := &LevelScene{CurrentLevel: startlevel, Whoami: Play, Game: game}
|
|
|
|
scene.GenerateLevels(game)
|
|
scene.Levels[scene.CurrentLevel].SetupGrid(game)
|
|
|
|
return scene
|
|
}
|
|
|
|
func (scene *LevelScene) GenerateLevels(game *Game) {
|
|
for _, level := range assets.Levels {
|
|
scene.Levels = append(scene.Levels, NewLevel(game, 32, &level))
|
|
}
|
|
}
|
|
|
|
// Interface methods
|
|
func (scene *LevelScene) SetNext() int {
|
|
if scene.Whoami != scene.Next {
|
|
return scene.Next
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
func (scene *LevelScene) Update() error {
|
|
if scene.CurrentLevel != scene.Game.Observer.CurrentLevel {
|
|
fmt.Printf("current: %d, next: %d\n", scene.CurrentLevel, scene.Game.Observer.CurrentLevel)
|
|
scene.CurrentLevel = scene.Game.Observer.CurrentLevel
|
|
scene.Levels[scene.CurrentLevel].SetupGrid(scene.Game)
|
|
}
|
|
|
|
scene.Levels[scene.CurrentLevel].Update()
|
|
return nil
|
|
}
|
|
|
|
func (scene *LevelScene) Draw(screen *ebiten.Image) {
|
|
screen.Clear()
|
|
scene.Levels[scene.CurrentLevel].Draw(screen)
|
|
}
|