Mappy
Posted: Thu Jun 29, 2006 6:09 pm
Code updated For 5.20+
The following is my PureBasic interface system for using my Mappy DLL.
Mappy is a 2D tile map editor (availiable at http://www.tilemap.co.uk). The DLL was originally used for DarkBasic (and is used by PureBasic as the actually Mappy DLL cant be called directly). Both are available from my web site.
A screenshot of it is here :
http://www.nicholaskingsley.co.uk/MiscT ... ebasic.JPG
As you can see there are a number of interesting glitches which present themselves :
A) It appears that bitmap images cant have transparencies, which is a problem for some tiles - and is a trifle annoying
B) Exported 24-bit bitmaps aren't accepted by Pure Basic
Aside from that (and the fact that I need an alternative way of getting author information - DBPro returns DWORD's for strings, and the fact that a fair few functions are missing), considering its my first Pure Basic program, it went very well.
The following is my PureBasic interface system for using my Mappy DLL.
Mappy is a 2D tile map editor (availiable at http://www.tilemap.co.uk). The DLL was originally used for DarkBasic (and is used by PureBasic as the actually Mappy DLL cant be called directly). Both are available from my web site.
Code: Select all
ImportC "Mappy_DBPro.lib"
loadMappyFile.l(FileName$,extraBytes.l=0) As "?loadMappyFile@@YAKPADK@Z"
getMappyVersion.l() As "?getMappyVersion@@YAKXZ"
getMapFormat.l() As "?getMapFormat@@YAKXZ"
; getAuthor.s(pOldString.l=0) As "?getAuthor@@YAKK@Z"
getMapWidth.l() As "?getMapWidth@@YAKXZ"
getMapHeight.l() As "?getMapHeight@@YAKXZ"
getBlockWidth.l() As "?getBlockWidth@@YAKXZ"
getBlockHeight.l() As "?getBlockHeight@@YAKXZ"
getNumBlocks.l() As "?getNumBlocks@@YAKXZ"
getNumberOfLayers.l() As "?getNumberOfLayers@@YAKXZ"
getMappyIndex.l(x.l,y.l) As "?getMappyIndex@@YAKKK@Z"
getTileAtPosition.l(layer.l,x.l,y.l) As "?getTileAtPosition@@YAKKKK@Z"
wrietTileAtPosition.l(layer.l,x.l,y.l,tile.l) As "?writeTileAtPosition@@YAKKKKK@Z"
getBlockDataSide.l() As "?getBlockDataSize@@YAKXZ"
updateAnimation() As "?updateAnimations@@YAXXZ"
getBackgroundOffset.l(block.l) As "?getBackgroundOffset@@YAKK@Z"
getForegroundOffset.l(block.l,which.l) As "?getForgroundOffset@@YAKKK@Z"
getCurrentAnimationBlock.l(block.l) As "?getCurrentAnimationBlock@@YAKK@Z"
EndImport
Declare loadMappyGraphics()
Declare displayMap(x.l, y.l,layer.l,sx.l,sy.l)
Global MAPPYGRAPHICDIR$="MAPPYGRAPHICS"
Global MAPPYFILENAMEBASE$="000000"
OpenConsole()
status=LoadMappyFile("test.fma",0)
Print ("Load Status:")
PrintN (Str(status))
If status=0
PrintN ("Loaded OK")
mapWidth=getMapWidth()
mapHeight=getMapHeight()
mapFormat=getMapFormat()
mapVersion=getMappyVersion()
numBlocks=getNumBlocks()
Print ("Map Width :")
PrintN (Str(mapWidth))
Print ("Map Height :")
PrintN (Str(mapHeight))
Print ("Map Format :")
PrintN (Str(mapFormat))
Print ("Mappy Version :")
PrintN (Str(mapVersion))
Print ("Number Of Blocks :")
PrintN (Str(numBlocks))
EndIf
Repeat
Until Inkey()<>""
CloseConsole()
If OpenWindow(0, 100, 100, 600, 600, "PureBasic - Image")
loadMappyGraphics()
x=20
y=20
displayMap(0,0,0,x,y)
Repeat
EventID = WindowEvent()
If EventID
Else
displayMap(0,0,0,x,y)
updateAnimation()
Delay(1)
EndIf
Until EventID = #PB_Event_CloseWindow ; If the user has pressed on the close button
CloseWindow(0)
EndIf
End
Procedure displayMap(x.l, y.l,layer.l,sx.l,sy.l)
lx.l=0
ly.l=0
tile.w=0
px.l=0
py.l=0
image.l=0
mapWidth=getMapWidth()
mapHeight=getMapHeight()
blockWidth=getBlockWidth()
blockHeight=getBlockHeight()
If StartDrawing(WindowOutput(0))
py=y
For ly=sy To mapHeight-1
px=x
For lx=sx To mapWidth-1
tile=getTileAtPosition(lx,ly,layer)
If tile<>0
If tile & (1<<15>0)
DrawImage(ImageID(image),px*blockWidth,py*blockHeight)
EndIf
image=getForegroundOffset(tile,0)
If image>0
DrawImage(ImageID(image),px*blockWidth,py*blockHeight)
EndIf
Else
DrawImage(ImageID(image),px*blockWidth,py*blockHeight)
EndIf
px+1
Next
py+1
Next ly
StopDrawing()
EndIf
EndProcedure
Procedure loadMappyGraphics()
l.l=0
name$=""
num$=""
numA$=""
For l=0 To getNumBlocks()-1
numA$=Str(l)
num$=Right(MAPPYFILENAMEBASE$,Len(MAPPYFILENAMEBASE$)-Len(numA$))+numA$+".BMP"
name$=MAPPYGRAPHICDIR$+"\G"+num$
If LoadImage(l,name$)=0
MessageRequester("*","File "+name$+" Not Loaded")
EndIf
Next l
EndProcedure
http://www.nicholaskingsley.co.uk/MiscT ... ebasic.JPG
As you can see there are a number of interesting glitches which present themselves :
A) It appears that bitmap images cant have transparencies, which is a problem for some tiles - and is a trifle annoying
B) Exported 24-bit bitmaps aren't accepted by Pure Basic
Aside from that (and the fact that I need an alternative way of getting author information - DBPro returns DWORD's for strings, and the fact that a fair few functions are missing), considering its my first Pure Basic program, it went very well.