-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
70 lines (54 loc) · 1.14 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
64
65
66
67
68
69
70
package main
import (
"log"
"math/rand"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/m110/airplanes/assets"
"github.com/m110/airplanes/scene"
"github.com/m110/airplanes/system"
)
var (
screenWidth = 480
screenHeight = 640
)
type Scene interface {
Update()
Draw(screen *ebiten.Image)
}
type Game struct {
scene Scene
}
func NewGame() *Game {
assets.MustLoadAssets()
g := &Game{}
g.switchToTitle()
return g
}
func (g *Game) switchToTitle() {
g.scene = scene.NewTitle(screenWidth, screenHeight, g.switchToAirbase)
}
func (g *Game) switchToAirbase() {
g.scene = scene.NewAirbase(g.switchToGame, g.switchToTitle)
}
func (g *Game) switchToGame(players []system.ChosenPlayer) {
g.scene = scene.NewGame(players, screenWidth, screenHeight)
}
func (g *Game) Update() error {
g.scene.Update()
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
g.scene.Draw(screen)
}
func (g *Game) Layout(width, height int) (int, int) {
return width, height
}
func main() {
ebiten.SetWindowSize(screenWidth, screenHeight)
rand.Seed(time.Now().UTC().UnixNano())
err := ebiten.RunGame(NewGame())
if err != nil {
log.Fatal(err)
}
}