From ffc2b2d594629c1f2b0141cde6692d36c354a480 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Thu, 7 Jan 2021 14:15:00 +0100 Subject: [PATCH] Full tileset support. --- include/tiles.h | 3 ++- levels/create_demo.lua | 5 +++-- src/level.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/tiles.h b/include/tiles.h index 4c16dc3..43ff003 100644 --- a/include/tiles.h +++ b/include/tiles.h @@ -1,6 +1,7 @@ #ifndef _DEF_TILES #define _DEF_TILES -#define TILE_AT(x, y) (x + y * 8) +#define TILESET_WIDTH 16 +#define TILE_AT(x, y) (x + y * TILESET_WIDTH) typedef unsigned char Tile; /* the tile ID */ typedef unsigned char Tile_flags; /* the tile properties (bitmask) */ diff --git a/levels/create_demo.lua b/levels/create_demo.lua index adc7953..ebe906d 100755 --- a/levels/create_demo.lua +++ b/levels/create_demo.lua @@ -6,8 +6,9 @@ local function create_random_level(width, height, layers) io.write(height, "\n") for i = 1, layers, 1 do for r = 1, width * height, 1 do - io.write(math.ceil(math.random() * 4) * math.floor(math.random() * 1.5)) - io.write("\n") + local var = math.ceil(math.random() * 4) * math.floor(math.random() * 1.5) + if var ~= 0 then var = var + math.floor(math.random() * 4) * 16 end + io.write(var, "\n") end if i ~= layers then io.write("n\n") diff --git a/src/level.c b/src/level.c index f1e2eac..33a20aa 100644 --- a/src/level.c +++ b/src/level.c @@ -45,7 +45,8 @@ void layer_draw(const Level *level, Camera *camera, uint layer_id) { (x * TILE_SIZE / VEC_PRECISION - camera->offset.x) * SCALE, (y * TILE_SIZE / VEC_PRECISION - camera->offset.y) * SCALE }; dsubimage(tl.x, tl.y, &img_tileset, - tile * TILE_PX_SIZE, 0 * TILE_PX_SIZE, + tile % TILESET_WIDTH * TILE_PX_SIZE, + tile / TILESET_WIDTH * TILE_PX_SIZE, TILE_PX_SIZE, TILE_PX_SIZE, 0); } }