I have a tavern sprite that I want to use in my 2D RPG, but I can't figure out how to draw it on the screen. It either scrolls with the PC and the rest of the screen, or when I put it directly into the map transparently with mappy, it isn't transparent in the program. I'm using the mappybb.bb file that is somewhere in the code archives. I don't have a link right now, so I'll just post the code:
; Please see mbbtest1.bb for a usage example ; This file is not meant to be run directly! ; also see the other mbb examples for various effects ; (C) Robin Burrows 2002 <rburrows@...; ; Please report bugs! ; For Mappy tilemaps: <a href="http://www.rbsite.freeserve.co.uk/robmpy.htm" target="_blank">http://www.rbsite.freeserve.co.uk/robmpy.htm</a> ; Release 4 (12/4/2002) Full FMP1.0 support ; Lots of tiles may take a while to load with debug on, fast with debug off Const mapmaxlayers = 2 ; change this to number of layers you have in your map! Const MER_MAPTOONEW = 3 Global maperror = 0 Global mapislsb, maptype Global mapchunkdone = 0 Global mapwidth,mapheight Global maptrans8, maptransr, maptransg, maptransb, maptransval Global mapblockwidth, mapblockheight, mapdepth Global mapblockstrsize, mapnumblockstr, mapnumblockgfx Global mapblockgapx, mapblockgapy Global mapblockstaggerx, mapblockstaggery, mapclickmask Global mapcurlyr, mapnumanims ; Don't fiddle with these, they're set later Dim mappt (0,0,0) Dim aniseq (0) Dim tilegfx (0) Dim cmappt (0) Dim blks.BLKSTR (0) Dim anis.ANISTR (0) Type BLKSTR Field bg, fg, fg2, fg3 Field user1, user2, user3, user4, user5, user6, user7 Field tl, tr, bl, br Field trigger, unused1, unused2, unused3 End Type Type ANISTR Field antype, andelay, ancount, anuser Field ancur, anstart, anend End Type Function MapGetBlock .BLKSTR (mx, my) If (mappt(mx, my, mapcurlyr) < 0) Return blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur)) Else Return blks(mappt (mx, my, mapcurlyr)) End If End Function Function MapSetBlock (mx, my, mv) mappt(mx, my, mapcurlyr) = mv End Function Function MapGetBlockInPixels .BLKSTR (mx, my) Local xp, yp If (mx < 0 Or my < 0 Or mx >= (mapblockwidth*mapwidth) Or my >= (mapblockheight*mapheight)) Then Return blks(0) xp = mx yp = my mx = MapGetXOffset (xp, yp) my = MapGetYOffset (xp, yp) If (mappt(mx, my, mapcurlyr) < 0) Return blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur)) Else Return blks(mappt (mx, my, mapcurlyr)) End If End Function Function MapSetBlockInPixels (mx, my, mv) If (mx < 0 Or my < 0 Or mx >= (mapblockwidth*mapwidth) Or my >= (mapblockheight*mapheight)) Then Return mappt(mx, my, mapcurlyr) = mv End Function Function MapDrawBG (mx, my, sx, sy, sw, sh) Local mx2, sx2 If (mapblockstaggerx Or mapblockstaggery) MapDrawStagger (mx, my, sx, sy, sw, sh, 0) Return End If Viewport sx, sy, sw, sh sw = sw + sx sh = sh + sy sx = sx -(mx Mod mapblockwidth) sy = sy -(my Mod mapblockheight) mx = mx / mapblockwidth my = my / mapblockheight mx2 = mx sx2 = sx While (sy < sh) mx = mx2 sx = sx2 While (sx < sw) If (mappt (mx, my, mapcurlyr) < 0) DrawBlock (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\bg), sx, sy) Else DrawBlock (tilegfx(blks(mappt (mx, my, mapcurlyr))\bg), sx, sy) End If mx = mx + 1 sx = sx + mapblockwidth Wend my = my + 1 sy = sy + mapblockheight Wend End Function Function MapDrawBGT (mx, my, sx, sy, sw, sh) Local mx2, sx2, tileg If (mapblockstaggerx Or mapblockstaggery) MapDrawStagger (mx, my, sx, sy, sw, sh, 0) Return End If Viewport sx, sy, sw, sh sw = sw + sx sh = sh + sy sx = sx -(mx Mod mapblockwidth) sy = sy -(my Mod mapblockheight) mx = mx / mapblockwidth my = my / mapblockheight mx2 = mx sx2 = sx While (sy < sh) mx = mx2 sx = sx2 While (sx < sw) If (mappt (mx, my, mapcurlyr) < 0) tileg = blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\bg Else tileg = blks(mappt (mx, my, mapcurlyr))\bg End If If (tileg > 0) Then DrawImage (tilegfx(tileg), sx, sy) mx = mx + 1 sx = sx + mapblockwidth Wend my = my + 1 sy = sy + mapblockheight Wend End Function Function MapDrawFG (mx, my, sx, sy, sw, sh, blyr) Local mx2, sx2, tileg If (mapblockstaggerx Or mapblockstaggery) MapDrawStagger (mx, my, sx, sy, sw, sh, blyr+1) Return End If Viewport sx, sy, sw, sh sw = sw + sx sh = sh + sy sx = sx -(mx Mod mapblockwidth) sy = sy -(my Mod mapblockheight) mx = mx / mapblockwidth my = my / mapblockheight mx2 = mx sx2 = sx While (sy < sh) mx = mx2 sx = sx2 While (sx < sw) If (mappt (mx, my, mapcurlyr) < 0) If (blyr = 0) tileg = blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg If (blyr = 1) tileg = blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg2 If (blyr = 2) tileg = blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg3 Else If (blyr = 0) tileg = blks(mappt (mx, my, mapcurlyr))\fg If (blyr = 1) tileg = blks(mappt (mx, my, mapcurlyr))\fg2 If (blyr = 2) tileg = blks(mappt (mx, my, mapcurlyr))\fg3 End If If (tileg > 0) Then DrawImage (tilegfx(tileg), sx, sy) mx = mx + 1 sx = sx + mapblockwidth Wend my = my + 1 sy = sy + mapblockheight Wend End Function Function MapDrawStagger (mx, my, sx, sy, sw, sh, bl) Local mx2, sx2 Viewport sx, sy, sw, sh sw = sw + sx sh = sh + sy sx = sx -(mx Mod mapblockgapx) sx = sx - mapblockstaggerx sy = sy -(my Mod mapblockgapy) sy = sy - mapblockstaggery mx = mx / mapblockgapx my = (my / mapblockgapy) * 2 mx2 = mx sx2 = sx While (sy < sh) mx = mx2 sx = sx2 While (sx < sw) If (mappt (mx, my, mapcurlyr) < 0) If (bl = 0) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\bg), sx, sy) If (bl = 1) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg), sx, sy) If (bl = 2) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg2), sx, sy) If (bl = 3) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg3), sx, sy) Else If (bl = 0) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\bg), sx, sy) If (bl = 1) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\fg), sx, sy) If (bl = 2) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\fg2), sx, sy) If (bl = 3) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\fg3), sx, sy) End If mx = mx + 1 sx = sx + mapblockgapx Wend my = my + 1 mx = mx2 sx = sx2+mapblockstaggerx sy = sy+mapblockstaggery While (sx < sw) If (mappt (mx, my, mapcurlyr) < 0) If (bl = 0) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\bg), sx, sy) If (bl = 1) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg), sx, sy) If (bl = 2) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg2), sx, sy) If (bl = 3) DrawImage (tilegfx(blks(aniseq(anis(-(mappt (mx, my, mapcurlyr)))\ancur))\fg3), sx, sy) Else If (bl = 0) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\bg), sx, sy) If (bl = 1) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\fg), sx, sy) If (bl = 2) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\fg2), sx, sy) If (bl = 3) DrawImage (tilegfx(blks(mappt (mx, my, mapcurlyr))\fg3), sx, sy) End If mx = mx + 1 sx = sx + mapblockgapx Wend my = my + 1 sy = sy + (mapblockgapy-mapblockstaggery) Wend End Function Function MapDrawRow (mx, my, sx, sy, sw, sh, rw) Local tileg, sy2, attblk, attloop If (((my/mapblockgapy)+rw) >= mapheight) Then Return Viewport sx, sy, sw, sh sw = sw + sx sh = sh + sy sx = sx -(mx Mod mapblockgapx) sy = sy -(my Mod mapblockgapy) sy = sy + ((rw/2)*mapblockgapy) If (Not (rw And 1)) sx = sx - mapblockstaggerx sy = sy - mapblockstaggery End If mx = mx / mapblockgapx my = (my / mapblockgapy) * 2 my = my + rw sy2 = sy While (sx < sw) sy = sy2 attloop = 0 Repeat If (mappt (mx, my, mapcurlyr) < 0) attblk = aniseq(anis(-(mappt (mx,my, mapcurlyr)))\ancur)+attloop Else attblk = mappt (mx, my, mapcurlyr)+attloop End If If (attloop > 0) tileg = blks(attblk)\bg If (tileg > 0) If ((blks(attblk)\unused2 + blks(attblk)\unused3) = 0) Then DrawImage (tilegfx(tileg), sx, sy) If (blks(attblk)\unused2 And (Not (blks(attblk)\unused3))) Then DrawImageRect (tilegfx(tileg), sx, sy, 0, 0, mapblockwidth/2, mapblockheight) If (blks(attblk)\unused3 And (Not (blks(attblk)\unused2))) Then DrawImageRect (tilegfx(tileg), sx+(mapblockwidth/2), sy, mapblockwidth/2, 0, mapblockwidth/2, mapblockheight) End If sy = sy - mapblockheight End If tileg = blks(attblk)\fg If (tileg > 0) If ((blks(attblk)\unused2 + blks(attblk)\unused3) = 0) Then DrawImage (tilegfx(tileg), sx, sy) If (blks(attblk)\unused2 And (Not (blks(attblk)\unused3))) Then DrawImageRect (tilegfx(tileg), sx, sy, 0, 0, mapblockwidth/2, mapblockheight) If (blks(attblk)\unused3 And (Not (blks(attblk)\unused2))) Then DrawImageRect (tilegfx(tileg), sx+(mapblockwidth/2), sy, mapblockwidth/2, 0, mapblockwidth/2, mapblockheight) End If sy = sy - mapblockheight tileg = blks(attblk)\fg2 If (tileg > 0) If ((blks(attblk)\unused2 + blks(attblk)\unused3) = 0) Then DrawImage (tilegfx(tileg), sx, sy) If (blks(attblk)\unused2 And (Not (blks(attblk)\unused3))) Then DrawImageRect (tilegfx(tileg), sx, sy, 0, 0, mapblockwidth/2, mapblockheight) If (blks(attblk)\unused3 And (Not (blks(attblk)\unused2))) Then DrawImageRect (tilegfx(tileg), sx+(mapblockwidth/2), sy, mapblockwidth/2, 0, mapblockwidth/2, mapblockheight) End If sy = sy - mapblockheight tileg = blks(attblk)\fg3 If (tileg > 0) If ((blks(attblk)\unused2 + blks(attblk)\unused3) = 0) Then DrawImage (tilegfx(tileg), sx, sy) If (blks(attblk)\unused2 And (Not (blks(attblk)\unused3))) Then DrawImageRect (tilegfx(tileg), sx, sy, 0, 0, mapblockwidth/2, mapblockheight) If (blks(attblk)\unused3 And (Not (blks(attblk)\unused2))) Then DrawImageRect (tilegfx(tileg), sx+(mapblockwidth/2), sy, mapblockwidth/2, 0, mapblockwidth/2, mapblockheight) End If sy = sy - mapblockheight attloop = attloop + 1 Until (blks(attblk)\unused1 = 0) mx = mx + 1 sx = sx + mapblockgapx Wend End Function Function MapInitAnims () Local n If (mapnumanims < 1) Return n = 1 While (anis(n)\antype <> 255) If (anis(n)\antype = 8) Then anis(n)\antype = 5 If (anis(n)\antype = 7) Then anis(n)\antype = 6 If (anis(n)\antype = 9) Then anis(n)\antype = 3 If (anis(n)\antype = 2 Or anis(n)\antype = 6) anis(n)\ancur = anis(n)\anstart If (anis(n)\anstart <> anis(n)\anend) Then anis(n)\ancur = (anis(n)\anend)-1 Else anis(n)\ancur = anis(n)\anstart End If anis(n)\ancount = anis(n)\andelay n = n + 1 Wend End Function Function MapUpdateAnims () Local n If (mapnumanims < 1) Return n = 1 While (anis(n)\antype <> 255) If (anis(n)\antype <> 0) anis(n)\ancount = anis(n)\ancount - 1 If (anis(n)\ancount < 0) anis(n)\ancount = anis(n)\andelay If (anis(n)\anstart <> anis(n)\anend) If (anis(n)\antype = 1) ; LOOPF anis(n)\ancur = anis(n)\ancur + 1 If (anis(n)\ancur = anis(n)\anend) Then anis(n)\ancur = anis(n)\anstart End If If (anis(n)\antype = 2) ; LOOPR anis(n)\ancur = anis(n)\ancur - 1 If (anis(n)\ancur = ((anis(n)\anend)-1)) Then anis(n)\ancur = (anis(n)\anend)-1 End If If (anis(n)\antype = 3) ; ONCE anis(n)\ancur = anis(n)\ancur + 1 If (anis(n)\ancur = anis(n)\anend) anis(n)\ancur = anis(n)\anstart anis(n)\antype = 9 End If End If If (anis(n)\antype = 4) ; ONCEH If (anis(n)\ancur <> (anis(n)\anend-1)) Then anis(n)\ancur = anis(n)\ancur + 1 End If If (anis(n)\antype = 5) ; PPFF anis(n)\ancur = anis(n)\ancur + 1 If (anis(n)\ancur = anis(n)\anend) anis(n)\ancur = anis(n)\ancur - 2 anis(n)\antype = 6 If (anis(n)\ancur < anis(n)\anstart) Then anis(n)\ancur = anis(n)\ancur + 1 End If Else If (anis(n)\antype = 6) ; PPFR anis(n)\ancur = anis(n)\ancur - 1 If (anis(n)\ancur = (anis(n)\anstart-1)) anis(n)\ancur = anis(n)\ancur + 2 anis(n)\antype = 5 If (anis(n)\ancur > anis(n)\anend) Then anis(n)\ancur = anis(n)\ancur - 1 End If End If End If If (anis(n)\antype = 7) ; PPRF anis(n)\ancur = anis(n)\ancur - 1 If (anis(n)\ancur = (anis(n)\anstart-1)) anis(n)\ancur = anis(n)\ancur + 2 anis(n)\antype = 6 If (anis(n)\ancur > anis(n)\anend) Then anis(n)\ancur = anis(n)\ancur - 1 End If Else If (anis(n)\antype = 8) ; PPRR anis(n)\ancur = anis(n)\ancur + 1 If (anis(n)\ancur = anis(n)\anend) anis(n)\ancur = anis(n)\ancur - 2 anis(n)\antype = 5 If (anis(n)\ancur < anis(n)\anstart) Then anis(n)\ancur = anis(n)\ancur + 1 End If End If End If End If End If End If n = n + 1 Wend End Function Function MapFreeMem () Local n For n = 0 To (mapnumblockstr-1) Delete blks(n) Next For n = 1 To (mapnumanims) Delete anis(n) Next For n = 0 To (mapnumblockgfx-1) FreeImage tilegfx(n) Next End Function Function MapClickmask (x, y, xory) x = x Mod mapblockgapx y = y Mod mapblockgapy If (x >= mapblockwidth And xory = 0) Then Return 0 If (x >= mapblockwidth And xory = 1) If (y < mapblockstaggery) Return -1 Else Return 1 End If End If If (y >= mapblockheight And xory = 1) Then Return 1 If (y >= mapblockheight And xory = 0) If (x < mapblockstaggerx) Return -1 Else Return 0 End If End If If (ReadPixel (x, y, ImageBuffer (tilegfx(mapclickmask))) = maptransval) If (x < (mapblockwidth/2) And xory = 0) Then Return -1 If (x >= (mapblockwidth/2) And xory = 0) Then Return 0 If (y < (mapblockheight/2) And xory = 1) Then Return -1 If (y >= (mapblockheight/2) And xory = 1) Then Return 1 End If Return 0 End Function Function MapGetXOffset (xpix, ypix) Local xb If (mapblockstaggerx Or mapblockstaggery) xpix = xpix+mapblockstaggerx ypix = ypix+mapblockstaggery xb = xpix/mapblockgapx If (mapclickmask) xb = xb+MapClickmask (xpix, ypix, 0) End If Else xb = xpix/mapblockgapx End If If (xb < 0) Then xb = 0 If (xb >= mapwidth) Then xb = mapwidth-1 Return xb End Function Function MapGetYOffset (xpix, ypix) Local yb If (mapblockstaggerx Or mapblockstaggery) xpix = xpix+mapblockstaggerx ypix = ypix+mapblockstaggery yb = ypix/mapblockgapy If (mapclickmask) yb = yb*2 yb = yb+MapClickmask (xpix, ypix, 1) End If Else yb = ypix/mapblockgapy End If If (yb < 0) Then yb = 0 If (yb >= mapheight) Then yb = mapheight-1 Return yb End Function Function MapLoad (mname$) Local fpt, maplen, mapid1, mapid2, mapid3, mapid4, mapcklen mapcurlyr = 0 mapnumanims = 0 mapblockstaggerx = 0 mapblockstaggery = 0 fpt = ReadFile (mname$) If MapReadByte (fpt) <> 70 maperror = 1 If MapReadByte (fpt) <> 79 maperror = 1 If MapReadByte (fpt) <> 82 maperror = 1 If MapReadByte (fpt) <> 77 maperror = 1 maplen = MapGetcksz (fpt) If MapReadByte (fpt) <> 70 maperror = 1 If MapReadByte (fpt) <> 77 maperror = 1 If MapReadByte (fpt) <> 65 maperror = 1 If MapReadByte (fpt) <> 80 maperror = 1 maplen = maplen - 4 While (maplen) mapid1 = MapReadByte (fpt) mapid2 = MapReadByte (fpt) mapid3 = MapReadByte (fpt) mapid4 = MapReadByte (fpt) mapcklen = MapGetcksz (fpt) ; Print "Found "+Chr$(mapid1)+Chr$(mapid2)+Chr$(mapid3)+Chr$(mapid4)+" length "+mapcklen+" bytes." maplen = maplen - mapcklen maplen = maplen - 8 mapchunkdone = 0 If mapid1 = Asc("M") And mapid2 = Asc("P") And mapid3 = Asc("H") And mapid4 = Asc("D") Then MapDecodeMPHD (fpt, mapcklen) If mapid1 = Asc("C") And mapid2 = Asc("M") And mapid3 = Asc("A") And mapid4 = Asc("P") Then MapDecodeCMAP (fpt, mapcklen) If mapid1 = Asc("B") And mapid2 = Asc("K") And mapid3 = Asc("D") And mapid4 = Asc("T") Then MapDecodeBKDT (fpt, mapcklen) If mapid1 = Asc("A") And mapid2 = Asc("N") And mapid3 = Asc("D") And mapid4 = Asc("T") Then MapDecodeANDT (fpt, mapcklen) If mapid1 = Asc("B") And mapid2 = Asc("G") And mapid3 = Asc("F") And mapid4 = Asc("X") Then MapDecodeBGFX (fpt, mapcklen) If mapid1 = Asc("B") And mapid2 = Asc("O") And mapid3 = Asc("D") And mapid4 = Asc("Y") Then MapDecodeLYR (fpt, mapcklen, 0) If mapid1 = Asc("L") And mapid2 = Asc("Y") And mapid3 = Asc("R") And mapid4 = Asc("1") Then MapDecodeLYR (fpt, mapcklen, 1) If mapid1 = Asc("L") And mapid2 = Asc("Y") And mapid3 = Asc("R") And mapid4 = Asc("2") Then MapDecodeLYR (fpt, mapcklen, 2) If mapid1 = Asc("L") And mapid2 = Asc("Y") And mapid3 = Asc("R") And mapid4 = Asc("3") Then MapDecodeLYR (fpt, mapcklen, 3) If mapid1 = Asc("L") And mapid2 = Asc("Y") And mapid3 = Asc("R") And mapid4 = Asc("4") Then MapDecodeLYR (fpt, mapcklen, 4) If mapid1 = Asc("L") And mapid2 = Asc("Y") And mapid3 = Asc("R") And mapid4 = Asc("5") Then MapDecodeLYR (fpt, mapcklen, 5) If mapid1 = Asc("L") And mapid2 = Asc("Y") And mapid3 = Asc("R") And mapid4 = Asc("6") Then MapDecodeLYR (fpt, mapcklen, 6) If mapid1 = Asc("L") And mapid2 = Asc("Y") And mapid3 = Asc("R") And mapid4 = Asc("7") Then MapDecodeLYR (fpt, mapcklen, 7) If (mapchunkdone = 0) While (mapcklen) MapReadByte (fpt) mapcklen = mapcklen - 1 Wend End If Wend CloseFile (fpt) End Function Function MapDecodeMPHD (fcpt, chklen) ; Print "MPHD" If (MapReadByte (fcpt) > 1) maperror = MER_MAPTOONEW Return -1 End If MapReadByte (fcpt) If (MapReadByte (fcpt) = 1) mapislsb = 1 Else mapislsb = 0 End If maptype = MapReadByte (fcpt) If (maptype > 3) maperror = MER_MAPTOONEW Return -1 End If chklen = chklen-4 mapwidth = MapReadShort (fcpt) mapheight = MapReadShort (fcpt) MapReadShort (fcpt) MapReadShort (fcpt) mapblockwidth = MapReadShort (fcpt) mapblockheight = MapReadShort (fcpt) mapdepth = MapReadShort (fcpt) mapblockstrsize = MapReadShort (fcpt) mapnumblockstr = MapReadShort (fcpt) mapnumblockgfx = MapReadShort (fcpt) Dim mappt (mapwidth, mapheight, mapmaxlayers) Dim tilegfx (mapnumblockgfx) Dim blks.BLKSTR (mapnumblockstr) chklen = chklen-20 If (chklen > 0) maptrans8 = MapReadByte (fcpt) maptransr = MapReadByte (fcpt) maptransg = MapReadByte (fcpt) maptransb = MapReadByte (fcpt) chklen = chklen-4 If (chklen > 0) mapblockgapx = MapReadShort (fcpt) mapblockgapy = MapReadShort (fcpt) mapblockstaggerx = MapReadShort (fcpt) mapblockstaggery = MapReadShort (fcpt) chklen = chklen-8 If (chklen > 0) mapclickmask = MapReadShort (fcpt) chklen = chklen-2 Else mapclickmask = 0 End If Else mapblockgapx = mapblockwidth mapblockgapy = mapblockheight mapblockstaggerx = 0 mapblockstaggery = 0 End If Else maptrans8 = 0 maptransr = 255 maptransg = 0 maptransb = 255 End If While (chklen) MapReadByte (fcpt) chklen = chklen - 1 Wend mapchunkdone = 1 End Function Function MapDecodeCMAP (fcpt, chklen) ; Print "CMAP" Local n Dim cmappt (chklen) For n = 0 To (chklen-1) cmappt(n) = MapReadByte (fcpt); Next mapchunkdone = 1 End Function Function MapDecodeBKDT (fcpt, chklen) ; Print "BKDT" Local n, mbsize For n = 0 To (mapnumblockstr-1) blks(n) = New BLKSTR blks(n)\bg = MapReadLong(fcpt) blks(n)\fg = MapReadLong(fcpt) blks(n)\fg2 = MapReadLong(fcpt) blks(n)\fg3 = MapReadLong(fcpt) If (maptype = 0) If (mapdepth = 15) mbsize = (mapblockwidth*mapblockheight*2) Else mbsize = (mapblockwidth*mapblockheight*(mapdepth/8)) End If blks(n)\bg = blks(n)\bg/mbsize blks(n)\fg = blks(n)\fg/mbsize blks(n)\fg2 = blks(n)\fg2/mbsize blks(n)\fg3 = blks(n)\fg3/mbsize End If blks(n)\user1 = MapReadLong(fcpt) blks(n)\user2 = MapReadLong(fcpt) blks(n)\user3 = MapReadShort(fcpt) blks(n)\user4 = MapReadShort(fcpt) blks(n)\user5 = MapReadByte(fcpt) blks(n)\user6 = MapReadByte(fcpt) blks(n)\user7 = MapReadByte(fcpt) l = MapReadByte (fcpt) blks(n)\tl = 0 If (l And 1) Then blks(n)\tl = 1 blks(n)\tr = 0 If (l And 2) Then blks(n)\tr = 1 blks(n)\bl = 0 If (l And 4) Then blks(n)\bl = 1 blks(n)\br = 0 If (l And 8) Then blks(n)\br = 1 blks(n)\trigger = 0 If (l And 16) Then blks(n)\trigger = 1 blks(n)\unused1 = 0 If (l And 32) Then blks(n)\unused1 = 1 blks(n)\unused2 = 0 If (l And 64) Then blks(n)\unused2 = 1 blks(n)\unused3 = 0 If (l And 128) Then blks(n)\unused3 = 1 chklen = chklen-32 Next While (chklen) MapReadByte (fcpt) chklen = chklen - 1 Wend mapchunkdone = 1 End Function Function MapDecodeANDT (fcpt, chklen) ; Print "ANDT" Local lastanim, n, strtpos, andtpos strtpos = FilePos(fcpt) andtpos = chklen Dim anis.ANISTR (1000) lastanim = 0 n = 1 While (lastanim = 0) andtpos = andtpos - 16 SeekFile (fcpt, strtpos+andtpos) anis(n) = New ANISTR anis(n)\antype = MapReadByte (fcpt) anis(n)\andelay = MapReadByte (fcpt) anis(n)\ancount = MapReadByte (fcpt) anis(n)\anuser = MapReadByte (fcpt) anis(n)\ancur = MapReadLong (fcpt) anis(n)\anstart = MapReadLong (fcpt) anis(n)\anend = MapReadLong (fcpt) If (maptype = 0) anis(n)\ancur = (anis(n)\ancur+chklen)/4 anis(n)\anstart = (anis(n)\anstart+chklen)/4 anis(n)\anend = (anis(n)\anend+chklen)/4 End If If (anis(n)\antype = 255) Then lastanim = 1 n = n + 1 mapnumanims = mapnumanims + 1 Wend Dim aniseq (andtpos/4) SeekFile (fcpt, strtpos) For n = 0 To ((andtpos-1)/4) aniseq(n) = MapReadLong (fcpt) If (maptype = 0) Then aniseq(n) = aniseq(n)/32 Next SeekFile (fcpt, strtpos+chklen) mapchunkdone = 1 End Function Function MapDecodeBGFX (fcpt, chklen) ; Print "BGFX" Local n, x, y, p, p2, pred, pgreen, pblue For n = 0 To (mapnumblockgfx-1) tilegfx(n) = CreateImage (mapblockwidth, mapblockheight) If (n = 0) SetBuffer ImageBuffer (tilegfx(n)) If (mapdepth = 8) p = maptrans8 WritePixel 0, 0, (cmappt(p*3) Shl 16) Or (cmappt((p*3)+1) Shl 8) Or (cmappt((p*3)+2)) Else WritePixel 0, 0, (maptransr Shl 16) Or (maptransg Shl 8) Or maptransb End If maptransval = ReadPixel (0, 0) End If If (mapdepth = 8) SetBuffer ImageBuffer (tilegfx(n)) LockBuffer ImageBuffer (tilegfx(n)) For y = 0 To (mapblockheight-1) For x = 0 To (mapblockwidth-1) p = MapReadByte(fcpt) chklen = chklen - 1 ; Color (cmappt(p*3), cmappt((p*3)+1), cmappt((p*3)+2)) ; Plot x, y WritePixelFast x, y, (cmappt(p*3) Shl 16) Or (cmappt((p*3)+1) Shl 8) Or (cmappt((p*3)+2)) Next Next UnlockBuffer ImageBuffer (tilegfx(n)) MaskImage tilegfx(n), cmappt(maptrans8*3), cmappt((maptrans8*3)+1), cmappt((maptrans8*3)+2) End If If (mapdepth = 15) SetBuffer ImageBuffer (tilegfx(n)) LockBuffer ImageBuffer (tilegfx(n)) For y = 0 To (mapblockheight-1) For x = 0 To (mapblockwidth-1) p = MapReadByte(fcpt) p2 = MapReadByte(fcpt) pred = (p Shr 2) Shl 3 pred = pred Or (pred Shr 5) pgreen = (p And 3) Shl 6 pgreen = pgreen Or ((p2 Shr 5) Shl 3) pgreen = pgreen Or (pgreen Shr 5) pblue = (p2 Shl 3) And 255 pblue = pblue Or (pblue Shr 5) chklen = chklen - 2 ; Color (cmappt(p*3), cmappt((p*3)+1), cmappt((p*3)+2)) ; Plot x, y WritePixelFast x, y, (pred Shl 16) Or (pgreen Shl 8) Or pblue Next Next UnlockBuffer ImageBuffer (tilegfx(n)) MaskImage tilegfx(n), maptransr, masptransg, maptransb End If If (mapdepth = 16) SetBuffer ImageBuffer (tilegfx(n)) LockBuffer ImageBuffer (tilegfx(n)) For y = 0 To (mapblockheight-1) For x = 0 To (mapblockwidth-1) p = MapReadByte(fcpt) p2 = MapReadByte(fcpt) pred = (p Shr 3) Shl 3 pred = pred Or (pred Shr 5) pgreen = (p And 7) Shl 5 pgreen = pgreen Or ((p2 Shr 5) Shl 2) pgreen = pgreen Or (pgreen Shr 6) pblue = (p2 Shl 3) And 255 pblue = pblue Or (pblue Shr 5) chklen = chklen - 2 ; Color (cmappt(p*3), cmappt((p*3)+1), cmappt((p*3)+2)) ; Plot x, y WritePixelFast x, y, (pred Shl 16) Or (pgreen Shl 8) Or pblue Next Next UnlockBuffer ImageBuffer (tilegfx(n)) MaskImage tilegfx(n), maptransr, masptransg, maptransb End If If (mapdepth = 24) SetBuffer ImageBuffer (tilegfx(n)) LockBuffer ImageBuffer (tilegfx(n)) For y = 0 To (mapblockheight-1) For x = 0 To (mapblockwidth-1) pred = MapReadByte(fcpt) pgreen = MapReadByte(fcpt) pblue = MapReadByte(fcpt) chklen = chklen - 3 ; Color (pred, pgreen, pblue) ; Plot x, y WritePixelFast x, y, (pred Shl 16) Or (pgreen Shl 8) Or pblue Next Next UnlockBuffer ImageBuffer (tilegfx(n)) MaskImage tilegfx(n), maptransr, masptransg, maptransb End If If (mapdepth = 32) SetBuffer ImageBuffer (tilegfx(n)) LockBuffer ImageBuffer (tilegfx(n)) For y = 0 To (mapblockheight-1) For x = 0 To (mapblockwidth-1) MapReadByte(fcpt) pred = MapReadByte(fcpt) pgreen = MapReadByte(fcpt) pblue = MapReadByte(fcpt) chklen = chklen - 4 ; Color (pred, pgreen, pblue) ; Plot x, y WritePixelFast x, y, (pred Shl 16) Or (pgreen Shl 8) Or pblue Next Next UnlockBuffer ImageBuffer (tilegfx(n)) MaskImage tilegfx(n), maptransr, masptransg, maptransb End If Next SetBuffer BackBuffer() While (chklen) MapReadByte (fcpt) chklen = chklen - 1 Wend mapchunkdone = 1 End Function Function MapDecodeLYR (fcpt, chklen, lyrnum) ; Print "LYR"+(lyrnum) Local n, x, y, rlecount, rleval If (maptype = 0) For y = 0 To (mapheight-1) For x = 0 To (mapwidth-1) mappt (x, y, lyrnum) = MapReadShort (fcpt) If (mappt (x, y, lyrnum) < 0) mappt (x, y, lyrnum) = mappt (x, y, lyrnum)/16 Else mappt (x, y, lyrnum) = mappt (x, y, lyrnum)/mapblockstrsize EndIf chklen = chklen-2 Next Next End If If (maptype = 1) For y = 0 To (mapheight-1) For x = 0 To (mapwidth-1) mappt (x, y, lyrnum) = MapReadShort (fcpt) chklen = chklen-2 Next Next End If If (maptype = 2) For y = 0 To (mapheight-1) x = 0 : While (x < mapwidth) rlecount = MapReadShort (fcpt) chklen = chklen-2 If (rlecount > 0) While (rlecount > 0) mappt (x, y, lyrnum) = MapReadShort (fcpt) chklen = chklen-2 x = x + 1 : rlecount = rlecount - 1 Wend Else rleval = MapReadShort (fcpt) chklen = chklen-2 While (rlecount < 0) mappt (x, y, lyrnum) = rleval x = x + 1 : rlecount = rlecount + 1 Wend End If Wend Next End If If (maptype > 2) Print "Sorry, unsupported use FMP0.5 or FMP1.0 for now" Stop End If While (chklen) MapReadByte (fcpt) chklen = chklen - 1 Wend mapchunkdone = 1 End Function Function MapGetcksz ( fcpt ) l = ReadByte (fcpt) l = l * 256 l = l + ReadByte (fcpt) l = l * 256 l = l + ReadByte (fcpt) l = l * 256 l = l + ReadByte (fcpt) Return l End Function Function MapReadLong (fcpt) Local l If (mapislsb = 1) l = ReadByte (fcpt) l = l + (ReadByte (fcpt)*256) l = l + (ReadByte (fcpt)*65536) l = l + (ReadByte (fcpt)*16777216) Else l = ReadByte (fcpt) l = l * 256 l = l + ReadByte (fcpt) l = l * 256 l = l + ReadByte (fcpt) l = l * 256 l = l + ReadByte (fcpt) End If Return l End Function Function MapReadShort (fcpt) Local l If (mapislsb = 1) l = ReadByte (fcpt) l = l + (ReadByte (fcpt)*256) Else l = ReadByte (fcpt) l = l * 256 l = l + ReadByte (fcpt) End If If (l > 32767) Then l = l -65536 Return l End Function Function MapReadByte (fcpt) Return ReadByte (fcpt) End Function