forked from andersondalmina/flappy-bird-neural-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (43 loc) · 860 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
52
53
54
55
56
package main
import (
"fmt"
"math/rand"
"time"
_ "image/png"
"github.com/andersondalmina/flappy-bird-neural-network/components"
"github.com/andersondalmina/flappy-bird-neural-network/scenes"
"github.com/faiface/pixel/pixelgl"
)
func main() {
pixelgl.Run(run)
}
func run() {
rand.Seed(time.Now().UTC().UnixNano())
t := "Flappy Bird Neural Network!"
win, err := components.CreateWindow(t)
if err != nil {
panic(err)
}
s := scenes.CreateMenuScene()
var (
frames = 0
second = time.Tick(time.Second)
last = time.Now()
)
for !win.Closed() {
if win.JustPressed(pixelgl.KeyEscape) {
return
}
components.Delta = time.Since(last).Seconds()
last = time.Now()
s = s.Run(win)
win.Update()
frames++
select {
case <-second:
win.SetTitle(fmt.Sprintf("%s | FPS: %d", t, frames))
frames = 0
default:
}
}
}