Author Topic: Opening "flare - *.txt" from tiled editor - from dummies for dummies :)  (Read 1632 times)

Offline siatek

  • Mr. Drawsprite
  • **
  • Posts: 58
    • View Profile
this is a file format exported from "tiled" editor
there must be exactly 3 standard layers: object, collision and background
you can expand this easy ...

cheers

Code: (glbasic) [Select]

// ------------------------------------------------------------- //
// ---  TFlareFile  ---
// ------------------------------------------------------------- //

TYPE TFlareFile

backgroundLayer%[]
collisionLayer%[]
objectLayer%[]

width%
height%

FUNCTION Load: filename$

LOCAL chn% = GENFILE()
LOCAL buffer$

IF OPENFILE(chn, filename$, 1) = FALSE THEN END

READLINE chn, buffer$
READLINE chn, buffer$
buffer$ = LTRIM$ (buffer$,"width=")
self.width = INTEGER(buffer$)

READLINE chn, buffer$
buffer$ = LTRIM$ (buffer$,"height=")

self.height = INTEGER(buffer$)

DIM self.backgroundLayer[self.width][self.height]
DIM self.collisionLayer[self.width][self.height]
DIM self.objectLayer[self.width][self.height]

LOCAL x%

READLINE chn, buffer$
READLINE chn, buffer$
READLINE chn, buffer$
READLINE chn, buffer$

FOR y = 0 TO self.height-1
x=0
buffer$ = self.zReadLine$(chn)
LOCAL tiles$[]
SPLITSTR (buffer$, tiles$[], ",")
FOREACH tile IN tiles$[]
self.backgroundLayer[x][y] = INTEGER (tile)
INC x
NEXT
NEXT

READLINE chn, buffer$
READLINE chn, buffer$
READLINE chn, buffer$
READLINE chn, buffer$

FOR y = 0 TO self.height-1
x=0
buffer$ = zReadLine$(chn)
LOCAL tiles$[]
SPLITSTR (buffer$, tiles$[], ",")
FOREACH tile IN tiles$[]
self.collisionLayer[x][y] = INTEGER (tile)
INC x
NEXT
NEXT

READLINE chn, buffer$
READLINE chn, buffer$
READLINE chn, buffer$
READLINE chn, buffer$

FOR y = 0 TO self.height-1
x=0
buffer$ = self.zReadLine$(chn)
LOCAL tiles$[]
SPLITSTR (buffer$, tiles$[], ",")
FOREACH tile IN tiles$[]
self.objectLayer[x][y] = INTEGER (tile)
INC x
NEXT
NEXT

CLOSEFILE chn

ENDFUNCTION

FUNCTION zReadLine$: chn
LOCAL chda$, L$=""
REPEAT
    IF ENDOFFILE(chn) THEN BREAK
    READSTR chn, chda$, 1
    L$=L$+chda$
UNTIL ASC(chda$)=10
L$=TRIM$(L$)
RETURN L$
ENDFUNCTION

ENDTYPE
glbasic roxx !!!

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile