-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (40 loc) · 934 Bytes
/
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
package main
import (
"os"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"github.com/meghashyamc/snake-game/ui"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetFormatter(&log.JSONFormatter{})
gameApp := app.New()
gameApp.SetIcon(loadIcon())
window := gameApp.NewWindow("Snake Game")
newGameVisual, err := formGameVisual(window)
if err != nil {
os.Exit(1)
}
window.SetContent(newGameVisual.Container)
go ui.ListenToInput(window)
window.ShowAndRun()
}
func formGameVisual(win fyne.Window) (*ui.GameVisual, error) {
thisGameVisual, err := ui.NewGameVisual()
if err != nil {
return nil, err
}
thisGameVisual.InitContainer()
go thisGameVisual.Animate()
return thisGameVisual, nil
}
func loadIcon() fyne.Resource {
res, err := fyne.LoadResourceFromPath("icon.png")
if err != nil {
log.WithFields(log.Fields{
"err": err.Error(),
}).Error("Error loading app icon")
os.Exit(1)
}
return res
}