|
本帖最后由 EGNE#6985 于 2023-7-12 11:17 编辑
-- main.lua
-- https://create-bbs.reckfeng.com/ ... wthread&tid=642
up.game:event("Game-Init", function()
-- 示例用法
local noise = require 'noise'
-- 初始化地形大小和高度范围
local mapSize = 50
local maxHeight = 295 * 8
-- 创建一个地形矩阵
local map = {}
for x = 1, mapSize do
map[x] = {}
for y = 1, mapSize do
map[x][y] = 0
end
end
-- 生成地形数据
for x = 1, mapSize do
for y = 1, mapSize do
local frequency = 0.01 -- 频率
local amplitude = 0.55 -- 振幅
local persistence = 0.95 -- 持续度
local octaves = 5 -- 阶数
local height = 0
for i = 1, octaves do
local octaveX = x * frequency
local octaveY = y * frequency
height = height + noise(octaveX, octaveY, "12345") * amplitude
frequency = frequency * 2
amplitude = amplitude * persistence
end
height = height * maxHeight
map[x][y] = height
end
end
-- 绘制地形
for x = 1, mapSize do
for y = 1, mapSize do
local h = math.floor(map[x][y]) // 295 * 295
local key = nil
-- 分层染色
if h > 0 * 295 then
key = 134239615 -- 红色
elseif h <= 0 * 295 then
key = 134266735 -- 蓝色
end
Cube:creatCube(Util:creatVector(x * 295, y * 295, h), 295, 295, 295, key) -- 此处更换为自己对应的生成代码
end
end
end)
|
|