From 1b6c73f1170f170b5908a33d1b479477d89c8080 Mon Sep 17 00:00:00 2001 From: shylie Date: Wed, 16 Jul 2025 01:13:37 -0400 Subject: [PATCH] Allow for custom chunk height --- main.lua | 4 ++-- zprite/zchunk.lua | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main.lua b/main.lua index cdd8579..12a1dca 100644 --- a/main.lua +++ b/main.lua @@ -21,13 +21,13 @@ end local BIG_BLOCK = love.graphics.newQuad(24 * 9, 24 * 9, 24, 24, tex) -local z = require("zprite").zchunk.new(tex, 384) +local z = require("zprite").zchunk.new(tex, 384, 40) z._height_scale = 10 local function update_map() for i = -32, 32 do for j = -32, 32 do - local layers = love.math.simplexNoise(i * 0.02, j * 0.02) * 28 + 4 + local layers = love.math.simplexNoise(i * 0.02, j * 0.02) * 34 + 6 z:put(i * 24, j * 24, BIG_BLOCK, math.floor(layers) + 1, layers < 23 and dirt_color or mountain_color) coroutine.yield() end diff --git a/zprite/zchunk.lua b/zprite/zchunk.lua index 0b4c179..248e1f6 100644 --- a/zprite/zchunk.lua +++ b/zprite/zchunk.lua @@ -3,6 +3,7 @@ local zprite = require("zprite.zprite") ---@class zchunk ---@field private _chunks {integer: {z: zprite, x: integer, y: integer}} ---@field private _chunk_size integer +---@field private _chunk_height integer ---@field private _texture love.Image ---@field private _height_scale number local zchunk = {} @@ -10,11 +11,16 @@ zchunk.__index = zchunk ---@param texture love.Image ---@param chunk_size integer? -function zchunk.new(texture, chunk_size) +---@param chunk_height integer? +function zchunk.new(texture, chunk_size, chunk_height) chunk_size = chunk_size or 16 + chunk_height = chunk_height or 32 if chunk_size < 1 then error("chunk size must be at least 1") end + if chunk_height < 1 then + error("chunk height must be at least 1") + end if not texture then error("must have a texture") end @@ -23,6 +29,7 @@ function zchunk.new(texture, chunk_size) obj._chunks = {} obj._chunk_size = chunk_size + obj._chunk_height = chunk_height obj._texture = texture @@ -69,7 +76,7 @@ function zchunk:put(x, y, quad, layer_count, color_map, base_layer) local index = self:_chunk_index(x, y) if not self._chunks[index] then self._chunks[index] = { - z = zprite.new(self._texture, self._chunk_size * self._chunk_size * 32), + z = zprite.new(self._texture, self._chunk_size * self._chunk_size * self._chunk_height), x = math.floor(x / self._chunk_size), y = math.floor(y / self._chunk_size), }