math.randomseed(os.time()) local map_generator = require "final_map" local lovebird = require "lib.lovebird" local lume = require "lib.lume" local running_average = require "lib.running_average" local simplex_map = require "lib.simplex_map" local map love.load = function() map = map_generator.generate() print("Min Temperature", map.temperature.min, "Average", running_average.track("minT", map.temperature.min)) print("Max Temperature", map.temperature.max, "Average", running_average.track("maxT", map.temperature.max)) -- if true then return end -- lower temperature by half height -- NOTE ruins "normalization" but that's fine once we have "real" numbers to work with -- for x = 0, map.temperature.w do -- for y = 0, map.temperature.h do -- map.temperature[x][y] = math.max(0, map.temperature[x][y] - map.altitude[x][y] / 2) -- end -- end -- heightmap.normalize(map.temperature, -89.2, 56.7) -- modify temperature by latitude -- TODO would be more efficient to calculate Y in outer loop, since X does not change the distance -- NOTE only subtracts temperature, which further "ruins normalization" and makes everything too cold: -- local center_y = map.size / 2 -- 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, 0, 1) -- end -- end -- heightmap.normalize(map.temperature, -89.2, 56.7) -- increase humidity by half temperature -- for x = 0, map.humidity.w do -- for y = 0, map.humidity.h do -- map.humidity[x][y] = math.min(1, map.humidity[x][y] + map.temperature[x][y] / 2) -- end -- end -- heightmap.normalize(map.humidity, 18, 3240) end local camera = { x = 0, y = 0, speed = 500, } love.update = function(dt) lovebird.update() if love.keyboard.isDown("w") then camera.y = camera.y - camera.speed * dt end if love.keyboard.isDown("s") then camera.y = camera.y + camera.speed * dt end if love.keyboard.isDown("a") then camera.x = camera.x - camera.speed * dt end if love.keyboard.isDown("d") then camera.x = camera.x + camera.speed * dt end end local window_width, window_height = love.graphics.getDimensions() love.draw = function() love.graphics.translate(window_width / 2 - (map.size * map.tile_size) / 2 - camera.x, window_height / 2 - (map.size * map.tile_size) / 2 - camera.y) for x = 1, map.size do for y = 1, map.size do local value = map.biome[x][y] -- local value = map.temperature[x][y] if value then love.graphics.setColor(value) -- love.graphics.setColor( (value + map.temperature.max) / (map.temperature.max + math.abs(map.temperature.min)) , 0, 0, 1) love.graphics.rectangle("fill", x * map.tile_size, y * map.tile_size, map.tile_size, map.tile_size) end end end end love.keypressed = function(key) if key == "escape" then love.event.quit() elseif key == "r" then love.load() elseif key == "t" then print(running_average.count("minT")) elseif key == "=" then map.tile_size = map.tile_size * 2 elseif key == "-" then map.tile_size = map.tile_size / 2 end end