summaryrefslogtreecommitdiff
path: root/src/tilemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tilemap.c')
-rw-r--r--src/tilemap.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/tilemap.c b/src/tilemap.c
index 5660046..84d2509 100644
--- a/src/tilemap.c
+++ b/src/tilemap.c
@@ -8,6 +8,7 @@
#include "main.h"
#include "tilemap.h"
+#include "collision.h"
struct tilemap *tilemap = NULL, *next_tilemap = NULL;
@@ -58,7 +59,9 @@ struct tilemap *load_tilemap(void *data, size_t size) {
SDL_SetRenderTarget(renderer, tilemap->tileset);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
-
+
+ collision_T collision[256] = {0};
+
for (uint32_t count = sets->tilesets_count; count > 0; count--) {
int height = *(uint32_t *) str;
str += sizeof (uint32_t);
@@ -67,8 +70,14 @@ struct tilemap *load_tilemap(void *data, size_t size) {
goto fail;
}
void *tex = res_get_texture(str).data;
+ struct blob col = res_get_collision(str);
SDL_RenderCopy(renderer, tex, &(SDL_Rect) {0, 0, 128, height}, &(SDL_Rect) {0, y, 128, height});
+ if (col.size + y * 2 > 0xf0) {
+ fprintf(stderr, "warn: '%s' overflows tile properties\n", str);
+ col.size = 0xf0 - y * 2;
+ }
+ memcpy(collision + y * 2, col.data, col.size * sizeof (collision_T));
y += height;
str += len + 1;
@@ -78,9 +87,11 @@ struct tilemap *load_tilemap(void *data, size_t size) {
SDL_SetRenderTarget(renderer, tilemap->wang_tileset);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
-
- if (sets->tilesets_count) {
+
+ int wangs = 0;
+ if (sets->wang_count) {
int height = *(uint32_t *) str;
+ wangs = height / 8;
str += sizeof (uint32_t);
size_t len = strnlen(str, size);
if (len == size) {
@@ -88,13 +99,19 @@ struct tilemap *load_tilemap(void *data, size_t size) {
return NULL;
}
void *tex = res_get_texture(str).data;
+ struct blob col = res_get_collision(str);
SDL_RenderCopy(renderer, tex, &(SDL_Rect) {0, 0, 128, height}, &(SDL_Rect) {0, 0, 128, height});
+ if (col.size > 16) {
+ fprintf(stderr, "warn: '%s' overflows tile properties\n", str);
+ col.size = 16;
+ }
+ memcpy(collision + 0xf0, col.data, col.size * sizeof (collision_T));
str += len + 1;
size -= len + 4 + 1;
}
-
+
struct map const *const map = (void *) str;
if (map->width * map->height * map->layers > size - sizeof (struct map)) {
goto fail;
@@ -121,7 +138,7 @@ struct tilemap *load_tilemap(void *data, size_t size) {
}
}
- for (int tile = 0xf0; tile < 0x100; tile++) {
+ for (int tile = 0xf0; tile < 0xf0 + wangs; tile++) {
for (int y = 0; y < map->height - 1; y++) {
size_t const yy = y * map->width;
for (int x = 0; x < map->width - 1; x++) {