Full tileset support.

This commit is contained in:
KikooDX 2021-01-07 14:15:00 +01:00
parent b572b0f43d
commit ffc2b2d594
3 changed files with 7 additions and 4 deletions

View File

@ -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) */

View File

@ -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")

View File

@ -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);
}
}