Codesnippets > 2D-snippets

Mappy Code

(1/2) > >>

MrTAToad:
This is the source code to my Mappy routine.

And a test program :


--- Code: ---LOCAL mapX%,mapY%,result%

LIMITFPS -1

result%=Mappy_LoadFile("Level01.FMP",0)
DEBUG "Layer Names : "+Mappy_GetLayerNames$()+"\n"
DEBUG "Map Width : "+Mappy_GetMapWidth()+"\n"
DEBUG "Map Height : "+Mappy_GetMapHeight()+"\n"
DEBUG "Map Depth : "+Mappy_GetMapDepth()+"\n"
DEBUG "Map Author : "+Mappy_GetAuthor$()+"\n"
DEBUG "Mappy Version : "+Mappy_Version()+"\n"
SELECT Mappy_GetMapFormat()
CASE 0
DEBUG "FMP 0.5\n"
CASE 1
DEBUG "FMP 1.0\n"
CASE 2
DEBUG "FMP 1.0 RLE\n"
ENDSELECT
IF Mappy_IsLSB()
DEBUG "Data is in LSB format\n"
ELSE
DEBUG "Data is not in LSB format\n"
ENDIF

DEBUG "Add new layer : "+Mappy_AddLayer(1)+"\n"
DEBUG "Number of layers : "+Mappy_GetNumberOfLayers()+"\n"
DEBUG "Delete a layer : "+Mappy_DeleteLayer(1)+"\n"
DEBUG "Number of layers : "+Mappy_GetNumberOfLayers()+"\n"
DEBUG "Map Block Width : "+Mappy_GetBlockWidth()+"\n"
DEBUG "Map Block Height : "+Mappy_GetBlockHeight()+"\n"
DEBUG "Number Of Blocks : "+Mappy_GetNumberOfBlocks()+"\n"

//loadMappyGraphics()
mapX%=0
mapY%=0

WHILE TRUE
DrawMap(mapX%,mapY%,0,0,640,480)
// DrawMap(mapX%,mapY%,320,0,319,239)
// DrawMap(mapX%,mapY%,0,240,319,239)
// DrawMap(mapX%,mapY%,320,240,319,239)

PRINT "Result : "+result%,0,0
PRINT "Collision : "+Mappy_Collision(29*16,36*16,29*16,37*16),0,16

IF KEY(203)
IF mapX%>0 THEN DEC mapX%
ELSE
IF KEY(205)
INC mapX%
ENDIF
ENDIF

IF KEY(200)
IF mapY%>0 THEN DEC mapY%
ELSE
IF KEY(208)
INC mapY%
ENDIF
ENDIF

SHOWSCREEN

DEBUG "JJ\n"
Mappy_UpdateAnimations()
WEND

END

FUNCTION loadMappyGraphics%:
LOCAL l%
LOCAL name$
LOCAL num$

SETTRANSPARENCY 0
FOR l%=1 TO Mappy_GetNumberOfBlocks()-1
num$="000000"+l%
name$="Media/MappyGraphics/G"+MID$(num$,LEN(num$)-6,6)+".png"
IF DOESFILEEXIST(name$)=FALSE
DEBUG "Not found : "+name$+"\n"
RETURN FALSE
ELSE
LOADSPRITE name$,l%
ENDIF
NEXT

RETURN TRUE
ENDFUNCTION

--- End code ---

Quentin:
Wow! This looks like great work :)

Do you have an example map to play with?

MrTAToad:
These should work fine.

Isometric maps wont work (at least not until a map drawing system is done), because its not an area that I have knowledge about.

Scott_AW:
Great, I'll be sure to check this out and get back to you on it....

And I tried to give it a shot, but said "mapdefs.h: no such file or directory" then followed by a crazy compiler fit, but I figured that was because of the missing header file.
 

MrTAToad:
The mapdefs.h file is included in the other post.  It goes in the same place as the project file.

I've included my project file now :)

Navigation

[0] Message Index

[#] Next page

Go to full version