Happy easter to all for a nice long weekend break
// Project: CreateObjectFromMeshMemblock
// Created: 2018-03-02
// show all errors
SetErrorMode(2)
// Setup the hard coded constants
#constant screenwidth=800
#constant screenheight=600
#constant blocksizex=32 // size of the chunk
#constant blocksizey=1 // size of the chunk
#constant blocksizez=32 // size of the chunk
#constant blocksize#=10 // size of each cube
#constant texturedlayers=1 // the amount of textured layers per level on the chunk
#constant occludelayer=3 // this will make all layers of blocksizey and below visible anything higher is invisible
#constant totalworldchunks=3 // how many of the 16x16 chunks are generated and surrounded
// setup perlinmapdata
#constant perlinw = 64 //power of 2
#constant perlinh = 64 //power of 2
#constant perlinz = 0
// set window properties
SetWindowTitle( "CreateObjectFromMeshMemblock" )
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
SetDefaultMagFilter(0)
SetDefaultMinFilter(0)
// setup the types - each entity may have multiple of entities to keep track of, these can be stored as Types
type _textures
id // texture store
r,g,b // colors
dr,dg,db // depths (because minecraft tiles is built with rectangular different shades of the color)
texturessize
endtype
type _worldlayers
id
layers as integer[6] // 6 potential inventory blocks so can place new but different textured blocks on the s
endtype
type _perlinmap
r
g
b
a
texture
noise
endtype
type _playblocks
spr
red
green
blue
endtype
global playblocks as _playblocks[10]
type _tree
cones as integer[10]
stump
height#
endtype
global tree as _tree[5] // how many in the scene, use .insert to add new
// Initialise Globals
// Inventory Variables
global playerblocks // stored the players object of which will use to add/destroy
global currentselectedplayblock,pointer
// world variables
global perlinmap as _perlinmap[perlinw,perlinh,perlinz]
global worldlayers as _worldlayers[100000] // this stores each the chunks id, used to join them all up together
// use "Totalworldchunks" to set how many joined on the x and z axis
global worldchunks
global chunks, totalcubecount
// textures
global textures as _textures[50] // used to store textures (not ready yet)
// memblock variables
global face,vertcount,vertoff,vertsize
// Camera Variables
global camerax#,cameray#,cameraz#
global angx#,angy#,startx#,starty#
// Object variables
global treecount=0
global ocean
// Perlin Variables - these are to count through the perlin map array
global perlinx,perlinzz
// Run the Game Title Screen
// title() - Not ready yet
// Initialise Game
InitialiseGame()
camerax#=50
cameray#=50
cameraz#=1
SetCameraPosition(1,camerax#,cameray#,cameraz#)
pointer=CreateObjectSphere(.1,5,5)
SetObjectPosition(pointer,getcamerax(1),getcameray(1),getcameraz(1)-10)
do
movecamerawithmouse()
displayinventoryandhealth()
checkkeypresses()
displaydebuginfo()
sync()
loop
function InitialiseGame()
createblockpointer()
definetextures()
setupinventoryitems()
setupskyandfog()
createtree(0)
createocean()
buildmap()
worldchunks=generatechunk()
buildchunks()
initialisecamera()
endfunction
function createocean()
ocean=CreateObjectPlane(100000,100000)
SetObjectRotation(ocean,90,0,0)
SetObjectColor(ocean,0,0,50,255)
SetObjectPosition(ocean,getobjectx(ocean),-10,getobjectz(ocean))
endfunction
function createtree(id)
tree[id].height#=random(1,4)
tree[id].stump = CreateObjectCylinder(tree[id].height#*2,tree[id].height#/2,10)
SetObjectColor(tree[id].stump, 83, 53, 10,255)
for a=0 to tree[id].height#*1.5
tree[id].cones[a] = CreateObjectCone(a,2+a,50)
SetObjectPosition(tree[id].cones[a],0,2+(tree[id].height#)-a,0)
SetObjectColor(tree[id].cones[a],random(50,100),random(120,170),0,255)
fixobjecttoobject(tree[id].cones[a],tree[id].stump)
next
endfunction tree[treecount].stump
function generatechunk()
totalcubecount=0
vertnum=0:
chunks=100 // memory reference ic
for y=1 to blocksizey
xpos#=0:ypos#=0:zpos#=0
blockcount=1
makememblock(chunks)
for layers=1 to texturedlayers // 6 texturs at moment
for z=1 to blocksizez
for x=1 to blocksizex
if y=1
// if working on the top layer then create blocks at different levels above land
if random(1,5)>texturedlayers then addplane(chunks, xpos#,random(0,3)*blocksize#,zpos#,blockcount,x,y,z)
else
// otherwise they are below you, so keep them on the same level
if random(1,5)>texturedlayers then addplane(chunks, xpos#,0,zpos#,blockcount,x,y,z)
endif
inc blockcount
inc totalcubecount
xpos#=xpos#+blocksize#
inc perlinx
if perlinx>256 then perlinx=256
next x
zpos#=zpos#+blocksize#
xpos#=0
next z
zpos#=0
xpos#=0
worldlayers[y].layers[layers]=CreateObjectFromMeshMemblock(chunks)
next layers
next y
endfunction worldchunks
function buildmap()
// start perlin map data
NoiseInit()
mapimg=generateperlinimage()
mapsprite = CreateSprite(mapimg)
//SetSpriteSize(mapsprite,128,128)
SetSpritePosition(mapsprite,screenwidth-100,10)
endfunction
function buildchunks()
totalcubecount=0
perlinx=1:perlinzz=1
a=1
for y=1 to blocksizey
for layers=1 to texturedlayers
for wx=1 to totalworldchunks
for wz=1 to totalworldchunks
worldlayers[a].id=InstanceObject(worldlayers[y].layers[layers]) // worldchunks is the ID of the 1st chunk object made
// worldlayers[a].id=generatechunk()
SetObjectPosition(worldlayers[a].id,wx*(blocksizex*blocksize#),y*blocksize#,wz*(blocksizez*blocksize#))
// if random(1,100)>80 then add_a_tree()
//SetObjectImage(worldlayers[a].id,textures[perlinmap[wx,wz,0].texture].id,0)
SetObjectImage(worldlayers[a].id,textures[random(0,texturedlayers)].id,0) // we have 5 textures made at moment
// make only the top layer visible to keep fps on an even keel
// we will need to look down and see any open underground - so maybe can increase this to y<4 of something so can only see 4
// levels down
// Make chunks invisible more than 5 chunks away
if y<occludelayer
SetObjectVisible(worldlayers[a].id,1)
else
SetObjectVisible(worldlayers[a].id,0)
endif
if wx<totalworldchunks/2-4 and wz>totalworldchunks/2+4
SetObjectVisible(worldlayers[a].id,0)
else
// SetObjectVisible(worldlayers[a].id,1)
endif
// find the centre chunk of starting position, we then can make chunks invisible say 4 surround chunks and render later
// when move around
if wx = totalworldchunks/2 and wz=totalworldchunks/2
centrechunk=a
endif
inc a
inc totalcubecount,blocksizex*blocksizey*blocksizez
next
next
next
next
// SetObjectVisible(worldlayers[centrechunk].id,1)
/*
for a=-5 to 5
SetObjectVisible(worldlayers[centrechunk-totalworldchunks-a].id,1)
// SetObjectVisible(worldlayers[centrechunk+totalworldchunks+a].id,1)
SetObjectVisible(worldlayers[centrechunk-totalworldchunks+a].id,1)
// SetObjectVisible(worldlayers[centrechunk-totalworldchunks+1].id,1)
SetObjectVisible(worldlayers[centrechunk+totalworldchunks-a].id,1)
SetObjectVisible(worldlayers[centrechunk+totalworldchunks+a].id,1)
//SetObjectVisible(worldlayers[centrechunk+totalworldchunks+1].id,1)
SetObjectVisible(worldlayers[centrechunk-a].id,1)
// SetObjectVisible(worldlayers[centrechunk+1].id,1)
next
*/
endfunction
function add_a_tree()
// Add a tree
// inc treecount
createtree(treecount)
// if treecount>tree.length-1 then treecount=tree.length-1
// tree[treecount].stump=InstanceObject(tree[0].stump)
treex#=random(1,(blocksizex * totalworldchunks)*blocksize#)
treez#=random(1,(blocksizez * totalworldchunks)*blocksize#)
SetObjectPosition(tree[treecount].stump,treex#,blocksize#,treez#)
inc treecount
endfunction
function initialisecamera()
setcamerarange(1,0.1,10000.0)
setcameraposition(1,getcamerax(1),600,getcameraz(1))
angx#=0:angy#=0:startx#=1024/2:starty#=768/2
SetRawMousePosition(1024/2,768/2)
camerax#=(blocksizex * (totalworldchunks*5))
cameray#=(blocksizey*2)
cameraz#=(blocksizez * (totalworldchunks * 5))
endfunction
function checkkeypresses()
if GetRawKeyState(37) then dec camerax#,1//Left
if GetRawKeyState(39) then inc camerax#,1//Right
if GetRawKeyState(38) then inc cameraz#,1//Forward
if GetRawKeyState(40) then dec cameraz#,1//Backward
if GetRawKeyState(87) then inc cameray#,1//87 W
if GetRawKeyState(83) then dec cameray#,1//87 S
if GetRawKeyState(65) then RotateCameraLocalY(1,1)
if GetRawKeyState(68) then RotateCameraLocalY(1,-1)
// if cameray#<(blocksizey*10) then cameray#=(blocksizey*10)
if GetRawKeyState(32)
blockx=random(1,blocksizex)
blocky=random(1,blocksizey)
blockz=random(1,blocksizez)
//chk = CreateMemblockFromObjectMesh(worldlayers[1].id,1)
removeplane(chunks,blockx,blocky,blockz,random(1,blocksizex*blocksizez),blockx,blocky,blockz)
SetObjectMeshFromMemblock(worldlayers[1].layers[1],1,chunks)
endif
if GetRawKeyPressed(27) then end
endfunction
function setupinventoryitems()
for a=0 to 9
swap()
box=CreateObjectBox(.5,.5,.5)
SetObjectRotation(box,0,45,0)
red=random(0,255):playblocks[a].red=red
green=random(0,255):playblocks[a].green=green
blue=random(0,255):playblocks[a].blue=blue
SetObjectColor(box,red,green,blue,255)
SetObjectTransparency(box,1)
render()
playblocks[a].spr=CreateSprite(getimage(screenwidth/2-50,screenheight/2-50,screenwidth/2+50,screenheight/2+50))
DeleteObject(box)
next
DrawLine(0,0,1,1,MakeColor(255,255,255),MakeColor(255,255,255),1)
mouse=createsprite(GetImage(0,0,1,1))
SetRawMouseVisible(0)
endfunction
function displayinventoryandhealth()
for a=0 to 9
SetSpritePosition(playblocks[a].spr,(screenwidth/2-(50*5))+a*50,screenheight-150)
next
endfunction
// this creates the centre pointer
function createblockpointer()
mouse = CreateObjectSphere(.1,10,10)
SetObjectPosition(mouse,50,1,50)
SetRawMousePosition(screenwidth/2,screenheight/2)
SetRawMouseVisible(0)
endfunction
function displaydebuginfo()
print (GetRawLastKey())
print (GetPolygonsDrawn())
print ("Chunk size : " + str(blocksizex) + " x " + str(blocksizey) + " x " + str(blocksizez) )
print ("World size : " + str(totalworldchunks) + " Chunks by " + str(totalworldchunks)+ " Chunks")
print("Potential cubes within : " + str(totalcubecount))
print("WASD and cursors to move about")
print (ScreenFPS())
endfunction
function movecamerawithmouse()
fDiffX# = (GetPointerX() - startx#)/6.0
fDiffY# = (GetPointerY() - starty#)/6.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
SetCameraPosition(1,camerax#,cameray#,cameraz#)
SetObjectPosition(pointer,newx#,angy#+fDiffX# ,0)
/*
VectorX# = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() )
VectorY# = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() )
VectorZ# = Get3DVectorZFromScreen( GetPointerX(), GetPointerY()*2 )
// get a vector that points in the direction the camera is looking
VectorX2# = Get3DVectorXFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorY2# = Get3DVectorYFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorZ2# = Get3DVectorZFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
depth#=5
// normalise Vector in the direction of Vector2
Dot# = VectorX#*VectorX2# + VectorY#*VectorY2# + VectorZ#*VectorZ2#
if ( Dot# > 0 )
VectorX# = VectorX# / Dot#
VectorY# = VectorY# / Dot#
VectorZ# = VectorZ# / Dot#
endif
WorldX# = VectorX# * Depth# + GetCameraX(1)
WorldY# = VectorY# * Depth# + GetCameraY(1)
WorldZ# = VectorZ# * Depth# + GetCameraZ(1)
*/
endfunction
// thanks santman
function makememblock(chk)
createobjectplane(999,7,7)
deletememblock(1)
deletememblock(chk)
CreateMemblockFromObjectMesh(1,999,1)
creatememblock(chk,10000000)
rem here we read the memblock to get it's data
off=0
vertcount=GetMemblockInt(1,off)
SetMemblockInt(chk,off,vertcount)
off=off+4
indicecount=GetMemblockInt(1,off)
SetMemblockInt(chk,off,indicecount)
off=off+4
attspervert=GetMemblockInt(1,off) // 3=position, normals & UV data
SetMemblockInt(chk,off,3)
off=off+4
vertsize=GetMemblockInt(1,off)
SetMemblockInt(chk,off,vertsize)
off=off+4
vertoff=GetMemblockInt(1,off)
SetMemblockInt(chk,off,vertoff)
off=off+4
indexoff=GetMemblockInt(1,off)
SetMemblockInt(chk,off,indexoff)
off=off+4
vertdat1=GetMemblockbyte(1,off)
SetMemblockbyte(chk,off,vertdat1)
vertdat2=GetMemblockbyte(1,off+1)
SetMemblockbyte(chk,off+1,vertdat2)
vertdat3=GetMemblockbyte(1,off+2)
SetMemblockbyte(chk,off+2,vertdat3)
vertdat4=GetMemblockbyte(1,off+3)
SetMemblockbyte(chk,off+3,vertdat4)
vertstring$=GetMemblockstring(1,off+4,vertdat4)
SetMemblockstring(chk,off+4,vertstring$)
off=off+4+vertdat4
vertdat5=GetMemblockbyte(1,off)
SetMemblockbyte(chk,off,vertdat5)
vertdat6=GetMemblockbyte(1,off+1)
SetMemblockbyte(chk,off+1,vertdat6)
vertdat7=GetMemblockbyte(1,off+2)
SetMemblockbyte(chk,off+2,vertdat7)
vertdat8=GetMemblockbyte(1,off+3)
SetMemblockbyte(chk,off+3,vertdat8)
vertstring2$=GetMemblockstring(1,off+4,vertdat8)
SetMemblockstring(chk,off+4,vertstring2$)
off=off+4+vertdat8
vertdat9=GetMemblockbyte(1,off)
SetMemblockbyte(chk,off,vertdat9)
vertdat10=GetMemblockbyte(1,off+1)
SetMemblockbyte(chk,off+1,vertdat10)
vertdat11=GetMemblockbyte(1,off+2)
SetMemblockbyte(chk,off+2,vertdat11)
vertdat12=GetMemblockbyte(1,off+3)
SetMemblockbyte(chk,off+3,vertdat12)
vertstring3$=GetMemblockstring(1,off+4,vertdat12)
SetMemblockstring(chk,off+4,vertstring3$)
off=off+4+vertdat12
vertnumchoice=0
off=vertoff+(vertnumchoice*vertsize)
xpos#=GetMemblockFloat(1,off)
ypos#=GetMemblockFloat(1,off+4)
zpos#=GetMemblockFloat(1,off+8)
xnorm#=GetMemblockFloat(1,off+12)
ynorm#=GetMemblockFloat(1,off+16)
znorm#=GetMemblockFloat(1,off+20)
u#=GetMemblockFloat(1,off+24)
v#=GetMemblockFloat(1,off+28)
deleteobject(999)
endfunction chk
function addplane(chk,xoff#,yoff#,zoff#,blockcount,x,z,y)
off=0
SetMemblockInt(chk,off,vertcount*(blockcount*6))
newfacecount=0
rem the front face
//if z>1
//if world[x,z-1,y]=0
for a=0 to 5
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 0
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 1
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 2
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 3
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 4
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 5
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+(a*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,-1.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the right face
//if x<chunksize
//if world[x+1,z,y]=0
for a=6 to 11
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 6
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 7
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 8
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 9
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 10
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 11
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
endselect
off2=vertoff+((a-6)*vertsize)
setmemblockfloat(chk,off+12,1.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the rear face
//if z<chunksize
//if world[x,z+1,y]=0
for a=12 to 17
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 12
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 13
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 14
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 15
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 16
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 17
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
endselect
off2=vertoff+((a-12)*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,1.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the left face
//if x>1
//if world[x-1,z,y]=0
for a=18 to 23
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 18
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 19
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 20
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 21
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 22
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 23
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+((a-18)*vertsize)
setmemblockfloat(chk,off+12,-1.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the top face
//if y<chunksize
//if world[x,z,y+1]=0
for a=24 to 29
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 24
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 25
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 26
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 27
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 28
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 29
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#+(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+((a-24)*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,1.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the bottom face
//if y>2
//if world[x,z,y-1]=0
for a=30 to 35
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 30
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 31
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 32
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 33
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#)
endcase
case 34
setmemblockfloat(chk,off,xoff#-(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
case 35
setmemblockfloat(chk,off,xoff#+(blocksize#/2))
setmemblockfloat(chk,off+4,yoff#-(blocksize#/2))
setmemblockfloat(chk,off+8,zoff#+blocksize#)
endcase
endselect
off2=vertoff+((a-30)*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,-1.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
endfunction
// thanks santman
function removeplane(chk,xoff#,yoff#,zoff#,blockcount,x,z,y)
off=0
// SetMemblockInt(chk,off,vertcount*(blockcount*6))
newfacecount=0
rem the front face
//if z>1
//if world[x,z-1,y]=0
for a=0 to 5
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 0
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 1
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 2
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 3
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 4
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 5
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+(a*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,-1.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the right face
//if x<chunksize
//if world[x+1,z,y]=0
for a=6 to 11
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 6
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 7
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 8
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 9
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 10
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 11
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+((a-6)*vertsize)
setmemblockfloat(chk,off+12,1.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the rear face
//if z<chunksize
//if world[x,z+1,y]=0
for a=12 to 17
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 12
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 13
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 14
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 15
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 16
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 17
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+((a-12)*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,1.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the left face
//if x>1
//if world[x-1,z,y]=0
for a=18 to 23
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 18
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 19
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 20
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 21
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 22
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 23
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+((a-18)*vertsize)
setmemblockfloat(chk,off+12,-1.0)
setmemblockfloat(chk,off+16,0.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the top face
//if y<chunksize
//if world[x,z,y+1]=0
for a=24 to 29
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 24
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 25
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 26
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 27
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 28
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 29
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+((a-24)*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,1.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
rem the bottom face
//if y>2
//if world[x,z,y-1]=0
for a=30 to 35
off=vertoff+((a+((blockcount-1)*36))*vertsize)
select a
case 30
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 31
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 32
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 33
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 34
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
case 35
setmemblockfloat(chk,off,xoff#)
setmemblockfloat(chk,off+4,yoff#)
setmemblockfloat(chk,off+8,zoff#)
endcase
endselect
off2=vertoff+((a-30)*vertsize)
setmemblockfloat(chk,off+12,0.0)
setmemblockfloat(chk,off+16,-1.0)
setmemblockfloat(chk,off+20,0.0)
setmemblockfloat(chk,off+24,GetMemblockFloat(1,off2+24))
setmemblockfloat(chk,off+28,GetMemblockFloat(1,off2+28))
facesdrawn=facesdrawn+1
newfacecount=newfacecount+1
next a
//endif
//endif
endfunction
// thanks santman
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/255.0,y/255.0)
noise = abs(noise)
//if x<chunksize# and y<chunksize# then
perlinmap[x,y,0].noise=noise/10
//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
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
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
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
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
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
offset = offset + 4
next
next
map=CreateImageFromMemblock(mem)
DeleteObject(mem)
endfunction map
// ***************************************************************************************************
// 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 createtextures(sizex# as float, sizey# as float,density, toptexture, bottomtexture)
if bottomtexture=0
//do a full block of the same texture
texturecount=toptexture
swap()
for a=0 to sizex# step density
for b=0 to sizey# step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
render()
textures[texturecount].id = getimage(0,0,sizex#, sizey#)
else
// do an half block with a different texture at bottom
texturecount=toptexture
swap()
for a=0 to sizex# step density
for b=0 to sizey#/3 step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
texturecount=bottomtexture
for a=0 to sizex# step density
for b=sizey#/3 to sizey# step density
rr=random(0,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
render()
textures[texturecount].id = getimage(0,0,sizex#, sizey#)
endif
endfunction textures[texturecount].id
function definetextures()
// grass=createtexture(64,64,0,200,0,8)
//grass
textures[0].r=0 :textures[0].dr=50
textures[0].g=255 :textures[0].dg=50
textures[0].b=0 :textures[0].db=50
//dirt
textures[1].r=139 :textures[1].dr=50
textures[1].g=69:textures[1].dg=50
textures[1].b=19:textures[1].db=50
//goldgold=createtexture(8,8,255,215,100,1)
textures[2].r=255 :textures[2].dr=50
textures[2].g=215 :textures[2].dg=50
textures[2].b=100 :textures[2].db=50
// water=createtexture(8,8,0,0,100,1)
textures[3].r=0 :textures[3].dr=50
textures[3].g=0 :textures[3].dg=50
textures[3].b=100 :textures[3].db=50
// lightwater=createtexture(8,8,39,89,45,1)
textures[4].r=0 :textures[4].dr=50
textures[4].g=100 :textures[4].dg=50
textures[4].b=100 :textures[4].db=50
// =createtexture(8,8,39,89,45,1)
textures[5].r=194 :textures[5].dr=50
textures[5].g=178 :textures[5].dg=50
textures[5].b=128 :textures[5].db=50
// create the texturs
textures[0].id = CreateTextures(8,8,1,0,0) // top
textures[1].id = CreateTextures(8,8,1,1,1) // bottom
textures[2].id = CreateTextures(8,8,1,2,2) // sides
textures[3].id = CreateTextures(8,8,1,3,3) // sides
textures[4].id = CreateTextures(8,8,1,4,4) // sides
textures[5].id = CreateTextures(8,8,1,5,5) // sides
endfunction
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,20000)
SetFogMode(1)
endfunction
Press the W a little bit to head into the air an then keep hold of space bar.
Im really not sure if this is doing this perfectly though
So if you could test as well, that would be grand
Thanks
edit - there only one snag - its duplicating the 1st created chunk - that will never do and will resolve, just testing removing blocks at moment