01-14-2005, 04:39 AM
I'm developing a clone for an old DOS Game (www.gameofrobot.de) with freebasic, and because of my lazyness I use a free mapeditor from (www.mapeditor.de.vu). Perhaps some of you know it, therefor I post my loadmap code snippet. Some things could be done better/easier, I know And it's far from being complete. But it serves me well.
For a better understanding of my code, you should read the manual of the mapeditor. Included with the editor is sourcecode for handling the mapfiles with blitzbasic.
Greetings
Fausti
P.S. Hope my english is understandable With mapeditor 1.4 it doesn't go. I'm using 1.1. But I'll update the source...
Code:
TYPE MAP_HEADER
blocks AS UINTEGER
layers AS UINTEGER
images AS UINTEGER
geoms AS UINTEGER
tilesets AS UINTEGER
anims AS UINTEGER
basis AS UINTEGER
daten AS UINTEGER
meta AS UINTEGER
END TYPE
TYPE MAP_TILESET
MaskR AS UINTEGER
MaskG AS UINTEGER
MaskB AS UINTEGER
FrameB AS UINTEGER
FrameH AS UINTEGER
Anims AS UINTEGER
Frames AS UINTEGER
FileName AS STRING * 12
END TYPE
TYPE MAP_ANIMATION
Frames AS UINTEGER
StartFrame AS UINTEGER
Modus AS UINTEGER
Frame(256) AS UINTEGER
Zeit(256) AS UINTEGER
END TYPE
TYPE MAP_LAYER
Visible AS UINTEGER
Name AS STRING * 12
BDatenTiefe AS UINTEGER
BDatenSize AS UINTEGER
BDaten AS STRING
DatenTiefe AS UINTEGER
DatenSize AS UINTEGER
Daten AS STRING
MDatenTiefe AS UINTEGER
MDatenSize AS UINTEGER
MDaten AS STRING
END TYPE
TYPE MAP_TYPE
Header AS MAP_HEADER
BlockSize(256) AS UINTEGER
TileSet(256) AS MAP_TILESET
Animation(256) AS MAP_ANIMATION
Layer(256) AS MAP_LAYER
END TYPE
SUB Map_Load(fname$)
DIM tString AS STRING
DIM nChar AS UINTEGER
DIM tChar AS STRING * 1
DIM tByte AS STRING * 1
DIM tMap AS MAP_TYPE
DIM aB_Tileset
DIM aB_Animation
DIM aB_Background
DIM aB_Layer
aB_Layer = -1
DIM aFrame
DIM aBLOCK, lBType, aBType
DIM nBeg, nCount, nCalc
DIM nValue AS UINTEGER
OPEN fname$ FOR BINARY AS #1
' HEADER
tString = STRING(64, " "): GET #1,, tString
nBeg = 28: nCount = 2: GOSUB Str2UInt: tMap.Header.blocks = nValue
nBeg = 30: nCount = 2: GOSUB Str2UInt: tMap.Header.layers = nValue
nBeg = 32: nCount = 2: GOSUB Str2UInt: tMap.Header.images = nValue
nBeg = 34: nCount = 2: GOSUB Str2UInt: tMap.Header.geoms = nValue
nBeg = 36: nCount = 2: GOSUB Str2UInt: tMap.Header.tilesets = nValue
nBeg = 38: nCount = 2: GOSUB Str2UInt: tMap.Header.anims = nValue
nBeg = 40: nCount = 2: GOSUB Str2UInt: tMap.Header.basis = nValue
nBeg = 42: nCount = 2: GOSUB Str2UInt: tMap.Header.daten = nValue
nBeg = 44: nCount = 2: GOSUB Str2UInt: tMap.Header.meta = nValue
' TABLE
tString = STRING(tMap.Header.blocks * 4, " "): GET #1,, tString
FOR i = 0 TO tMap.Header.blocks - 1
nBeg = (i * 4): nCount = 4: GOSUB Str2UInt: tMap.BlockSize(i) = nValue
NEXT
' BLOCKS
FOR aBLOCK = 0 TO tMap.Header.blocks - 1
GET #1,, tChar: aBType = ASC(tChar)
SEEK #1, (SEEK(1)-1)
SELECT CASE aBType
CASE 100 'TILESET
tString = STRING(26, " "): GET #1,, tString
nBeg = 1: nCount = 1: GOSUB Str2UInt: tMap.TileSet(aB_Tileset).MaskR = nValue
nBeg = 2: nCount = 1: GOSUB Str2UInt: tMap.TileSet(aB_Tileset).MaskG = nValue
nBeg = 3: nCount = 1: GOSUB Str2UInt: tMap.TileSet(aB_Tileset).MaskB = nValue
nBeg = 4: nCount = 2: GOSUB Str2UInt: tMap.TileSet(aB_Tileset).FrameB = nValue
nBeg = 6: nCount = 2: GOSUB Str2UInt: tMap.TileSet(aB_Tileset).FrameH = nValue
nBeg = 10: nCount = 2: GOSUB Str2UInt: tMap.TileSet(aB_Tileset).Anims = nValue
nBeg = 12: nCount = 2: GOSUB Str2UInt: tMap.TileSet(aB_Tileset).Frames = nValue
tMap.TileSet(aB_Tileset).FileName = MID$(tString, 15, 12)
aB_Tileset = aB_Tileset + 1
CASE 101 'ANIMATION
tString = STRING(13, " "): GET #1,, tString
nBeg = 1: nCount = 2: GOSUB Str2UInt: tMap.Animation(aB_Animation).Frames = nValue
nBeg = 3: nCount = 2: GOSUB Str2UInt: tMap.Animation(aB_Animation).StartFrame = nValue
nBeg = 5: nCount = 2: GOSUB Str2UInt: tMap.Animation(aB_Animation).Modus = nValue
FOR aFrame = 0 TO tMap.Animation(aB_Animation).Frames - 1
tString = STRING(4, " "): GET #1,, tString
nBeg = 0: nCount = 2: GOSUB Str2UInt: tMap.Animation(aB_Animation).Frame(aFrame) = nValue
nBeg = 2: nCount = 2: GOSUB Str2UInt: tMap.Animation(aB_Animation).Zeit(aFrame) = nValue
NEXT
aB_Animation = aB_Animation + 1
CASE 0 'BACKGROUND
tString = STRING(36, " "): GET #1,, tString
CASE 1 'LAYER RECTANGLE
aB_Layer = aB_Layer + 1
tString = STRING(35, " "): GET #1,, tString
nBeg = 1: nCount = 1: GOSUB Str2UInt: tMap.Layer(aB_Layer).Visible = nValue
tMap.Layer(aB_Layer).Name = MID$(tString, 3, 12)
CASE 102 'BASEDATA
tString = STRING(8, " "): GET #1,, tString
nBeg = 1: nCount = 1: GOSUB Str2UInt: tMap.Layer(aB_Layer).BDatenTiefe = nValue
nBeg = 2: nCount = 4: GOSUB Str2UInt: tMap.Layer(aB_Layer).BDatenSize = nValue
tString = STRING(tMap.Layer(aB_Layer).BDatenSize, " ")
GET #1,, tString
tMap.Layer(aB_Layer).BDaten = tString
CASE 103 'MAPDATA
tString = STRING(8, " "): GET #1,, tString
nBeg = 1: nCount = 1: GOSUB Str2UInt: tMap.Layer(aB_Layer).DatenTiefe = nValue
nBeg = 2: nCount = 4: GOSUB Str2UInt: tMap.Layer(aB_Layer).DatenSize = nValue
tMap.Layer(aB_Layer).Daten = STRING(tMap.Layer(aB_Layer).DatenSize, " ")
GET #1,, tMap.Layer(aB_Layer).Daten
CASE 104 'METADATA
tString = STRING(8, " "): GET #1,, tString
nBeg = 1: nCount = 1: GOSUB Str2UInt: tMap.Layer(aB_Layer).MDatenTiefe = nValue
nBeg = 2: nCount = 4: GOSUB Str2UInt: tMap.Layer(aB_Layer).MDatenSize = nValue
tMap.Layer(aB_Layer).MDaten = STRING(tMap.Layer(aB_Layer).MDatenSize, " ")
GET #1,, tMap.Layer(aB_Layer).MDaten
CASE ELSE 'UNKNOWN
PRINT "Unbekannter Block ("+STR$(aBType)+") gefunden!"
END SELECT
NEXT
CLOSE 1
EXIT SUB
Str2UInt:
nCalc = 1
nValue = 0
REM FOR i = (nCount - 1) TO 0 STEP -1
FOR j = 0 TO (nCount - 1)
nChar = ASC(MID$(tString, nBeg + j+1, 1))
nValue = nValue + (nChar * nCalc)
nCalc = nCalc * 256
NEXT
RETURN
END SUB
For a better understanding of my code, you should read the manual of the mapeditor. Included with the editor is sourcecode for handling the mapfiles with blitzbasic.
Greetings
Fausti
P.S. Hope my english is understandable With mapeditor 1.4 it doesn't go. I'm using 1.1. But I'll update the source...