Implemented multilayer handling
This commit is contained in:
parent
d2a212d454
commit
937e824293
|
@ -23,7 +23,7 @@ gosl.json for configuration (Port/Address, Level)
|
||||||
// Run:
|
// Run:
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClientOffset = 10
|
const ClientOffset = 0
|
||||||
|
|
||||||
type goslClient struct {
|
type goslClient struct {
|
||||||
con *net.TCPConn
|
con *net.TCPConn
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
//"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type directionType int
|
type directionType int
|
||||||
|
@ -41,6 +41,7 @@ type Level struct {
|
||||||
Name string
|
Name string
|
||||||
FPS int
|
FPS int
|
||||||
Layers map[string]*Layer
|
Layers map[string]*Layer
|
||||||
|
lorder []zString // ordered key list (by z index)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (lvl *Level) AddLayer(z int, l *Layer) {
|
//func (lvl *Level) AddLayer(z int, l *Layer) {
|
||||||
|
@ -100,8 +101,31 @@ func (lvl *Level) Width() (max int) {
|
||||||
return
|
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
|
//testcomment
|
||||||
func (lvl *Level) GetFrame(o, w, maxW, frameNo int) (ret *Frame) {
|
func (lvl *Level) GetFrame(o, w, maxW, frameNo int) (ret *Frame) {
|
||||||
|
lvl.initOrder()
|
||||||
h := lvl.Height()
|
h := lvl.Height()
|
||||||
|
|
||||||
ret = &Frame{
|
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])
|
ret.Data = append(ret.Data, mdata[y*w:(y+1)*w])
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, layer := range lvl.Layers {
|
for zli, zl := range lvl.lorder {
|
||||||
if layer.Z == 0 {
|
layer := lvl.Layers[zl.id]
|
||||||
|
//for _, layer := range lvl.Layers {
|
||||||
|
//if layer.Z == 0 {
|
||||||
for row := 0; row < h; row++ {
|
for row := 0; row < h; row++ {
|
||||||
//ret.Data = append(ret.Data, []rune{})
|
//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 {
|
if 0 < ro && ro < len(r) && string(r[ro]) != layer.T {
|
||||||
ret.Data[row][col] = r[ro]
|
ret.Data[row][col] = r[ro]
|
||||||
} else {
|
} else {
|
||||||
|
if zli == 0 {
|
||||||
ret.Data[row][col] = rune(' ')
|
ret.Data[row][col] = rune(' ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//for col := 0
|
//for col := 0
|
||||||
//log.Println(len(layer.Frames[f][row]))
|
//log.Println(len(layer.Frames[f][row]))
|
||||||
//ret.Data[row] = append(ret.Data[row], (layer.Frames[f][row][off%w:])...)
|
//ret.Data[row] = append(ret.Data[row], (layer.Frames[f][row][off%w:])...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -5,10 +5,16 @@
|
||||||
"locomotive": {
|
"locomotive": {
|
||||||
"Z-Index": 0,
|
"Z-Index": 0,
|
||||||
"Direction": 4,
|
"Direction": 4,
|
||||||
"Speed": 1,
|
"Speed": 3,
|
||||||
"Repeat": false,
|
"Repeat": false,
|
||||||
"Transparent": "•"
|
"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