Basic frame rendering
This commit is contained in:
parent
f4f2d95a62
commit
47e7356a9a
|
@ -54,41 +54,31 @@ func handleConn(conn *net.TCPConn) {
|
|||
|
||||
func serveClients() {
|
||||
World = data.LoadLevel(LevelFile)
|
||||
var oFrame = data.Frame{
|
||||
1, 10,
|
||||
[][]rune{
|
||||
[]rune("hallo"),
|
||||
[]rune("das"),
|
||||
[]rune("ist"),
|
||||
[]rune("einTest"),
|
||||
},
|
||||
}
|
||||
fCounter := 0
|
||||
for { // while true
|
||||
for _, k := range clientKeys {
|
||||
id, client := k, clients[k]
|
||||
if id > 0 {
|
||||
oFrame := World.GetFrame(0, client.w, fCounter)
|
||||
fCounter++
|
||||
enc := gob.NewEncoder(client.con)
|
||||
err := enc.Encode(oFrame)
|
||||
if err != nil {
|
||||
// client disconnected
|
||||
|
||||
//log.Println("BEFORE remove: clients:", clients, " clientKeys:", clientKeys)
|
||||
|
||||
// delete client
|
||||
delete(clients, client.id)
|
||||
|
||||
// delete client key
|
||||
// ugly as fuck in go to remove from a slice
|
||||
// it *should* work though
|
||||
idInKeys := sort.SearchInts(clientKeys, client.id)
|
||||
clientKeys = append(clientKeys[:idInKeys], clientKeys[idInKeys+1:]...)
|
||||
|
||||
//log.Println("AFTER remove: clients:", clients, " clientKeys:", clientKeys)
|
||||
}
|
||||
//log.Println("ID:", id, "Client:", client)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second / 25)
|
||||
time.Sleep(time.Second / time.Duration(World.FPS))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,3 +59,39 @@ func LoadLevel(filename string) *Level {
|
|||
//log.Println(ret.Layers["locomotive"])
|
||||
return ret
|
||||
}
|
||||
|
||||
func (lvl *Level) Height() int {
|
||||
max := 0
|
||||
for _, l := range lvl.Layers {
|
||||
for _, f := range l.Frames {
|
||||
if len(f) > max {
|
||||
max = len(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
func (lvl *Level) GetFrame(off, w, frame int) (ret *Frame) {
|
||||
//log.Println(ret)
|
||||
h := lvl.Height()
|
||||
|
||||
ret = &Frame{
|
||||
W: w,
|
||||
H: h,
|
||||
}
|
||||
|
||||
for _, l := range lvl.Layers {
|
||||
if l.Z == 0 {
|
||||
for i := 0; i < h; i++ {
|
||||
ret.Data = append(ret.Data, []rune{})
|
||||
f := (frame % len(l.Frames)) + 1
|
||||
if i <= len(l.Frames[f]) {
|
||||
ret.Data[i] = append(ret.Data[i], l.Frames[f][i]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -8,13 +8,7 @@
|
|||
"Speed": 2,
|
||||
"Repeat": false,
|
||||
"Transparent": "•"
|
||||
},
|
||||
"background": {
|
||||
"Z-Index": 1,
|
||||
"Direction": 6,
|
||||
"Speed": 1,
|
||||
"Repeat": true,
|
||||
"Transparent": "•"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user