-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
46 lines (40 loc) · 983 Bytes
/
level.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
package main
import (
"image"
"log"
"github.com/hajimehoshi/ebiten/v2"
"github.com/lafriks/go-tiled"
"github.com/lafriks/go-tiled/render"
)
const (
level0FilePath string = "./assets/tiles/forgotten-fields.tmx"
)
type Level struct {
pathLayerImg *image.NRGBA
mapImg *ebiten.Image
}
func (l *Level) loadMap() {
levelMap, err := tiled.LoadFile(level0FilePath)
if err != nil {
log.Fatalf("error parsing map: %s", err.Error())
panic(err)
}
renderer, err := render.NewRenderer(levelMap)
if err != nil {
log.Fatalf("map unsupported for rendering: %s", err.Error())
panic(err)
}
err = renderer.RenderGroup(0)
if err != nil {
log.Fatalf("error rendering path template layers: %s", err.Error())
panic(err)
}
l.pathLayerImg = renderer.Result
renderer.Clear()
err = renderer.RenderVisibleGroups()
if err != nil {
log.Fatalf("group unsupported for rendering: %s", err.Error())
panic(err)
}
l.mapImg = ebiten.NewImageFromImage(renderer.Result)
}