Implemented multilayer handling
This commit is contained in:
parent
d2a212d454
commit
937e824293
|
@ -23,7 +23,7 @@ gosl.json for configuration (Port/Address, Level)
|
|||
// Run:
|
||||
}
|
||||
|
||||
const ClientOffset = 10
|
||||
const ClientOffset = 0
|
||||
|
||||
type goslClient struct {
|
||||
con *net.TCPConn
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/gob"
|
||||
"log"
|
||||
"os"
|
||||
//"sort"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type directionType int
|
||||
|
@ -41,6 +41,7 @@ type Level struct {
|
|||
Name string
|
||||
FPS int
|
||||
Layers map[string]*Layer
|
||||
lorder []zString // ordered key list (by z index)
|
||||
}
|
||||
|
||||
//func (lvl *Level) AddLayer(z int, l *Layer) {
|
||||
|
@ -100,8 +101,31 @@ func (lvl *Level) Width() (max int) {
|
|||
return
|
||||
}
|
||||
|
||||
// Implement Sorter
|
||||
type zString struct {
|
||||
id string
|
||||
z int
|
||||
}
|
||||
type ByZ []zString
|
||||
|
||||
func (a ByZ) Len() int { return 1 }
|
||||
func (a ByZ) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByZ) Less(i, j int) bool { return a[i].z < a[j].z }
|
||||
|
||||
func (lvl *Level) initOrder() {
|
||||
if lvl.lorder == nil {
|
||||
lvl.lorder = []zString{}
|
||||
for k, v := range lvl.Layers {
|
||||
lvl.lorder = append(lvl.lorder, zString{k, v.Z})
|
||||
}
|
||||
sort.Sort(ByZ(lvl.lorder))
|
||||
sort.Reverse(ByZ(lvl.lorder))
|
||||
}
|
||||
}
|
||||
|
||||
//testcomment
|
||||
func (lvl *Level) GetFrame(o, w, maxW, frameNo int) (ret *Frame) {
|
||||
lvl.initOrder()
|
||||
h := lvl.Height()
|
||||
|
||||
ret = &Frame{
|
||||
|
@ -116,8 +140,10 @@ func (lvl *Level) GetFrame(o, w, maxW, frameNo int) (ret *Frame) {
|
|||
ret.Data = append(ret.Data, mdata[y*w:(y+1)*w])
|
||||
}
|
||||
|
||||
for _, layer := range lvl.Layers {
|
||||
if layer.Z == 0 {
|
||||
for zli, zl := range lvl.lorder {
|
||||
layer := lvl.Layers[zl.id]
|
||||
//for _, layer := range lvl.Layers {
|
||||
//if layer.Z == 0 {
|
||||
for row := 0; row < h; row++ {
|
||||
//ret.Data = append(ret.Data, []rune{})
|
||||
|
||||
|
@ -151,15 +177,17 @@ func (lvl *Level) GetFrame(o, w, maxW, frameNo int) (ret *Frame) {
|
|||
if 0 < ro && ro < len(r) && string(r[ro]) != layer.T {
|
||||
ret.Data[row][col] = r[ro]
|
||||
} else {
|
||||
if zli == 0 {
|
||||
ret.Data[row][col] = rune(' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
//for col := 0
|
||||
//log.Println(len(layer.Frames[f][row]))
|
||||
//ret.Data[row] = append(ret.Data[row], (layer.Frames[f][row][off%w:])...)
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -5,10 +5,16 @@
|
|||
"locomotive": {
|
||||
"Z-Index": 0,
|
||||
"Direction": 4,
|
||||
"Speed": 1,
|
||||
"Speed": 3,
|
||||
"Repeat": false,
|
||||
"Transparent": "•"
|
||||
},
|
||||
"ground": {
|
||||
"Z-Index": 1,
|
||||
"Direction": 6,
|
||||
"Speed": 1,
|
||||
"Repeat": true,
|
||||
"Transparent": "ä"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
11
levels/locoworld/ground/1.frame
Normal file
11
levels/locoworld/ground/1.frame
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=====================--=================-==============--======-===========-====
|
Loading…
Reference in New Issue
Block a user