Update example to use latest library features

This commit is contained in:
shylie 2025-07-23 07:18:56 -04:00
parent d02bc5f0fd
commit d4d6a140ef
2 changed files with 16 additions and 13 deletions

View File

@ -7,7 +7,7 @@ local gx = 0
local gy = 0 local gy = 0
local angle = 0 local angle = 0
local scale = 1 local scale = 1
local dist = 4 local dist = 5
local atlas = { local atlas = {
water = love.graphics.newQuad(1, 1, 8, 8, tex), water = love.graphics.newQuad(1, 1, 8, 8, tex),
@ -18,27 +18,32 @@ local atlas = {
snow = love.graphics.newQuad(11, 11, 8, 8, tex), snow = love.graphics.newQuad(11, 11, 8, 8, tex),
} }
local alpha = 0.75
local colors = {} local colors = {}
function colors.water(layer) function colors.water(layer)
return 0.1, layer / 16, layer / 8 return 0.1, layer / 16, layer / 8, alpha
end end
function colors.sand(layer) function colors.sand(layer)
return layer / 16 + 0.2, layer / 16 + 0.15, 0.4 return layer / 16 + 0.2, layer / 16 + 0.15, 0.4, alpha
end end
function colors.dirt(layer) function colors.dirt(layer)
if layer < 16 then if layer < 16 then
return layer / 40, layer / 80, 0.1 return layer / 40, layer / 80, 0.1, alpha
else else
return 0.1, layer / 50 + 0.1, 0.1 return 0.1, layer / 50 + 0.1, 0.1, alpha
end end
end end
function colors.stone(layer) function colors.stone(layer)
local value = layer / 48 - 0.2 local value = layer / 48 - 0.2
return value / 1.1, value, value * 1.1 return value / 1.1, value, value * 1.1, alpha
end end
function colors.snow(layer) function colors.snow(layer)
local value = layer / 48 + 0.25 local value = layer / 48 + 0.25
return value / 1.1, value, value * 1.1 return value / 1.1, value, value * 1.1, alpha
end
local function offset_map(_)
return -1, 1
end end
local z = zprite.zchunk.new(tex, 16 * 8, 40, dist * 2 + 1) local z = zprite.zchunk.new(tex, 16 * 8, 40, dist * 2 + 1)
@ -109,7 +114,7 @@ end
local function generate(x, y) local function generate(x, y)
local height = heightmap(x, y) local height = heightmap(x, y)
z:put(x, y, atlas.stone, math.ceil(height * 40), pick_color(height)) z:put(x, y, atlas.stone, math.ceil(height * 40), pick_color(height), offset_map)
end end
local generated = {} local generated = {}
@ -194,14 +199,12 @@ end
local t = love.math.newTransform() local t = love.math.newTransform()
function love.draw() function love.draw()
for _, chunk in pairs(z._chunks) do z._height_scale = 18 * scale
chunk.z._height_scale = 18 * scale
end
t:reset() t:reset()
t:translate(love.graphics.getWidth() / 2, love.graphics.getHeight() / 2) t:translate(love.graphics.getWidth() / 2, love.graphics.getHeight() / 2)
t:scale(scale, scale) t:scale(scale, scale)
t:rotate(angle) t:rotate(angle)
t:translate(gx - z._chunk_size, gy - z._chunk_size / 2) t:translate(gx - z._chunk_size / 2, gy - z._chunk_size / 2)
z:draw(t) z:draw(t)
end end

2
zprite

@ -1 +1 @@
Subproject commit 071b00d922ba6dcf76b5ecae0fdd5c01579482bf Subproject commit 0ac6791e752f5887cafe38e74e06ee86c76bec44