-
Notifications
You must be signed in to change notification settings - Fork 1
/
hud.go
56 lines (47 loc) · 1.35 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/text"
"image/color"
"math"
"time"
)
// Empty, but not yet fully functional. This approach is necessary, since method values bind their receiver, i.e. see my question
// on StackOverflow at https://stackoverflow.com/questions/59971005/why-is-this-behaviour-regarding-method-pointers-and-global-variable-initializati
var hudState = new(HudState)
// Define HudScene
var hudScene = &Scene{
Init: hudState.initHud,
Reset: hudState.Reset,
Update: hudState.Update,
Draw: hudState.Draw,
}
type HudState struct {
startTime time.Time
}
func (h *HudState) initHud() {
InitializeRandomSeed()
h.startTime = time.Now()
PlayAudioTimes("background", math.MaxInt32)
}
func (*HudState) Update() {
CheckExitKey()
}
func (h *HudState) Draw(screen *ebiten.Image) {
background.Draw(screen)
step := int64(750)
duration := step * 4
passedTime := duration - time.Now().Sub(h.startTime).Milliseconds()
if passedTime < step {
SetScene("game")
return
}
passedTime = passedTime / step
secs := fmt.Sprintf("%d", int(passedTime))
text.Draw(screen, secs, Font(160), width/2-len(secs)*50/2, height/2, color.Gray{Y: 200})
text.Draw(screen, randomSeed.Code, Font(20), (width-len(randomSeed.Code)*10)/2, height/2+50, color.Gray{Y: 180})
}
func (h *HudState) Reset() {
h.initHud()
}