-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (30 loc) · 920 Bytes
/
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
// Example showing how to use PixMap struct, which is used to store screen
// and sprite-sheet pixels.
package main
import (
"embed"
"github.com/elgopher/pi"
"github.com/elgopher/pi/ebitengine"
)
//go:embed sprite-sheet.png
var resources embed.FS
func main() {
pi.Load(resources)
// copy from sprite-sheet to sprite-sheet:
pi.SprSheet().Copy(10, 0, 100, 100, pi.SprSheet(), 0, 0)
// draw a filled rectangle directly to sprite-sheet:
pi.SprSheet().RectFill(60, 30, 70, 40, 7)
// merge from sprite-sheet to screen using custom merge function, which merges two lines
pi.SprSheet().Merge(-1, -1, 103, 70, pi.Scr(), -1, -1, func(dst, src []byte) {
for x := 0; x < len(dst); x++ {
dst[x] += pi.Pal[src[x]] + 1
}
})
// update each line in a loop:
pi.Scr().Foreach(10, 10, 16, 16, func(x, y int, line []byte) {
for i := 0; i < len(line); i++ {
line[i] = byte(i)
}
})
ebitengine.MustRun()
}