Mappy

Share your advanced PureBasic knowledge/code with the community.
MrTATaod
User
User
Posts: 20
Joined: Wed Jun 28, 2006 6:11 pm

Mappy

Post by MrTATaod »

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.

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


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.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Congratulations on the program :)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Hi, MrTAtaod, shouldn't be good to append that to this thread:
http://www.purebasic.fr/english/viewtopic.php?t=7080
?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
MrTATaod
User
User
Posts: 20
Joined: Wed Jun 28, 2006 6:11 pm

Post by MrTATaod »

I might tomorrow.
Post Reply