2024-02-06 15:26:20 +01:00
|
|
|
package game
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-06 19:02:25 +01:00
|
|
|
"fmt"
|
2024-02-06 15:26:20 +01:00
|
|
|
"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
|
2024-02-06 19:02:25 +01:00
|
|
|
Scenes map[int]Scene
|
2024-02-06 15:26:20 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-06 19:02:25 +01:00
|
|
|
func NewGame(width, height, startlevel int, startscene int) *Game {
|
2024-02-06 15:26:20 +01:00
|
|
|
world := ecs.NewWorld()
|
|
|
|
|
|
|
|
|
|
game := &Game{
|
|
|
|
|
Bounds: image.Rectangle{},
|
|
|
|
|
CurrentLevel: startlevel,
|
|
|
|
|
World: &world,
|
|
|
|
|
ScreenWidth: width,
|
|
|
|
|
ScreenHeight: height,
|
2024-02-06 19:02:25 +01:00
|
|
|
Scenes: map[int]Scene{},
|
2024-02-06 15:26:20 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-06 19:02:25 +01:00
|
|
|
game.Scenes[Play] = NewLevelScene(game, startlevel)
|
|
|
|
|
|
|
|
|
|
fmt.Println(game.World.Stats().String())
|
2024-02-06 15:26:20 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|