-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbols.go
92 lines (82 loc) · 1.74 KB
/
symbols.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
package main
import (
"log"
"github.com/veandco/go-sdl2/sdl"
)
const (
//foodString = "🍞"
foodString = "F"
metalString = "M"
//bowString = "🏹"
bowString = "b"
swordString = "s"
pikeString = "p"
crossbowString = "c"
lanceString = "l"
//villageString = "🐷"
villageString = "v"
//townString = "🏠"
townString = "t"
//cityString = "🏰"
cityString = "c"
//capitalString = "👑"
capitalString = "C"
)
type SymbolID int
const (
SymbolFood SymbolID = iota
SymbolMetal
SymbolBow
SymbolSword
SymbolPike
SymbolCrossbow
SymbolLance
SymbolCapital
SymbolCity
SymbolTown
SymbolVillage
)
type Symbol struct {
ID SymbolID
Texture *sdl.Texture
Width int32
Height int32
}
func MakeSymbol(r *sdl.Renderer, id SymbolID, str string) {
sym := new(Symbol)
sym.ID = id
text, err := DroidSansMono.RenderUTF8_Blended(str, colourWhite)
if err != nil {
log.Panicln(err)
}
sym.Width = text.W
sym.Height = text.H
sym.Texture, err = r.CreateTextureFromSurface(text)
if err != nil {
log.Panicln(err)
}
text.Free()
SymbolMap[id] = sym
}
var SymbolMap map[SymbolID]*Symbol
// Must come after LoadButtons
func LoadSymbols(r *sdl.Renderer) {
SymbolMap = make(map[SymbolID]*Symbol)
MakeSymbol(r, SymbolCapital, capitalString)
MakeSymbol(r, SymbolCity, cityString)
MakeSymbol(r, SymbolTown, townString)
MakeSymbol(r, SymbolVillage, villageString)
MakeSymbol(r, SymbolFood, foodString)
MakeSymbol(r, SymbolMetal, metalString)
MakeSymbol(r, SymbolBow, bowString)
MakeSymbol(r, SymbolSword, swordString)
MakeSymbol(r, SymbolPike, pikeString)
MakeSymbol(r, SymbolCrossbow, crossbowString)
MakeSymbol(r, SymbolLance, lanceString)
}
func CleanupSymbols() {
for _, sym := range(SymbolMap) {
sym.Texture.Destroy()
}
SymbolMap = nil
}