-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (51 loc) · 1.04 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
package main
import (
"fmt"
"log"
"math/rand"
"time"
"github.com/veandco/go-sdl2/sdl"
"github.com/veandco/go-sdl2/sdl_ttf"
)
const (
windowHeight = 600
windowWidth = 800
)
func run() error {
err := sdl.Init(sdl.INIT_EVERYTHING)
if err != nil {
return fmt.Errorf("Error while initializing sdl: %v", err)
}
err = ttf.Init()
if err != nil {
return fmt.Errorf("Error while initializing ttf: %v", err)
}
defer sdl.Quit()
window, renderer, err := sdl.CreateWindowAndRenderer(windowWidth, windowHeight, sdl.WINDOW_SHOWN)
defer window.Destroy()
if err != nil {
return fmt.Errorf("Error while creating window: %v", err)
}
scene, err := NewScene(renderer)
if err != nil {
return fmt.Errorf("Error while creating scene: %v", err)
}
go scene.run(20)
loop:
for {
switch sdl.WaitEvent().(type) {
case *sdl.QuitEvent:
break loop
case *sdl.MouseButtonEvent, *sdl.KeyUpEvent:
scene.bird.jump()
}
}
return nil
}
func main() {
rand.Seed(time.Now().UTC().UnixNano())
err := run()
if err != nil {
log.Fatal(err)
}
}