/
hud.go
43 lines (37 loc) · 815 Bytes
/
hud.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
package main
import (
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
type HUD struct {
ScoreDisplayFont font.Face
ResultDisplayFont font.Face
}
func newHUD() (*HUD, error) {
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
if err != nil {
return nil, err
}
const dpi = 72
scoreDisplayFont, err := opentype.NewFace(tt, &opentype.FaceOptions{
Size: 76,
DPI: dpi,
Hinting: font.HintingFull,
})
if err != nil {
return nil, err
}
resultDisplayFont, err := opentype.NewFace(tt, &opentype.FaceOptions{
Size: 18,
DPI: dpi,
Hinting: font.HintingFull,
})
if err != nil {
return nil, err
}
return &HUD{
ScoreDisplayFont: scoreDisplayFont,
ResultDisplayFont: resultDisplayFont,
}, nil
}