diff --git a/src/editing_area/draw.c b/src/editing_area/draw.c index e3b1b24..1f25869 100644 --- a/src/editing_area/draw.c +++ b/src/editing_area/draw.c @@ -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); } } }