55 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package game
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"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                    map[int]Scene
 | |
| }
 | |
| 
 | |
| func NewGame(width, height, startlevel int, startscene int) *Game {
 | |
| 	world := ecs.NewWorld()
 | |
| 
 | |
| 	game := &Game{
 | |
| 		Bounds:       image.Rectangle{},
 | |
| 		CurrentLevel: startlevel,
 | |
| 		World:        &world,
 | |
| 		ScreenWidth:  width,
 | |
| 		ScreenHeight: height,
 | |
| 		Scenes:       map[int]Scene{},
 | |
| 	}
 | |
| 
 | |
| 	game.Scenes[Play] = NewLevelScene(game, startlevel)
 | |
| 
 | |
| 	fmt.Println(game.World.Stats().String())
 | |
| 
 | |
| 	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
 | |
| }
 |