CDXMappy - documentation

This is the documentation for the SDLMappy class, designed for SDL (www.###).
It is based on original documentation of CDXMappy.


SDLMappy handles .FMP files created by Mappy Win32 Editor, (C) Robin Burrows. The current official Mappy Homepage is: http://www.geocities.com/SiliconValley/Vista/7336/robmpy.htm, with mirrors at http://www.rbsite.freeserve.co.uk/robmpy.htm and (if all else fails) http://surf.to/mappy

SDLMappy is based on original sources from Robin Burrows, was ported and modified for CDX by Ioannis Karagiorgos and then ported and modified for SDL by Regis Quercioli

Known problems:

  • 8 bits modes:

  • Displaying maps in 8-bit modes is not supported!
  • SetColorKey:

  • SetColorKey is not implemented in SDLMappy, the default ColorKey for transparency is the one of the first block (block n°0 - and this block must be blank).
  • MapDrawFG:

  • MapDrawFG is not implemented in SDLMappy, because I don't understand its purpose...


    Tutorial


    Here is a little code tutorial on how to use SDLMappy in your projects: 

    Initializing

    First of all you have to create your SDLMappy object: 

        SDLMappy * Map = new SDLMappy;

    Next, load your map: 

        if( Map->LoadMap("Map.fmp" , 0 , 0 , 320 , 200 )  == -1 )
            printf("Could not load map.fmp!" ); 

    When the map loading fails, it returns -1. LoadMap wants to have the filename of the map, the x/y coordinates of the map on the screen (where drawing will start, upper-left hand corner -- usually 0,0) and the visible map dimensions (width/height). 

    If you want a parallax surface, call 

       if( Map->CreateParallax( "parallax.bmp" ) == SDL_FALSE )
            printf( "Could not load parallax bitmap parallax.bmp" ); 

    Unlike CDXMappy the parallax surface size don't need to be a multiple of the map block size (its dimensions can be totally indifferent) !!! 

    If your Map is using animated tiles then you have to initialize the animations: 

        Map->MapInitAnims( ); 

    Thats all there has to be done for initialization. 

    Drawing

    Here are the functions needed to draw the map. 

    If you are using animated tiles, first call Map->MapUpdateAnims( ); 

        Then, call Map->MapMoveTo( x , y ) to move the map at the desired pixel position. 

    If you are using a parallax surface, you have to draw it first, for example: 

        if( Map->DrawParallax( SDLSurface * Surface ) == -1 )
            Map->RestoreParallax(); 

        Map->MapDrawBG( SDLSurface * Surface ) draws the background layer
        Map->MapDrawBGT( SDLSurface * Surface ) draws the background layer transparently (using the default color key) 
     


    Map Methods


    int LoadMap (char * Filename , int x , int y , int Width , int Height);

    Loads the map with the path and name specified into memory so it can be used. This function must be used before calling other Mappy functions. 

    Returns 0 on success, -1 on failure. 

    x/y are the output position of the map on the screen.
    Width/Height are the visible size of the map on the screen
    CAUTION:  loading a high/true colour map on an 8bit screen takes a painfully long time.

    void MapInitAnims (void);

    Resets animations to their initial values. 


    void MapUpdateAnims (void);

    Increments animations. Generally used once during an update loop before drawing. 


    int MapDrawBG (SDLSurface* s);

    MapDrawBG draws the background layer without transparency, so it will completely overwrite the specified area. 

    int MapDrawBGT (SDLSurface* s);

    MapDrawBGT draws the background layer with transparency. Any block whose tile is tile 0, or pixels of the transparent color in all blocks, won't overwrite be drawn. 

    int MapChangeLayer (int layernumber);

    This changes to a different map layer, returns -1 if failed, or the new layer number (0 to 7) if successful. 

    int MapGetTile (int x, int y);

    Returns the content of a block at position x,y. The x and y paramaters are the offset from the left and top of the map in BLOCKS, NOT pixels. 

    If return value is positive, the cell contains a block. If return value is negative, the cell contains animation. 

    BLKSTR * MapGetBlock (int x, int y);

    Returns a BLKSTR pointer, useful for collision detection and examining a block structure. Note: the x and y paramaters are the offset from the left and top of the map in BLOCKS, NOT pixels. Example: 

    BLKSTR * myblkstr;
    myblkstr = MapGetBlock (xoffinblocks, yoffinblocks);
    if (myblkstr->tl) { top left collision is set for this block } 

    MapSetBlock (int x, int y, int strvalue);

    The x and y paramaters are the offset from the left and top of the map in BLOCKS, NOT pixels. If strvalue is positive, the cell is set to that block structure. If strvalue is negative the cell is set to that anim structure - 1 (ie if you want to put anim 3 in, strvalue would be -4). 

    WORD GetMapBPP( void );

    This call returns the color depth of the current map. 

    WORD GetMapWidth( void );

    This call returns the width of the map in pixels. 

    WORD GetMapHeight( void );

    This call returns the height of the map in pixels. 

    WORD GetMapWidthInBlocks( void );

    This call returns the width of the map in blocks. 

    WORD GetMapHeightInBlocks( void );

    This call returns the height of the map in blocks. 

    WORD GetMapBlockWidth( void );

    Thie call returns the width of one map block, in pixels. 

    WORD GetMapBlockHeight( void );

    Thie call returns the height of one map block, in pixels. 

    void MapMoveTo( int x , int y );

    This call moves the map output to offset x,y. It takes into account invalid coordinates, and will modify them accordingly so as to not scroll off the edges of the map and cause a crash. 

    int MapGetXPosition( void );

    This call returns the current X offset of the map, in pixels, from the upper-left hand corner. 

    int MapGetYPosition( void );

    This call returns the current Y offset of the map, in pixels, from the upper-left hand corner. 

    int DrawParallax( CDXSurface * Surface );

    This call draws the parallax surface on the selected surface.

    BOOL CreateParallax( void );

    This call creates and load a parallax surface from bitmap file Filename
    Return value = TRUE if it was successful, otherwise FALSE.



    If you have problems with CDXMappy, please e-mail me
    If you have problems/questions about how Mappy works or the Mappy editor, please contact the author Robin Burrows or look at the Mappy Homepage. The current official Mappy Homepage is: http://www.geocities.com/SiliconValley/Vista/7336/robmpy.htm, with mirrors at http://www.rbsite.freeserve.co.uk/robmpy.htm and (if all else fails) http://surf.to/mappy

September 2000 , Regis Quercioli