-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (51 loc) · 1.09 KB
/
main.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
// Example showing practical use of palette swapping. Drawing same sprite with different palette
// generates tens of different sprites.
package main
import (
"embed"
"github.com/elgopher/pi"
"github.com/elgopher/pi/ebitengine"
)
const (
eyes = 1 // color number of eyes in sprite-sheet
skin = 7
mouth = 8
hair = 5
)
var (
//go:embed sprite-sheet.png
resources embed.FS
eyeColors = [...]byte{0, 1, 3, 4, 12}
skinColors = [...]byte{7, 5, 15}
hairColors = [...]byte{0, 4, 5, 6, 7, 9, 10}
mouthColors = [...]byte{2, 8}
)
func main() {
pi.Load(resources)
pi.Draw = draw
ebitengine.MustRun()
}
func draw() {
pi.Cls()
x, y := 0, 0
for _, eyeColor := range eyeColors {
pi.Pal[eyes] = eyeColor
for _, skinColor := range skinColors {
pi.Pal[skin] = skinColor
for _, hairColor := range hairColors {
pi.Pal[hair] = hairColor
for _, mouthColor := range mouthColors {
pi.Pal[mouth] = mouthColor
// draw the sprite with swapped colors:
pi.Spr(0, x, y)
x += 8
if x >= 128 {
// go to next line
x = 0
y += 8
}
}
}
}
}
}