-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.go
More file actions
45 lines (36 loc) · 858 Bytes
/
game.go
File metadata and controls
45 lines (36 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package engine
import (
"io/fs"
"engine/vec2"
"github.com/hajimehoshi/ebiten/v2"
)
type Game struct {
Scene *Scene
ScreenSize vec2.T
Fullscreen bool
Title string
AssetLoader *AssetLoader
}
func NewGame(title string, assets fs.FS) *Game {
return &Game{
Scene: NewScene(),
ScreenSize: vec2.T{X: 640, Y: 480},
Fullscreen: false,
Title: title,
AssetLoader: NewAssetLoader(assets),
}
}
func (g *Game) Run() error {
ebiten.SetWindowTitle(g.Title)
ebiten.SetWindowSize(int(g.ScreenSize.X), int(g.ScreenSize.Y))
return ebiten.RunGame(g)
}
func (g *Game) Update() error {
return g.Scene.Update()
}
func (g *Game) Draw(screen *ebiten.Image) {
g.Scene.Draw(screen)
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return int(g.ScreenSize.X), int(g.ScreenSize.Y)
}