better biomes, but not balanced

This commit is contained in:
2026-07-19 08:30:06 -06:00
parent cf72109178
commit bcfadc4800
+43 -21
View File
@@ -5,29 +5,47 @@ local lume = require "lib.lume"
local map = {}
local biomes = {
water = {
altitude = {min = 0, max = 0.2},
[1] = {
name = "water",
altitude = {min = 0, max = 0.9},
temperature = {min = 0.1, max = 0.9},
humidity = {min = 0.8, max = 1},
color = {0, 0, 1, 1},
},
sand = {
altitude = {min = 0.2, max = 0.215},
[2] = {
name = "sand",
altitude = {min = 0.2, max = 0.9},
temperature = {min = 0.2, max = 1},
humidity = {min = 0, max = 0.2},
color = {1, 1, 0, 1},
},
grass = {
altitude = {min = 0.215, max = 0.34},
[3] = {
name = "grass",
altitude = {min = 0.3, max = 0.9},
temperature = {min = 0.2, max = 0.8},
humidity = {min = 0.3, max = 0.6},
color = {0, 1, 0, 1},
},
trees = {
altitude = {min = 0.34, max = 0.72},
[4] = {
name = "trees",
altitude = {min = 0.4, max = 0.7},
temperature = {min = 0, max = 0.7},
humidity = {min = 0.1, max = 1},
color = {0, 0.67, 0, 1},
},
stone = {
altitude = {min = 0.72, max = 0.9},
[6] = {
name = "stone",
altitude = {min = 0, max = 1},
temperature = {min = 0, max = 1},
humidity = {min = 0, max = 1},
color = {0.67, 0.67, 0.67, 1},
},
ice = {
altitude = {min = 0.9, max = 1},
color = {1, 1, 1, 1}
[5] = {
name = "ice",
altitude = {min = 0, max = 1},
temperature = {min = 0, max = 0.1},
humidity = {min = 0.1, max = 1},
color = {1, 1, 1, 1},
},
}
@@ -55,7 +73,7 @@ love.load = function()
for x = 0, map.temperature.w do
for y = 0, map.temperature.h do
local distance = math.abs(y - center_y)
map.temperature[x][y] = lume.clamp(map.temperature[x][y] - distance / map.size / 2, 0, 1)
map.temperature[x][y] = lume.clamp(map.temperature[x][y] - distance / map.size, 0, 1)
end
end
heightmap.normalize(map.temperature, 0, 1)
@@ -74,13 +92,17 @@ love.load = function()
map.terrain[x] = {}
for y = 0, map.size do
if lume.distance(x, y, map.size / 2, map.size / 2, true) < radius then
for name, biome in pairs(biomes) do
local value = map.altitude[x][y]
-- this allows a non-deterministic change of terrain
-- depending on which biome is checked first but I don't care right now]
if value >= biome.altitude.min and value <= biome.altitude.max then
map.terrain[x][y] = biome.color
break
for _, biome in ipairs(biomes) do
local altitude = map.altitude[x][y]
if altitude >= biome.altitude.min and altitude <= biome.altitude.max then
local temperature = map.temperature[x][y]
if temperature >= biome.temperature.min and temperature <= biome.temperature.max then
local humidity = map.humidity[x][y]
if humidity >= biome.humidity.min and humidity <= biome.humidity.max then
map.terrain[x][y] = biome.color
break
end
end
end
end
end