openquell/game/game.go
2024-02-06 15:26:20 +01:00

52 lines
968 B
Go

package game
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
"github.com/mlange-42/arche/ecs"
)
type Game struct {
World *ecs.World
Bounds image.Rectangle
ScreenWidth, ScreenHeight int
CurrentLevel int
Scenes []Scene
}
func NewGame(width, height, startlevel int) *Game {
world := ecs.NewWorld()
game := &Game{
Bounds: image.Rectangle{},
CurrentLevel: startlevel,
World: &world,
ScreenWidth: width,
ScreenHeight: height,
}
levelscene := NewLevelScene(game, startlevel)
game.Scenes = append(game.Scenes, levelscene)
return game
}
func (game *Game) Update() error {
for _, scene := range game.Scenes {
scene.Update()
}
return nil
}
func (game *Game) Draw(screen *ebiten.Image) {
for _, scene := range game.Scenes {
scene.Draw(screen)
}
}
func (g *Game) Layout(newWidth, newHeight int) (int, int) {
return g.ScreenWidth, g.ScreenHeight
}