summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-28 21:43:24 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-29 23:32:07 (EDT)
commit2089d501882f927f8d8dd932dd1b167f722ae1cd (patch)
tree9468629348c9b3442b8c4943951b29ff8873af85
parent6fa5445fc076d7af82318c738dbd15a20f75ae56 (diff)
downloaddodge-balls-2089d501882f927f8d8dd932dd1b167f722ae1cd.zip
dodge-balls-2089d501882f927f8d8dd932dd1b167f722ae1cd.tar.gz
dodge-balls-2089d501882f927f8d8dd932dd1b167f722ae1cd.tar.bz2
[WIP] map: Merge wall tiles into hor/vert lines
-rw-r--r--src/map.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/map.c b/src/map.c
index f33782f..0a093ee 100644
--- a/src/map.c
+++ b/src/map.c
@@ -32,6 +32,11 @@
#include "output.h"
#include "xml.h"
+struct db_wall {
+ SDL_Rect rect;
+ struct db_wall *next;
+};
+
struct db_map_layer {
Uint32 *tiles;
char *encoding;
@@ -74,7 +79,8 @@ struct db_map {
struct db_ball *ball_head;
struct db_ball *ball_tail;
Uint8 *p_col;
- Uint8 *b_col;
+ struct db_wall *wall_head;
+ struct db_wall *wall_tail;
};
static char *
@@ -771,6 +777,9 @@ _db_map_set_collision_tiles(struct db_map *map)
struct db_map_layer *layer;
int i;
int gid;
+ Uint8 *b_col;
+ int x;
+ int y;
db_dbg("Allocating %d bit field elements", (map->w * map->h + 7) / 8);
map->p_col = calloc((map->w * map->h + 7) / 8, sizeof(*map->p_col));
@@ -778,8 +787,8 @@ _db_map_set_collision_tiles(struct db_map *map)
db_err("Failed to allocate memory");
return;
}
- map->b_col = calloc((map->w * map->h + 7) / 8, sizeof(*map->p_col));
- if (map->b_col == NULL) {
+ b_col = calloc((map->w * map->h + 7) / 8, sizeof(*map->p_col));
+ if (b_col == NULL) {
db_err("Failed to allocate memory");
free(map->p_col);
return;
@@ -798,7 +807,31 @@ _db_map_set_collision_tiles(struct db_map *map)
map->p_col[i / 8] |= 1 << (i % 8);
}
if (db_tile_ball_collides(map->tileset_head, gid)) {
- map->b_col[i / 8] |= 1 << (i % 8);
+ b_col[i / 8] |= 1 << (i % 8);
+ }
+ }
+ }
+
+ for (y = 0; y < map->h; ++y) {
+ for (x = 0; x < map->w; ++x) {
+ i = y * map->w + x;
+ if ((b_col[i / 8] & (1 << (i % 8))) != 0) {
+ if (x > 0 && map->walls[i] != NULL) {
+ ++map->walls[i - 1].rect.w;
+ map->walls[i] = map->walls[i - 1];
+ continue;
+ }
+ map->wall_tail = calloc(1,
+ sizeof(*map->wall_tail));
+ if (map->wall_tail == NULL) {
+ db_err("Failed to allocate memory");
+ free(map->p_col);
+ free(b_col);
+ return;
+ }
+ if (map->wall_head == NULL) {
+ map->wall_head = map->wall_tail;
+ }
}
}
}