my version of perlin noise
// Project: perlin
// Created: 2018-01-27
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "perlin" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#constant sizex = 100
#constant sizey = 100
type _heightmap
height#
endtype
global heightmap as _heightmap[sizex,sizey]
type _blocks
id
x#
y#
z#
height#
endtype
global block as _blocks[sizex,sizey]
buildcubes(.25,.25,.25)
noise=1//low = more high rising
for h=1 to 10
for x=1 to sizex
for y=1 to sizey
perlin(x,y,noise)
next
next
next
reposition()
cx#=getobjectx(block[1,1].id):cy#=getobjecty(block[1,1].id):cz#=getobjectz(block[1,1].id)
cx#=0:cy#=0:cz#=0
do
if GetRawKeyState(37) then dec cx#,.5
if GetRawKeyState(39) then inc cx#,.5
if GetRawKeyState(38) then inc cy#,.5
if GetRawKeyState(40) then dec cy#,.5
SetCameraPosition(1,cx#,cy#+5,cy#-5)
Print( ScreenFPS() )
Sync()
loop
function reposition()
for x=1 to sizex
for y=1 to sizey
SetObjectPosition(block[x,y].id , block[x,y].x# , block[x,y].height# , block[x,y].y#)
next
next
endfunction
function perlin(x,y,noise)
rnd=random(0,noise)
if rnd=1 then inc block[x,y].height#,GetObjectSizeMaxZ(block[x,y].id)
endfunction
function buildcubes(sizex#,sizey#,sizez#)
for x=1 to sizex
for y=1 to sizey
block[x,y].id = CreateObjectBox(sizex#,sizey#,sizez#)
block[x,y].x# = x * sizex#
block[x,y].y# = y * sizey#
SetObjectPosition(block[x,y].id,block[x,y].x#, block[x,y].height# , block[x,y].y#)
next
next
endfunction
hope it helps