summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-02-17 16:39:25 (EST)
committer P. J. McDermott <pjm@nac.net>2013-02-17 16:42:41 (EST)
commit12b4f785f2bfccce59eb80378a76bf36bef6ff55 (patch)
tree69f202d5fe228b1589b7520eaa7eef0bd5ff0bd3 /src
parente5b4399a3cdbb259236e6d98896abc706fc93c1d (diff)
downloadoverworld-rpg-12b4f785f2bfccce59eb80378a76bf36bef6ff55.zip
overworld-rpg-12b4f785f2bfccce59eb80378a76bf36bef6ff55.tar.gz
overworld-rpg-12b4f785f2bfccce59eb80378a76bf36bef6ff55.tar.bz2
Add map exits to a collisions array.
Diffstat (limited to 'src')
-rw-r--r--src/resources/map.c16
-rw-r--r--src/resources/map.h15
2 files changed, 30 insertions, 1 deletions
diff --git a/src/resources/map.c b/src/resources/map.c
index c1a33bf..4b2b9ac 100644
--- a/src/resources/map.c
+++ b/src/resources/map.c
@@ -160,6 +160,8 @@ map_get_layer(struct map *m, const char *name)
void
map_add_exit(struct map *m, struct map_exit *e)
{
+ int i, j;
+
e->next = NULL;
if (m->map_exits_head == NULL) {
m->map_exits_head = e;
@@ -167,6 +169,13 @@ map_add_exit(struct map *m, struct map_exit *e)
m->map_exits_tail->next = e;
}
m->map_exits_tail = e;
+
+ for (i = 0; i < e->width; ++i) {
+ for (j = 0; j < e->height; ++j) {
+ m->collisions[j * m->width + i].type = COLLISION_EXIT;
+ m->collisions[j * m->width + i].data.e = e;
+ }
+ }
}
static struct tileset *
@@ -254,6 +263,13 @@ tmx_map_start(void *pv, const char *name, const char **attr)
xml_get_int_attr(p, attr, "height", &m->height, 1);
xml_get_int_attr(p, attr, "tilewidth", &m->tilewidth, 1);
xml_get_int_attr(p, attr, "tileheight", &m->tileheight, 1);
+ m->collisions = malloc(m->width * m->height *
+ sizeof(*m->collisions));
+ if (m->collisions == NULL) {
+ return;
+ }
+ memset(m->collisions, 0, m->width * m->height *
+ sizeof(*m->collisions));
xml_node_push(p, m, tmx_map_el_start, tmx_map_end, NULL);
} else {
xml_unexpected_start_tag(p, name, "map");
diff --git a/src/resources/map.h b/src/resources/map.h
index bf225de..e088161 100644
--- a/src/resources/map.h
+++ b/src/resources/map.h
@@ -35,6 +35,19 @@ struct layer {
char *compression;
char *raw_data;
};
+struct map_collision {
+ enum {
+ COLLISION_NONE = 0,
+ COLLISION_CHAR,
+ COLLISION_OBJ,
+ COLLISION_EXIT
+ } type;
+ union {
+/* struct character *c;*/
+ Uint8 o;
+ struct map_exit *e;
+ } data;
+};
struct map_exit {
struct map *map;
int x;
@@ -69,7 +82,7 @@ struct map {
struct map_tileset *tilesets_head;
struct map_tileset *tilesets_tail;
struct layer layers[LAYERS_MAX];
- Uint8 *collision;
+ struct map_collision *collisions;
struct map_exit *map_exits_head;
struct map_exit *map_exits_tail;
int cur_ts_firstgid;