From d02bc5f0fdcfe38a56c85e0b395a98b6b35bed45 Mon Sep 17 00:00:00 2001 From: shylie Date: Sat, 19 Jul 2025 12:12:15 -0400 Subject: [PATCH] Add easing function --- atlas.png | Bin 302 -> 321 bytes conf.lua | 3 +++ main.lua | 71 +++++++++++++++++++++++++++++------------------------- 3 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 conf.lua diff --git a/atlas.png b/atlas.png index e7ed724d92020c4e627ec437593379d388ffa0f8..292937c4b8539998a80be32fb2bcca295b8814da 100644 GIT binary patch delta 281 zcmV+!0p|X$0>J{1F@O6>L_t(oh3%EW5`!=ZM4{t9V!b(MR7- zD;DkeOrDnmZvp^11-Pkxr#Ya3hsT2I{T!_~5q zU6iIghDkt{prJ2~eG{)>z7qFDcFK8zhmkr&B-=^5Tcg;Wyc;<=r7m(}&N?e(W4i@& z=l)Tm5?7R6D`mAixvRuhu#`3TB%k<6mP-7@F+&I;gb+dqA!NV@+GKnHV0o3x00000 LNkvXXu0mjfvh#ch diff --git a/conf.lua b/conf.lua new file mode 100644 index 0000000..42ef7f5 --- /dev/null +++ b/conf.lua @@ -0,0 +1,3 @@ +function love.conf(t) + t.window.resizable = true +end diff --git a/main.lua b/main.lua index f90d519..7244385 100644 --- a/main.lua +++ b/main.lua @@ -3,8 +3,8 @@ local zprite = require("zprite") local tex = love.graphics.newImage("atlas.png") tex:setFilter("nearest", "nearest") -local x = 0 -local y = 0 +local gx = 0 +local gy = 0 local angle = 0 local scale = 1 local dist = 4 @@ -26,10 +26,10 @@ function colors.sand(layer) return layer / 16 + 0.2, layer / 16 + 0.15, 0.4 end function colors.dirt(layer) - if layer < 20 then + if layer < 16 then return layer / 40, layer / 80, 0.1 else - return 0.1, layer / 32 + 0.3, 0.1 + return 0.1, layer / 50 + 0.1, 0.1 end end function colors.stone(layer) @@ -37,19 +37,19 @@ function colors.stone(layer) return value / 1.1, value, value * 1.1 end function colors.snow(layer) - local value = layer / 48 + 0.2 + local value = layer / 48 + 0.25 return value / 1.1, value, value * 1.1 end -local z = zprite.zchunk.new(tex, 16 * 8, 32, dist * 2 + 1) +local z = zprite.zchunk.new(tex, 16 * 8, 40, dist * 2 + 1) local function layered_noise(x, y, layers, persistence) local freq = 1 local ampl = 1 local maxval = 0 local val = 0 - for i = 1, layers do - val = val + love.math.perlinNoise(x * freq, y * freq) * ampl + for _ = 1, layers do + val = val + love.math.simplexNoise(x * freq, y * freq) * ampl maxval = maxval + ampl @@ -60,8 +60,12 @@ local function layered_noise(x, y, layers, persistence) return val / maxval end +local function ease(n) + return math.min((1.1 * n + 1 - math.cos(n * math.pi / 2)) / 2, 1) +end + local function heightmap(x, y) - return layered_noise(x * 0.003, y * 0.003, 1, 0.1) + return ease(layered_noise(x * 0.0005, y * 0.0005, 4, 0.8)) end local function dirtgrass_sprite(layer) @@ -72,7 +76,7 @@ local function dirtgrass_sprite(layer) end local function pick_from_atlas(height) - if height < 0.2 then + if height < 0.25 then return atlas.water end if height < 0.3 then @@ -94,10 +98,10 @@ local function pick_color(height) if height < 0.3 then return colors.sand end - if height < 0.7 then + if height < 0.67 then return colors.dirt end - if height < 0.9 then + if height < 0.85 then return colors.stone end return colors.snow @@ -105,7 +109,7 @@ end local function generate(x, y) local height = heightmap(x, y) - z:put(x, y, pick_from_atlas(height), math.ceil(height * 32), pick_color(height)) + z:put(x, y, atlas.stone, math.ceil(height * 40), pick_color(height)) end local generated = {} @@ -128,29 +132,30 @@ local function generate_chunk(cx, cy) end function love.update(dt) + local speed = 512 if love.keyboard.isDown("d") then - local dx = 256 * math.cos(-angle) - local dy = 256 * math.sin(-angle) - x = x - dx * dt - y = y - dy * dt + local dx = speed * math.cos(-angle) + local dy = speed * math.sin(-angle) + gx = gx - dx * dt + gy = gy - dy * dt end if love.keyboard.isDown("a") then - local dx = 256 * math.cos(-angle) - local dy = 256 * math.sin(-angle) - x = x + dx * dt - y = y + dy * dt + local dx = speed * math.cos(-angle) + local dy = speed * math.sin(-angle) + gx = gx + dx * dt + gy = gy + dy * dt end if love.keyboard.isDown("s") then - local dx = 256 * math.cos(-angle + math.pi / 2) - local dy = 256 * math.sin(-angle + math.pi / 2) - x = x - dx * dt - y = y - dy * dt + local dx = speed * math.cos(-angle + math.pi / 2) + local dy = speed * math.sin(-angle + math.pi / 2) + gx = gx - dx * dt + gy = gy - dy * dt end if love.keyboard.isDown("w") then - local dx = 256 * math.cos(-angle + math.pi / 2) - local dy = 256 * math.sin(-angle + math.pi / 2) - x = x + dx * dt - y = y + dy * dt + local dx = speed * math.cos(-angle + math.pi / 2) + local dy = speed * math.sin(-angle + math.pi / 2) + gx = gx + dx * dt + gy = gy + dy * dt end if love.keyboard.isDown("q") then angle = angle + dt @@ -171,8 +176,8 @@ function love.update(dt) end end - local center_cx = -math.floor(x / z._chunk_size) - local center_cy = -math.floor(y / z._chunk_size) + local center_cx = -math.floor(gx / z._chunk_size) + local center_cy = -math.floor(gy / z._chunk_size) for key, gen in pairs(generated) do if math.abs(gen[1] - center_cx) > dist or math.abs(gen[2] - center_cy) > dist then @@ -190,13 +195,13 @@ local t = love.math.newTransform() function love.draw() for _, chunk in pairs(z._chunks) do - chunk.z._height_scale = 12 * scale + chunk.z._height_scale = 18 * scale end t:reset() t:translate(love.graphics.getWidth() / 2, love.graphics.getHeight() / 2) t:scale(scale, scale) t:rotate(angle) - t:translate(x - z._chunk_size, y - z._chunk_size / 2) + t:translate(gx - z._chunk_size, gy - z._chunk_size / 2) z:draw(t) end