/
main.go
63 lines (50 loc) · 1.08 KB
/
main.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
_ "embed"
"image"
"log"
"math/rand"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/yohamta/donburi/examples/platformer/config"
"github.com/yohamta/donburi/examples/platformer/fonts"
"github.com/yohamta/donburi/examples/platformer/scenes"
)
//go:embed assets/fonts/excel.ttf
var excelFont []byte
type Scene interface {
Update()
Draw(screen *ebiten.Image)
}
type Game struct {
bounds image.Rectangle
scene Scene
}
func NewGame() *Game {
fonts.LoadFont(fonts.Excel, excelFont)
g := &Game{
bounds: image.Rectangle{},
scene: &scenes.PlatformerScene{},
}
return g
}
func (g *Game) Update() error {
g.scene.Update()
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
screen.Clear()
g.scene.Draw(screen)
}
func (g *Game) Layout(width, height int) (int, int) {
g.bounds = image.Rect(0, 0, width, height)
return width, height
}
func main() {
ebiten.SetWindowSize(config.C.Width, config.C.Height)
ebiten.SetWindowResizable(false)
rand.Seed(time.Now().UTC().UnixNano())
if err := ebiten.RunGame(NewGame()); err != nil {
log.Fatal(err)
}
}