Oooops and Thanks for noticing - now fixed now runs across with 5 potential cubes across and 11 down - 55 cubes (that should be enough for in-game play I think)
If we cry out for anymore then ill adjust the code to cater for more.
// Project: Craft-A-Light
// Created: 2018-06-22
// show all errors
SetErrorMode(2)
#constant screenwidth=1024
#constant screenheight=768
// set window properties
SetWindowTitle( "Craft-A-Light" )
SetWindowSize( screenwidth, screenheight, 1 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( screenwidth, screenheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 1200, 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
// Globals and stuff
// this is the amount of cubes that are on the tilesheet
#constant imagesizex#=10
#constant imagesizey#=10
global ang#, angx#, angy#, fDiffY#
global startx#
startx#=screenwidth/2
global starty#
starty#=screenheight/2
global camerax#,cameray#,cameraz#
global cubesize
global playerspeed#=.1
type _uvdata
minx#
miny#
maxx#
maxy#
halfx#
halfy#
endtype
global uvdata as _uvdata[20,20]
Type Vertex
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
color as integer
endtype
Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype
Type Mesh
VertexList as Vertex[]
TriangleList as Triangle[]
endtype
global meshID as Mesh
cubesize = 10 : numberofcubes=0
chunksizex=100
chunksizey=2
chunksizez=100
setupskyandfog()
cubeimage = LoadImage("test.png") // for the cube textures
y=1
posy#=0
for meshes=1 to 1
for x=1 to chunksizex
// for y=1 to chunksizey
y=random(-1,1)
for z=1 to chunksizez
cubetexturex=random(1,5) // There are 5 potential cubes along the X on the spritesheet
cubetexturey=random(1,11) // 11 cubes down
addcube(cubesize,cubetexturex,cubetexturey, 0,1,0,x*cubesize,random(1,3)*cubesize,z* cubesize)
inc numberofcubes
next
//next
next
chunkmesh = CreateObjectFromMeshTest(meshID)
SetObjectImage(chunkmesh, cubeimage, 0)
SetObjectUVScale(chunkmesh,0,2,2)
SetImageMagFilter(cubeimage,0) // no blurring
SetImageMinFilter(cubeimage,0) // no blurring
SetObjectPosition(chunkmesh, 0,posy#,0)
inc posy#,10
Meshid.VertexList.length=-1
meshid.TriangleList.length=-1
next
camerax#=(chunksizex * cubesize) /2
cameraz#=(chunksizez * cubesize) /2
cameray#=4 * cubesize
do
movecamerawithmouse()
checkkeypresses()
print ("Number of cubes " + str(numberofcubes))
print(ScreenFPS())
sync()
loop
function checkkeypresses()
if GetRawKeyState(37) then dec camerax#,playerspeed#//Left
if GetRawKeyState(39) then inc camerax#,playerspeed#//Right
if GetRawKeyState(38) then inc cameraz#,playerspeed#//Forward
if GetRawKeyState(40) then dec cameraz#,playerspeed#//Backward
if GetRawKeyState(87) then inc cameray#,playerspeed#//87 W
if GetRawKeyState(83) then dec cameray#,playerspeed#//83 S
// if cameray#<(cubesize) then cameray#=(cubesize)
SetCameraPosition(1,camerax#,cameray#,cameraz#)
if GetRawKeyPressed(27) then end
endfunction
function movecamerawithmouse()
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 360 ) then newX# = 360
if ( newX# < -360 ) then newX# = -360
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endfunction
function addcube(cubesize, tilenumberx, tilenumbery, normx#,normy#,normz#,x#,y#,z#)
cubex#=((tilenumberx-1) * .5) + tilenumberx // = 5.5
cubey#=(tilenumbery * 0.5)+ 0.5
maxx# as float
maxx# = ((100/15.00)/100) * cubex#
minx# = (maxx#-(100/15.00)/100)
halfx# = (maxx#/2 + minx# / 2)
bottommaxx# = ((100/15.00)/100) * (cubex#+.5)
bottomminx# = (bottommaxx#-((100/15.00)/100))
bottomhalfx# = (bottommaxx#/2 + bottomminx# / 2)
maxy# = ((100/11.00)/100) * cubey#
miny# = (maxy#-(100/11.00)/100)
halfy# = (maxy#/2 + miny# / 2)
AddVertex(meshID,x# ,y#,z# ,0,1,0, maxx#,halfy#,MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0))
//Triangle 2
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z# ,0,1,0, halfx#,miny#,MakeColor(255,0,0))
//Side 2
// Triangle 1
AddVertex(meshID,x#+cubesize,y#+cubesize,z# ,0,1,0 ,maxx# ,miny#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,maxx#,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,maxx# ,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx# ,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,halfx# ,halfy#, MakeColor(255,0,0))
//Bottom
// Triangle 1
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,bottommaxx#,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z#+-cubesize ,0,1,0 ,bottomhalfx# ,miny# , MakeColor(255,0,0))
// Side 4
// Triangle 1
AddVertex(meshID,x# ,y# ,z#+-cubesize ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,maxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
// side 5
AddVertex(meshID,x#,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#,y# ,z# ,0,1,0 ,halfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#,y# ,z#+-cubesize ,0,1,0 ,maxx# , halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z#+-cubesize ,0,1,0 ,maxx# , miny# , MakeColor(255,0,0))
//TOP
// Triangle 1
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z# ,0,1,0 ,minx#,miny#, MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0))
endfunction
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, color as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.color = color
m.VertexList.Insert(vert)
endfunction
Function AddTriangle(m ref as Mesh, v1 as integer, v2 as integer, v3 as integer)
t as Triangle
t.v1 = v1
t.v2 = v2
t.v3 = v3
m.TriangleList.Insert(t)
endfunction
Function CreateObjectFromMeshTest(m ref as mesh)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 3
IndexOffset = 60 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,3)
SetMemblockInt(memblock,12,32) // no color - 36 if color
SetmemblockInt(memblock,16,60)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
// SetMemblockInt(memblock,60,0x08010401)
//SetMemblockString(memblock,64,"color")
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,60+i*32,m.VertexList[i].x)
SetMemblockFloat(memblock,64+i*32,m.VertexList[i].y)
SetMemblockFloat(memblock,68+i*32,m.VertexList[i].z)
SetMemblockFloat(memblock,72+i*32,m.VertexList[i].nx)
SetMemblockFloat(memblock,76+i*32,m.VertexList[i].ny)
SetMemblockFloat(memblock,80+i*32,m.VertexList[i].nz)
SetMemblockFloat(memblock,84+i*32,m.VertexList[i].u)
SetMemblockFloat(memblock,88+i*32,m.VertexList[i].v)
// SetMemblockInt(memblock,92+i*36,m.VertexList[i].color)
next
for i = 0 to m.TriangleList.Length
SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1)
SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2)
SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3)
next
id = CreateObjectFromMeshMemblock(memblock)
DeleteMemblock(memblock)
endfunction id
function setupskyandfog()
// setup a skybox
SetSunActive(1)
SetSkyBoxHorizonSize(4.1,4)
SetSkyBoxHorizonColor(90,132,150)//nice horizon blue
SetSkyBoxSkyColor(0,122,193)//thunder horison thunderblue
SetSkyBoxVisible(1)
SetFogColor(155,155,155)
SetFogRange(1000,2000)
SetFogMode(1)
SetCameraRange(1,0.1,1000)
endfunction
I thought id try and build a proper chunk now - with 100 down
// Project: mesh_addcolor
// Inspried by TomToads code snippet on the forums for Triangle Strip generation into array first then build
// Created: 2018-06-22
// show all errors
SetErrorMode(2)
#constant screenwidth=1024
#constant screenheight=768
// set window properties
SetWindowTitle( "mesh_addcolor" )
SetWindowSize( screenwidth, screenheight, 1 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( screenwidth, screenheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 1200, 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
// Globals and stuff
// this is the amount of cubes that are on the tilesheet
#constant imagesizex#=10
#constant imagesizey#=10
global ang#, angx#, angy#, fDiffY#
global startx#
startx#=screenwidth/2
global starty#
starty#=screenheight/2
global camerax#,cameray#,cameraz#
global cubesize
global playerspeed#=.1
type _uvdata
minx#
miny#
maxx#
maxy#
halfx#
halfy#
endtype
global uvdata as _uvdata[20,20]
Type Vertex
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
color as integer
endtype
Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype
Type Mesh
VertexList as Vertex[]
TriangleList as Triangle[]
endtype
global meshID as Mesh
cubesize = 10 : numberofcubes=0
chunksizex=16
chunksizey=100
chunksizez=16
setupskyandfog()
cubeimage = LoadImage("test.png") // for the cube textures
y=1
posy#=0
for meshes=1 to 1
for x=1 to chunksizex
for y=1 to chunksizey
for z=1 to chunksizez
cubetexturex=random(1,1) // There are 5 potential cubes along the X on the spritesheet
cubetexturey=random(1,1) // 11 cubes down
addcube(cubesize,cubetexturex,cubetexturey, 0,1,0,x*cubesize,y*cubesize,z* cubesize)
inc numberofcubes
next
next
next
chunkmesh = CreateObjectFromMeshTest(meshID)
SetObjectImage(chunkmesh, cubeimage, 0)
SetObjectUVScale(chunkmesh,0,2,2)
SetImageMagFilter(cubeimage,0) // no blurring
SetImageMinFilter(cubeimage,0) // no blurring
SetObjectPosition(chunkmesh, 0,posy#,0)
inc posy#,10
Meshid.VertexList.length=-1
meshid.TriangleList.length=-1
next
camerax#=(chunksizex * cubesize) /2 - 300
cameraz#=(chunksizez * cubesize) /2
cameray#=(chunksizey+3) * cubesize
do
movecamerawithmouse()
checkkeypresses()
print ("Number of cubes " + str(numberofcubes))
print(ScreenFPS())
sync()
loop
function checkkeypresses()
if GetRawKeyState(37) then dec camerax#,playerspeed#//Left
if GetRawKeyState(39) then inc camerax#,playerspeed#//Right
if GetRawKeyState(38) then inc cameraz#,playerspeed#//Forward
if GetRawKeyState(40) then dec cameraz#,playerspeed#//Backward
if GetRawKeyState(87) then inc cameray#,playerspeed#//87 W
if GetRawKeyState(83) then dec cameray#,playerspeed#//83 S
// if cameray#<(cubesize) then cameray#=(cubesize)
SetCameraPosition(1,camerax#,cameray#,cameraz#)
if GetRawKeyPressed(27) then end
endfunction
function movecamerawithmouse()
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 360 ) then newX# = 360
if ( newX# < -360 ) then newX# = -360
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endfunction
function addcube(cubesize, tilenumberx, tilenumbery, normx#,normy#,normz#,x#,y#,z#)
cubex#=((tilenumberx-1) * .5) + tilenumberx // = 5.5
cubey#=(tilenumbery * 0.5)+ 0.5
maxx# as float
maxx# = ((100/15.00)/100) * cubex#
minx# = (maxx#-(100/15.00)/100)
halfx# = (maxx#/2 + minx# / 2)
bottommaxx# = ((100/15.00)/100) * (cubex#+.5)
bottomminx# = (bottommaxx#-((100/15.00)/100))
bottomhalfx# = (bottommaxx#/2 + bottomminx# / 2)
maxy# = ((100/11.00)/100) * cubey#
miny# = (maxy#-(100/11.00)/100)
halfy# = (maxy#/2 + miny# / 2)
AddVertex(meshID,x# ,y#,z# ,0,1,0, maxx#,halfy#,MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0))
//Triangle 2
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z# ,0,1,0, halfx#,miny#,MakeColor(255,0,0))
//Side 2
// Triangle 1
AddVertex(meshID,x#+cubesize,y#+cubesize,z# ,0,1,0 ,maxx# ,miny#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,maxx#,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,maxx# ,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx# ,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,halfx# ,halfy#, MakeColor(255,0,0))
//Bottom
// Triangle 1
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,bottommaxx#,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z#+-cubesize ,0,1,0 ,bottomhalfx# ,miny# , MakeColor(255,0,0))
// Side 4
// Triangle 1
AddVertex(meshID,x# ,y# ,z#+-cubesize ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,maxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
// side 5
AddVertex(meshID,x#,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#,y# ,z# ,0,1,0 ,halfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#,y# ,z#+-cubesize ,0,1,0 ,maxx# , halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z#+-cubesize ,0,1,0 ,maxx# , miny# , MakeColor(255,0,0))
//TOP
// Triangle 1
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z# ,0,1,0 ,minx#,miny#, MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0))
endfunction
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, color as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.color = color
m.VertexList.Insert(vert)
endfunction
Function AddTriangle(m ref as Mesh, v1 as integer, v2 as integer, v3 as integer)
t as Triangle
t.v1 = v1
t.v2 = v2
t.v3 = v3
m.TriangleList.Insert(t)
endfunction
Function CreateObjectFromMeshTest(m ref as mesh)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 3
IndexOffset = 60 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,3)
SetMemblockInt(memblock,12,32) // no color - 36 if color
SetmemblockInt(memblock,16,60)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
// SetMemblockInt(memblock,60,0x08010401)
//SetMemblockString(memblock,64,"color")
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,60+i*32,m.VertexList[i].x)
SetMemblockFloat(memblock,64+i*32,m.VertexList[i].y)
SetMemblockFloat(memblock,68+i*32,m.VertexList[i].z)
SetMemblockFloat(memblock,72+i*32,m.VertexList[i].nx)
SetMemblockFloat(memblock,76+i*32,m.VertexList[i].ny)
SetMemblockFloat(memblock,80+i*32,m.VertexList[i].nz)
SetMemblockFloat(memblock,84+i*32,m.VertexList[i].u)
SetMemblockFloat(memblock,88+i*32,m.VertexList[i].v)
// SetMemblockInt(memblock,92+i*36,m.VertexList[i].color)
next
for i = 0 to m.TriangleList.Length
SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1)
SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2)
SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3)
next
id = CreateObjectFromMeshMemblock(memblock)
DeleteMemblock(memblock)
endfunction id
function setupskyandfog()
// setup a skybox
SetSunActive(1)
SetSkyBoxHorizonSize(4.1,4)
SetSkyBoxHorizonColor(90,132,150)//nice horizon blue
SetSkyBoxSkyColor(0,122,193)//thunder horison thunderblue
SetSkyBoxVisible(1)
SetFogColor(155,155,155)
SetFogRange(1000,2000)
SetFogMode(1)
SetCameraRange(1,0.1,1000)
endfunction
Perlin Noised it
// Project: CraftALite
// Created: 2018-07-31
// show all errors
SetErrorMode(2)
#constant screenwidth=1024
#constant screenheight=768
// set window properties
SetWindowTitle( "CraftALite" )
SetWindowSize( 1024, 768, 1 )
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( 0, 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
// Globals and stuff
// this is the amount of cubes that are on the tilesheet
#constant perlinheight=10.0
#constant chunksizex=170
#constant chunksizey=1
#constant chunksizez=170
global ang#, angx#, angy#, fDiffY#
global startx#
startx#=screenwidth/2
global starty#
starty#=screenheight/2
global camerax#,cameray#,cameraz#
global cubesize
global playerspeed#=.1
type _uvdata
minx#
miny#
maxx#
maxy#
halfx#
halfy#
endtype
global uvdata as _uvdata[20,20]
Type Vertex
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
color as integer
endtype
Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype
Type Mesh
VertexList as Vertex[]
TriangleList as Triangle[]
endtype
global meshID as Mesh
cubesize = 10 : numberofcubes=0
// Perlin noise variables and setup
type _perlinmap
r,g, b, a, x, y
level
texture
noise
endtype
#constant perlinw = 512 //power of 2
#constant perlinh = 512 //power of 2
#constant perlinz = 0
global perlinmap as _perlinmap[perlinw,perlinh,perlinz]
global perlinx, perlinzz
NoiseInit()
mapimage = generateperlinimage()
mapsprite=CreateSprite(mapimage)
SetSpriteScale(mapsprite,.5,.5)
/// end
setupskyandfog()
cubeimage = LoadImage("test.png") // for the cube textures
y=1
posy#=0
for meshes=1 to 1
for x=1 to chunksizex
for y=1 to chunksizey
for z=1 to chunksizez
cubetexturex=random(1,1) // There are 5 potential cubes along the X on the spritesheet
cubetexturey=random(1,1) // 11 cubes down
addcube(cubesize,cubetexturex,cubetexturey, 0,1,0,x*cubesize,perlinmap[x,z,0].level*cubesize,z* cubesize)
inc numberofcubes
next
next
next
chunkmesh = CreateObjectFromMeshTest(meshID)
SetObjectImage(chunkmesh, cubeimage, 0)
SetObjectUVScale(chunkmesh,0,2,2)
SetImageMagFilter(cubeimage,0) // no blurring
SetImageMinFilter(cubeimage,0) // no blurring
SetObjectPosition(chunkmesh, 0,posy#,0)
inc posy#,10
Meshid.VertexList.length=-1
meshid.TriangleList.length=-1
next
camerax#=(chunksizex * cubesize) /2
cameraz#=(chunksizez * cubesize) /2
cameray#=(chunksizey+50) * cubesize
do
movecamerawithmouse()
checkkeypresses()
print ("Number of cubes " + str(numberofcubes))
print(ScreenFPS())
sync()
loop
function checkkeypresses()
if GetRawKeyState(37) then dec camerax#,playerspeed#//Left
if GetRawKeyState(39) then inc camerax#,playerspeed#//Right
if GetRawKeyState(38) then inc cameraz#,playerspeed#//Forward
if GetRawKeyState(40) then dec cameraz#,playerspeed#//Backward
if GetRawKeyState(87) then inc cameray#,playerspeed#//87 W
if GetRawKeyState(83) then dec cameray#,playerspeed#//83 S
// if cameray#<(cubesize) then cameray#=(cubesize)
SetCameraPosition(1,camerax#,cameray#,cameraz#)
if GetRawKeyPressed(27) then end
endfunction
function movecamerawithmouse()
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 360 ) then newX# = 360
if ( newX# < -360 ) then newX# = -360
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endfunction
function addcube(cubesize, tilenumberx, tilenumbery, normx#,normy#,normz#,x#,y#,z#)
cubex#=((tilenumberx-1) * .5) + tilenumberx // = 5.5
cubey#=(tilenumbery * 0.5)+ 0.5
maxx# as float
maxx# = ((100/15.00)/100) * cubex#
minx# = (maxx#-(100/15.00)/100)
halfx# = (maxx#/2 + minx# / 2)
bottommaxx# = ((100/15.00)/100) * (cubex#+.5)
bottomminx# = (bottommaxx#-((100/15.00)/100))
bottomhalfx# = (bottommaxx#/2 + bottomminx# / 2)
maxy# = ((100/11.00)/100) * cubey#
miny# = (maxy#-(100/11.00)/100)
halfy# = (maxy#/2 + miny# / 2)
AddVertex(meshID,x# ,y#,z# ,0,1,0, maxx#,halfy#,MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0))
//Triangle 2
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z# ,0,1,0, halfx#,miny#,MakeColor(255,0,0))
//Side 2
// Triangle 1
AddVertex(meshID,x#+cubesize,y#+cubesize,z# ,0,1,0 ,maxx# ,miny#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx#,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,maxx#,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,maxx# ,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx# ,miny#,MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,halfx# ,halfy#, MakeColor(255,0,0))
//Bottom
// Triangle 1
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z# ,0,1,0 ,bottommaxx#,halfy#, MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y# ,z#+-cubesize ,0,1,0 ,bottomhalfx# ,miny# , MakeColor(255,0,0))
// Side 4
// Triangle 1
AddVertex(meshID,x# ,y# ,z#+-cubesize ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+cubesize,z#+-cubesize ,0,1,0 ,maxx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+cubesize,z#+-cubesize ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
// side 5
AddVertex(meshID,x#,y# ,z#+-cubesize ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#,y# ,z# ,0,1,0 ,halfx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#,y# ,z#+-cubesize ,0,1,0 ,maxx# , halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#,y#+cubesize ,z#+-cubesize ,0,1,0 ,maxx# , miny# , MakeColor(255,0,0))
//TOP
// Triangle 1
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z# ,0,1,0 ,minx#,miny#, MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0))
AddVertex(meshID,x#+cubesize,y#+Cubesize ,z#+-cubesize ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0))
AddVertex(meshID,x# ,y#+Cubesize ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0))
endfunction
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, color as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.color = color
m.VertexList.Insert(vert)
endfunction
Function AddTriangle(m ref as Mesh, v1 as integer, v2 as integer, v3 as integer)
t as Triangle
t.v1 = v1
t.v2 = v2
t.v3 = v3
m.TriangleList.Insert(t)
endfunction
Function CreateObjectFromMeshTest(m ref as mesh)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 3
IndexOffset = 60 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,3)
SetMemblockInt(memblock,12,32) // no color - 36 if color
SetmemblockInt(memblock,16,60)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
// SetMemblockInt(memblock,60,0x08010401)
//SetMemblockString(memblock,64,"color")
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,60+i*32,m.VertexList[i].x)
SetMemblockFloat(memblock,64+i*32,m.VertexList[i].y)
SetMemblockFloat(memblock,68+i*32,m.VertexList[i].z)
SetMemblockFloat(memblock,72+i*32,m.VertexList[i].nx)
SetMemblockFloat(memblock,76+i*32,m.VertexList[i].ny)
SetMemblockFloat(memblock,80+i*32,m.VertexList[i].nz)
SetMemblockFloat(memblock,84+i*32,m.VertexList[i].u)
SetMemblockFloat(memblock,88+i*32,m.VertexList[i].v)
// SetMemblockInt(memblock,92+i*36,m.VertexList[i].color)
next
for i = 0 to m.TriangleList.Length
SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1)
SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2)
SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3)
next
id = CreateObjectFromMeshMemblock(memblock)
DeleteMemblock(memblock)
endfunction id
function setupskyandfog()
// setup a skybox
SetSunActive(1)
SetSkyBoxHorizonSize(4.1,4)
SetSkyBoxHorizonColor(90,132,150)//nice horizon blue
SetSkyBoxSkyColor(0,122,193)//thunder horison thunderblue
SetSkyBoxVisible(1)
SetFogColor(155,155,155)
SetFogRange(1000,2000)
SetFogMode(1)
SetCameraRange(1,0.1,1000)
endfunction
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you
#constant PN3DF2 = 0.5*(sqrt(3.0)-1.0)
#constant PN3DG2 = (3.0-sqrt(3.0))/6.0
Type sPNVECTOR
x as float
y as float
z as float
endtype
Global PNHash as integer[512]
Global PNGrad3 as sPNVECTOR[256]
Function NoiseInit()
Local n as integer, rn as integer
For n=0 To 255
PNHash[n] = n
Next n
For n=0 To 255
rn=Random(0, 255)
PNHash.swap(n,rn)
Next n
For n=0 To 255
PNHash[256 + n] = PNHash[n]
Next n
PNHash[511] = PNHash[0]
For n=0 To 15
PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0
PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0
PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0
PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0
PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1
PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1
PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1
PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1
PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1
PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1
PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1
PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1
PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0
PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0
PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1
PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1
Next n
endfunction
function Noise2D(xin as float, yin as float)
local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float
local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer
local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float
s = (xin + yin) * PN3DF2
xs = xin + s
i = floor(xs)
ys = yin + s
j = floor(ys)
t = (i + j) * PN3DG2
x0 = xin - (i - t)
y0 = yin - (j - t)
if x0>y0
i1=1
j1=0
else
i1=0
j1=1
endif
x1 = x0 - i1 + PN3DG2
y1 = y0 - j1 + PN3DG2
x2 = x0 - 1.0 + 2.0 * PN3DG2
y2 = y0 - 1.0 + 2.0 * PN3DG2
i = i && 255
j = j && 255
gi0 = PNHash[i + PNHash[j]] && 15
gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15
gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15
t0 = 0.5 - x0*x0-y0*y0
if t0<0
n0 = 0.0
else
t0 = t0 * t0
n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0)
endif
t1 = 0.5 - x1*x1-y1*y1
if t1<0
n1 = 0.0
else
t1 = t1 * t1
n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1)
endif
t2 = 0.5 - x2*x2-y2*y2
if t2<0
n2 = 0.0
else
t2 = t2 * t2
n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2)
endif
endfunction 70.0 * (n0 + n1 + n2)
function generateperlinimage()
// Generate image from memblock
size = perlinw * perlinh * 4 + 12
mem = CreateMemblock(size)
SetMemblockInt(mem,0,perlinw)
SetMemblockInt(mem,4,perlinh)
SetMemblockInt(mem,8,32)
offset as integer = 12
a as float, b as float
a = 5.0
b = 2.0
for y = 0 to perlinh - 1
for x = 0 to perlinw - 1
a = a + 0.0001
b = b + 0.002
// Try out these two noise methods
//noise = 255.0*Noise2D(x/10.0,y/10.0)
noise = 255.0*noise2d(x/120.0,y/120.0)
noise = abs(noise)
perlinmap[x,y,0].noise=noise
perlinmap[x,y,0].x = x
perlinmap[x,y,0].y = y
//clouds
if noise>255
perlinmap[x,y,0].r = noise
perlinmap[x,y,0].g = noise
perlinmap[x,y,0].b = noise
perlinmap[x,y,0].texture = 6 // snow
perlinmap[x,y,0].level = 5
SetMemblockByte(mem, offset, noise)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
//greenary
if noise>100 and noise<=255
perlinmap[x,y,0].r = 0
perlinmap[x,y,0].g = noise
perlinmap[x,y,0].b = 0
perlinmap[x,y,0].texture = 0 // grass
perlinmap[x,y,0].level = 4 // grass
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, 0)
SetMemblockByte(mem, offset+3, 255)
endif
//sand
if noise>50 and noise<=100
perlinmap[x,y,0].r = noise
perlinmap[x,y,0].g = noise
perlinmap[x,y,0].b = 0
perlinmap[x,y,0].texture = 5 // sand
perlinmap[x,y,0].level = 3
SetMemblockByte(mem, offset, noise)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, 0)
SetMemblockByte(mem, offset+3, 255)
endif
// water
if noise>25 and noise<=50
perlinmap[x,y,0].r = 0
perlinmap[x,y,0].g = noise
perlinmap[x,y,0].b = noise
perlinmap[x,y,0].texture = 4 // lightwater
perlinmap[x,y,0].level = 2
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, 0)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
if noise<=25
perlinmap[x,y,0].r = 0
perlinmap[x,y,0].g = 0
perlinmap[x,y,0].b = noise
perlinmap[x,y,0].texture = 3 // deep water
perlinmap[x,y,0].level = 1 // deep water
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
perlinmap[x,y,0].level=noise/perlinheight // height - the higher value then less (lower) - the lower value is higher
if perlinmap[x,y,0].level<1 then perlinmap[x,y,0].level=1
offset = offset + 4
next
next
mapspriteimage = CreateImageFromMemblock(mem)
mapsprite=CreateImageFromMemblock(mem)
endfunction mapsprite
Just tweak the constants
#constant perlinheight=10.0 / the low this value is the higher the perlin - the higher this is the lower the perlin
#constant chunksizex=170
#constant chunksizey=1
#constant chunksizez=170
Enjoy - catch up soon