This repository was archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhud.go
75 lines (61 loc) · 1.45 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"image/color"
"strconv"
"github.com/faiface/pixel"
"github.com/faiface/pixel/imdraw"
"github.com/faiface/pixel/pixelgl"
"github.com/faiface/pixel/text"
)
var (
HUD = &hud{}
coinPic *pixel.Sprite
)
type hud struct{}
func (h *hud) update(dt float64, win *pixelgl.Window) leveler {
return currentLvl
}
func (h *hud) draw(target pixel.Target) {
pos := pixel.V(winBounds.Max.X-32, 32)
unproj := cam.Unproject(pos)
coinPic.Draw(target, pixel.IM.Moved(unproj).Scaled(unproj, 1.5))
t := text.New(unproj, atlas)
t.Color = defaultTextColour
if currentLvl == &UpgradeScreen {
// To show on dark background
t.Color = color.RGBA{
R: 0xff,
G: 0xff,
B: 0xff,
A: 0xff,
}
}
_, _ = t.WriteString(strconv.Itoa(Player.coins))
t.Draw(target, pixel.IM.Moved(pixel.V(-4, -24)))
if Player.health < 100 && Player.health > 0 && currentLvl == &Level {
imd := imdraw.New(nil)
// border
bottomL := cam.Unproject(pixel.V(19, winBounds.Max.Y-20-101))
topR := cam.Unproject(pixel.V(20+11, winBounds.Max.Y-19))
imd.Color = color.RGBA{
R: 0x00,
G: 0x00,
B: 0x00,
A: 0xff,
}
imd.Push(bottomL, topR)
imd.Rectangle(2)
// bar
bottomL = cam.Unproject(pixel.V(20, winBounds.Max.Y-20-100))
topR = cam.Unproject(pixel.V(20+10, winBounds.Max.Y-20-(100-Player.health)))
imd.Color = color.RGBA{
R: 0xcd,
G: 0x00,
B: 0x0b,
A: 0xff,
}
imd.Push(bottomL, topR)
imd.Rectangle(0)
imd.Draw(target)
}
}