From f158a79d0e8a2158f843ecfc5d7eaaa620828679 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 17 Feb 2013 20:44:32 -0500 Subject: Support collision and unknown map layers. --- (limited to 'src') diff --git a/src/main.c b/src/main.c index 3512535..fa7c7f6 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ main(void) init(); - map = map_get("data/forest1.simple.tmx"); + map = map_get("data/forest1.tmx"); debug("Map dimensions: %dx%d", map->width, map->height); for (ts = map->tilesets_head; ts != NULL; ts = ts->next) { debug("Tileset name: %s", ts->tileset->name); diff --git a/src/resources/map.c b/src/resources/map.c index 67b00cb..2cc2f2a 100644 --- a/src/resources/map.c +++ b/src/resources/map.c @@ -155,6 +155,8 @@ map_get_layer(struct map *m, const char *name) return &m->layers[LAYER_CHAR_TOP]; } else if (strcmp(name, "obj-high") == 0) { return &m->layers[LAYER_OBJ_HIGH]; + } else if (strcmp(name, "collision") == 0) { + return &m->layers[LAYER_COLLISION]; } else if (strcmp(name, "weather") == 0) { return &m->layers[LAYER_WEATHER]; } else { @@ -355,8 +357,14 @@ tmx_map_el_start(void *pv, const char *name, const char **attr) xml_get_string_attr(p, attr, "name", &ly_name, 1); ly = map_get_layer(m, ly_name); free(ly_name); - ly->map = m; - xml_node_push(p, ly, tmx_layer_el_start, tmx_layer_end, NULL); + if (ly != NULL) { + ly->map = m; + xml_node_push(p, ly, tmx_layer_el_start, tmx_layer_end, + NULL); + } else { + xml_node_push(p, NULL, tmx_unused_start, tmx_layer_end, + NULL); + } } else if (xml_check_tag(name, "objectgroup")) { xml_node_push(p, m, tmx_objectgroup_el_start, tmx_objectgroup_end, NULL); diff --git a/src/resources/map.h b/src/resources/map.h index ba264de..02733bc 100644 --- a/src/resources/map.h +++ b/src/resources/map.h @@ -12,6 +12,7 @@ enum layer_id { LAYER_OBJ_MID, LAYER_CHAR_TOP, LAYER_OBJ_HIGH, + LAYER_COLLISION, LAYER_WEATHER, LAYERS_MAX }; -- cgit v0.9.1