/
level.go
49 lines (39 loc) · 859 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
47
48
49
package pt
import (
"sort"
"github.com/fogleman/gg"
)
type Level struct {
Object
}
func NewLevel() *Level {
l := &Level{}
l.Name = "Level"
l.Init()
return l
}
func (l *Level) ChildrenByZ() []ObjectIface {
children := l.GetChildren()
// Sort by ID first
sort.Slice(children, func(i, j int) bool {
return children[i].GetID() < children[j].GetID()
})
// Now stable sort by Z to keep the ID ordering
sort.SliceStable(children, func(i, j int) bool {
return children[i].GetPos().Z < children[j].GetPos().Z
})
return children
}
func (l *Level) Draw(drawContext *gg.Context) {
for _, child := range l.ChildrenByZ() {
child.Draw(drawContext)
}
}
func (l *Level) Update() error {
panic("Levels should always implement Update")
}
type LevelIface interface {
ChildrenByZ() []ObjectIface
Draw(drawContext *gg.Context)
Update() error
}