~kikoodx/sle

dcd4afc52009147957dcc48fb1e2c61219381284 — KikooDX 3 years ago 42b166b
fix: level drawing was broken
1 files changed, 23 insertions(+), 22 deletions(-)

M src/editing_area/draw.c
M src/editing_area/draw.c => src/editing_area/draw.c +23 -22
@@ 15,28 15,29 @@ void level_draw(struct Level level, struct Options options,
	for (x = 0; x < level.width; x += 1) {
		for (y = 0; y < level.height; y += 1) {
			const int tile_index = x + y * level.width;
			if (tile_index &&
			    tile_index < options.tileset_width *
			                     options.tileset_height) {
				const int tile =
				    level.data[x + y * level.width];
				const Rectangle tile_rect = {
				    (int)(tile %
				          options.tileset_width) *
					options.tile_width,
				    (int)(tile /
				          options.tileset_height) *
					options.tile_height,
				    options.tile_width,
				    options.tile_height};
				const Vector2 tile_pos = {
				    x * options.tile_width +
					options.editor_draw_offset_x,
				    y * options.tile_height +
					options.editor_draw_offset_y};
				DrawTextureRec(tileset, tile_rect,
				               tile_pos, WHITE);
			}
			/* if tile index is out of bound, skip */
			if (tile_index >= level.width *
			                      level.height)
				continue;
			const Tile tile =
			    level.data[x + y * level.width];
			/* if tile is not in tileset, skip */
			if (!tile || tile >= options.tileset_width * options.tileset_height)
				continue;

			const Rectangle tile_rect = {
			    (int)(tile % options.tileset_width) *
				options.tile_width,
			    (int)(tile / options.tileset_height) *
				options.tile_height,
			    options.tile_width, options.tile_height};
			const Vector2 tile_pos = {
			    x * options.tile_width +
				options.editor_draw_offset_x,
			    y * options.tile_height +
				options.editor_draw_offset_y};
			DrawTextureRec(tileset, tile_rect, tile_pos,
			               WHITE);
		}
	}
}