Allow for custom chunk height

This commit is contained in:
shylie 2025-07-16 01:13:37 -04:00
parent 2c0dc1efd3
commit 1b6c73f117
2 changed files with 11 additions and 4 deletions

View File

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

View File

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