lvl->width = xsz;
lvl->height = ysz;
lvl->cell_size = DEF_CELL_SIZE;
+ lvl->px = lvl->py = -1;
return 0;
}
struct cell *cell;
float *vecptr;
- lvl->fname = strdup(fname);
- if((lvl->dirname = malloc(strlen(fname) + 1))) {
-#ifndef LEVEL_EDITOR
- path_dir(lvl->fname, lvl->dirname);
-#endif
- }
-
if(!(ts = ts_load(fname))) {
fprintf(stderr, "failed to load level: %s\n", fname);
return -1;
ts_free_tree(ts);
return -1;
}
+
+ lvl->fname = strdup(fname);
+ if((lvl->dirname = malloc(strlen(fname) + 1))) {
+#ifndef LEVEL_EDITOR
+ path_dir(lvl->fname, lvl->dirname);
+#endif
+ }
+
lvl->cell_size = ts_get_attr_num(ts, "cellsize", DEF_CELL_SIZE);
if((vecptr = ts_get_attr_vec(ts, "player", 0))) {
node = (struct ts_node*)cell->next;
cell->next = 0;
- if(j <= 0 || cell[-1].type == CELL_SOLID) {
+ if(i >= lvl->height - 1 || cell[lvl->width].type == CELL_SOLID) {
cell->wall[0] = TILE_STRAIGHT;
}
- if(i <= 0 || cell[-lvl->width].type == CELL_SOLID) {
+ if(j >= lvl->width - 1 || cell[1].type == CELL_SOLID) {
cell->wall[1] = TILE_STRAIGHT;
}
- if(j >= lvl->width - 1 || cell[1].type == CELL_SOLID) {
+ if(i <= 0 || cell[-lvl->width].type == CELL_SOLID) {
cell->wall[2] = TILE_STRAIGHT;
}
- if(i >= lvl->height - 1 || cell[lvl->width].type == CELL_SOLID) {
+ if(j <= 0 || cell[-1].type == CELL_SOLID) {
cell->wall[3] = TILE_STRAIGHT;
}
ts_set_valuei(&attr->val, lvl->width);
ts_add_attr(root, attr);
+ if(lvl->cell_size && (attr = ts_alloc_attr())) {
+ ts_set_attr_name(attr, "cellsize");
+ ts_set_valuef(&attr->val, lvl->cell_size);
+ ts_add_attr(root, attr);
+ }
+
+ if(lvl->px >= 0 && lvl->px < lvl->width && lvl->py >= 0 && lvl->py < lvl->height) {
+ if((attr = ts_alloc_attr())) {
+ ts_set_attr_name(attr, "player");
+ ts_set_valueiv(&attr->val, 2, lvl->px, lvl->py);
+ ts_add_attr(root, attr);
+ }
+ }
+
for(i=0; i<lvl->height; i++) {
for(j=0; j<lvl->width; j++) {
cell = lvl->cells + i * lvl->width + j;