-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·81 lines (65 loc) · 1.62 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
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"embed"
"errors"
_ "image/png"
"log"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
camera "github.com/tducasse/ebiten-camera"
collisions "github.com/tducasse/ebiten-collisions"
manager "github.com/tducasse/ebiten-manager"
"github.com/tducasse/ebiten-template/scenes"
)
const (
screenWidth = 256
screenHeight = 144
windowScale = 4
)
const (
worldWidth = 512
worldHeight = 512
)
var errQuit = errors.New("quit")
type Game struct{}
var m *manager.Manager
var g *Game
//go:embed assets/*
var assetsFolder embed.FS
func (game *Game) Update() error {
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
return errQuit
}
if ebiten.IsKeyPressed(ebiten.KeyAlt) && inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
toggleFullscreen()
}
return m.Update()
}
func (game *Game) Draw(screen *ebiten.Image) {
m.Draw(screen)
}
func (game *Game) Layout(w, h int) (int, int) {
return screenWidth, screenHeight
}
func toggleFullscreen() {
ebiten.SetFullscreen(!ebiten.IsFullscreen())
}
func main() {
m = manager.MakeManager(map[string]*manager.Scene{
"menu": scenes.MenuScene,
"game": scenes.GameScene,
}, "menu")
g = &Game{}
scenes.Context = &scenes.ContextType{
Camera: camera.Init(screenWidth, screenHeight),
World: ebiten.NewImage(worldWidth, worldHeight),
CollisionWorld: collisions.MakeWorld(),
AssetsFolder: &assetsFolder,
Manager: m,
}
ebiten.SetWindowSize(screenWidth*windowScale, screenHeight*windowScale)
ebiten.SetWindowResizable(true)
if err := ebiten.RunGame(g); err != nil && err != errQuit {
log.Fatal(err)
}
}