-
Notifications
You must be signed in to change notification settings - Fork 3
/
load.go
158 lines (117 loc) · 3.35 KB
/
load.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package game
import (
"image/color"
_ "image/png"
"sync"
"time"
"geometry-jumper/resource"
"github.com/golang/freetype/truetype"
"github.com/hajimehoshi/ebiten"
"github.com/uber-go/zap"
)
func Load(lg zap.Logger) {
logger = lg
defer timeTrack(time.Now(), "Game.Load")
var wg sync.WaitGroup
wg.Add(5)
go func() {
defer wg.Done()
// This is very fragile. initImages must come first!
// I guess we could just call initImageMaps inside of initImages...?
initImages()
initImageMaps()
}()
go func() {
defer wg.Done()
err := loadAudio()
handleErr(err)
}()
go func() {
defer wg.Done()
initColorMaps()
}()
go func() {
defer wg.Done()
initFont()
}()
go func() {
defer wg.Done()
initPatternCollection()
}()
wg.Wait()
}
func initImages() {
pImage, err := openImage("Robot2.png")
handleErr(err)
PersonStandingImage, err = ebiten.NewImageFromImage(pImage, ebiten.FilterNearest)
handleErr(err)
pImage2, err := openImage("Robot2_jump.png")
handleErr(err)
PersonJumpingImage, err = ebiten.NewImageFromImage(pImage2, ebiten.FilterNearest)
handleErr(err)
platImage, err := openImage("platform.png")
handleErr(err)
PlatformImage, err = ebiten.NewImageFromImage(platImage, ebiten.FilterNearest)
handleErr(err)
sImage, err := openImage("square.png")
handleErr(err)
SquareImage, err = ebiten.NewImageFromImage(sImage, ebiten.FilterNearest)
handleErr(err)
tImage, err := openImage("triangle.png")
handleErr(err)
TriangleImage, err = ebiten.NewImageFromImage(tImage, ebiten.FilterNearest)
handleErr(err)
cImage, err := openImage("circle.png")
handleErr(err)
CircleImage, err = ebiten.NewImageFromImage(cImage, ebiten.FilterNearest)
handleErr(err)
UpperTrackLine, err = ebiten.NewImage(TrackLength, 1, ebiten.FilterNearest)
UpperTrackLine.Fill(color.White)
handleErr(err)
LowerTrackLine, err = ebiten.NewImage(TrackLength, 1, ebiten.FilterNearest)
LowerTrackLine.Fill(color.White)
handleErr(err)
UpperTrackOpts = &ebiten.DrawImageOptions{}
UpperTrackOpts.GeoM.Translate(0, UpperTrackYAxis)
LowerTrackOpts = &ebiten.DrawImageOptions{}
LowerTrackOpts.GeoM.Translate(0, LowerTrackYAxis)
titleImage, err := openImage("title.png")
handleErr(err)
TitleImage, err = ebiten.NewImageFromImage(titleImage, ebiten.FilterNearest)
handleErr(err)
end, err := openImage("end.png")
handleErr(err)
EndImage, err = ebiten.NewImageFromImage(end, ebiten.FilterNearest)
handleErr(err)
}
func initImageMaps() {
ShapeImageMap = map[int][]*ebiten.Image{
TriangleType: []*ebiten.Image{TriangleImage},
SquareType: []*ebiten.Image{SquareImage},
CircleType: []*ebiten.Image{CircleImage},
}
}
func initColorMaps() {
DefaultSquareColorMap = ebiten.ColorM{}
DefaultSquareColorMap.Scale(255, 0, 0, 100)
DefaultCircleColorMap = ebiten.ColorM{}
DefaultCircleColorMap.Scale(0, 255, 0, 100)
DefaultTriangleColorMap = ebiten.ColorM{}
DefaultTriangleColorMap.Scale(0, 0, 255, 100)
ColorMappings = map[int]ebiten.ColorM{
SquareType: DefaultSquareColorMap,
CircleType: DefaultCircleColorMap,
TriangleType: DefaultTriangleColorMap,
}
}
func initFont() {
fontAsset, err := resource.Asset("3Dventure.ttf")
handleErr(err)
Font, err = truetype.Parse(fontAsset)
handleErr(err)
}
func initPatternCollection() {
data, err := resource.Asset("patterns.json")
handleErr(err)
GamePatternCollection = PatternCollectionFromJSON(data)
}