-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.go
132 lines (113 loc) · 3.23 KB
/
init.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
package main
import (
"fmt"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
"github.com/hajimehoshi/ebiten/v2/text"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"image"
"image/color"
"math/rand"
"time"
)
var boxSprite Sprite
var engineSprite Sprite
var legSprite Sprite
var legFasteningSprite Sprite
var cabinSprite Sprite
var craneSprite Sprite
var craneUpperJawSprite Sprite
var craneLowerJawSprite Sprite
var chainElSprite Sprite
var cargoSprite Sprite
var flameParticleImg *ebiten.Image
var platformFace font.Face
var cargoFace font.Face
var hoodFace font.Face
var radarArrowImg *ebiten.Image
var hoodImg *ebiten.Image
var modalImg *ebiten.Image
var emptyTransparentImage = ebiten.NewImage(1, 1)
var emptyImage = ebiten.NewImage(3, 3)
var emptySubImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
var modalTitleFace font.Face
var modalTextFace font.Face
var levelNameFace font.Face
var levelDescFace font.Face
func init() {
initEbiten()
emptyImage.Fill(color.White)
rand.Seed(time.Now().UnixNano())
f, err := opentype.Parse(fonts.MPlus1pRegular_ttf)
checkErr(err)
platformFace, err = opentype.NewFace(f, &opentype.FaceOptions{
Size: 30,
DPI: FontDpi,
Hinting: font.HintingFull,
})
checkErr(err)
cargoFace, err = opentype.NewFace(f, &opentype.FaceOptions{
Size: 100,
DPI: FontDpi,
Hinting: font.HintingFull,
})
checkErr(err)
hoodFace, err = opentype.NewFace(f, &opentype.FaceOptions{
Size: 30,
DPI: FontDpi,
Hinting: font.HintingFull,
})
checkErr(err)
modalTitleFace, err = opentype.NewFace(f, &opentype.FaceOptions{
Size: 50,
DPI: FontDpi,
Hinting: font.HintingFull,
})
checkErr(err)
modalTextFace, err = opentype.NewFace(f, &opentype.FaceOptions{
Size: 20,
DPI: FontDpi,
Hinting: font.HintingFull,
})
checkErr(err)
levelNameFace, err = opentype.NewFace(f, &opentype.FaceOptions{
Size: 30,
DPI: FontDpi,
Hinting: font.HintingFull,
})
checkErr(err)
levelDescFace, err = opentype.NewFace(f, &opentype.FaceOptions{
Size: 30,
DPI: FontDpi,
Hinting: font.HintingFull,
})
checkErr(err)
// Ship parts
boxSprite = LoadPart("box")
engineSprite = LoadPart("engine")
legSprite = LoadPart("leg")
legFasteningSprite = LoadPart("leg_fastening")
cabinSprite = LoadPart("cabin")
craneSprite = LoadPart("crane")
craneUpperJawSprite = LoadPart("crane_upper_jaw")
craneLowerJawSprite = LoadPart("crane_lower_jaw")
chainElSprite = LoadPart("chain_el")
cargoSprite = LoadPart("cargo")
flameParticleImg = loadImage("flame_particle.png")
radarArrowImg = loadImage("hood/radar_arrow.png")
hoodImg = loadImage("hood/hood.png")
// Print text on image for future localization
text.Draw(hoodImg, fmt.Sprintf("%v\n%v", FuelLabelText, EnergyLabelText), hoodFace, 50, 1000, color.White)
text.Draw(hoodImg, fmt.Sprintf("%v\n%v", TargetLabelText, DistanceLabelText), hoodFace, 550, 1000, color.White)
// Cache distance glyphs
for i := 0; i < 50; i++ {
text.CacheGlyphs(hoodFace, fmt.Sprintf(DistanceText, i))
}
modalImg = loadImage("modal.png")
}
func initEbiten() {
ebiten.SetWindowSize(ScreenWidth, ScreenHeight)
ebiten.SetWindowTitle("Space Crane")
ebiten.SetWindowResizable(true)
}