-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (45 loc) · 1.01 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
package main
import (
"bytes"
"image"
_ "image/png"
"io/ioutil"
"log"
"github.com/hajimehoshi/ebiten/v2"
"golang.org/x/image/font"
)
const WIDTH int = 600
const HEIGHT int = 600
var bird_resource *ebiten.Image
var pipe_resource *ebiten.Image
var press_start_2p font.Face
func LoadImageFromPath(path string) image.Image {
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
img, _, err := image.Decode(bytes.NewReader(data))
if err != nil {
log.Fatal(err)
}
return img
}
func main() {
ebiten.SetWindowSize(WIDTH, HEIGHT)
ebiten.SetWindowTitle("Flappy Bird")
bird_image := LoadImageFromPath("duck.png")
bird_resource = ebiten.NewImageFromImage(bird_image)
bird := DefaultBird(
bird_resource,
)
pipe_image := LoadImageFromPath("pipe.png")
pipe_resource = ebiten.NewImageFromImage(pipe_image)
press_start_2p = LoadFontByPath("PressStart2P-Regular.ttf", 36)
game := Game{
score: 0,
scene: NewGameScene(bird),
}
if err := ebiten.RunGame(&game); err != nil {
panic(err)
}
}