Skip to content
Steven Arnow edited this page Jul 24, 2013 · 16 revisions

The darnit map API handles libdarnit map files (LDMZ.)

DARNIT_MAP_REF

This type points to an array of key-value propery pairs.

  • const char *d_map_prop(DARNIT_MAP_REF *prop, const char *key);

DARNIT_MAP_OBJECT

typedef struct {
        unsigned int x;
        unsigned int y;
        unsigned int l;
        DARNIT_MAP_REF *ref;
} DARNIT_MAP_OBJECT;
  • x - The X-coordinate for the object in tiles
  • y - The Y-coordinate for the object in tiles
  • l - Index of the layer to place the object on
  • ref - The list of properties for the object (see DARNIT_MAP_REF).

DARNIT_MAP_LAYER

typedef struct {
        DARNIT_TILEMAP *tilemap;
        DARNIT_TILESHEET *ts;
        DARNIT_MAP_REF *ref;
        unsigned int offset_x;
        unsigned int offset_y;
        unsigned int tile_w;
        unsigned int tile_h;
        DARNIT_MAP_REF **ts_ref;
        unsigned int ts_refs;
} DARNIT_MAP_LAYER;

ts_ref is a list of properties for tiles in the tileset used by this layer. This array may not cover the entire tileset, so you have to do bounds checking yourself with ts_refs.

  • DARNIT_TILEMAP *tilemap - The tilemap for this layer
  • DARNIT_TILESHEET *ts - The tilesheet used to draw the tilemap for this layer
  • DARNIT_MAP_REF *ref - The list of properties for this layer
  • offset_x - For othogonal maps, this is the amount to offset the rendering of the map with, on the X axis.
  • offset_y - For orthogonal maps, this is the amount to offset the rendering of the map with, on the Y axis.
  • tile_w - The width of a tile
  • tile_h - The height of a tile
  • DARNIT_MAP_REF **ts_ref - A list of properties for the tiles in the tileset used by this layer. May not have an entry for every tile. One entry in the array per tile.
  • ts_refs - The number of entries in the list of tile properties.

DARNIT_MAP

typedef struct {
        DARNIT_MAP_LAYER        *layer;
        const unsigned int      layers;
        DARNIT_MAP_OBJECT       *object;
        const unsigned int      objects;
        DARNIT_MAP_REF          *prop;
        DARNIT_MAP_STRINGDATA   *stringdata;
        DARNIT_MAP_REF          *stringrefs;

        const int               cam_x;
        const int               cam_y;
        const unsigned int      isometric;
} DARNIT_MAP;
  • DARNIT_MAP_LAYER *layer - Points to an array of DARNIT_MAP_LAYER containing per-layer information like tiledata, the tilemap for the layer etc.
  • layers - The number of layers in the map
  • DARNIT_MAP_OBJECT *object - Points to an array of DARNIT_MAP_OBJECT containing information about objects stored on the map (coordinates, key-value property information.)
  • objects - Number of objects on the map
  • DARNIT_MAP_REF - key-value properties for the map file
  • stringdata - Internal, don't touch
  • stringrefs - Internal, don't touch
  • cam_x - X coordinate for the camera on the map
  • cam_y - Y coordinate for the camera on the map
  • isometric - Set to 1 if the map is isometric, 0 if not.

Functions

d_map_prop

const char *d_map_prop(DARNIT_MAP_REF *prop, const char *key);

Searches a DARNIT_MAP_REF for the property key and returns the property value.

Arguments

  • prop - A DARNIT_MAP_REF that points to a storage of property value to look in for key
  • key - A string containing the name of the property you want to get from prop

Return value

Returns the property value on success, "NO SUCH KEY" if key was not found. A valid string is always returned.

d_map_load

DARNIT_MAP *d_map_load(const char *fname);

Loads a map with path fname and returns a DARNIT_MAP. Only LDMZ files are supported.

Arguments

  • fname - The path to the map file that you want to load
  • tile_w - The tile width to use instead of the one in the map
  • tile_h - The tile height to use instead of the one in the map

Return value

On failure, NULL is returned. Anything else is a valid DARNIT_MAP resource.

d_map_load_override

DARNIT_MAP *d_map_load_override(const char *fname, int tile_w, int tile_h);

Loads a map with path fname and returns a DARNIT_MAP. Only LDMZ files are supported. Unlike d_map_load, this function allows you to override tile size. Useful for when you want to use a higher/lower resolution tilesheet.

Arguments

  • fname - The path to the map file that you want to load
  • tile_w - The tile width you want to use instead of the width specified in the map
  • tile_h - The tile width you want to use instead of the width specified in the map

Return value

On failure, NULL is returned. Anything else is a valid DARNIT_MAP resource.

d_map_unload

DARNIT_MAP *d_map_unload(DARNIT_MAP *map);

Unloads map and returns a NULL-pointer for compact pointer clearing.

Arguments

  • map - The map to unload

Return value

Returns NULL for compact pointer clearing.

d_map_camera_move

void d_map_camera_move(DARNIT_MAP *map, int x, int y);

Moves the camera for the tilesets on all the layers in the map to x,y

Arguments

  • map - The map to move the tileset cameras on
  • x - The X-position to move the camera to
  • y - The Y-position to move the camera to

Return value None.

Clone this wiki locally