Boosted it to
23 - #constant chunksize#=90
and FPS gets to around 60fps ish
and very nice feeling of infinite
Enjoy your building...
ive added the inventory blocks
// Project: rollingmap
// Created: 2018-02-13
// show all errors
SetErrorMode(2)
#constant screenwidth=800
#constant screenheight = 600
// set window properties
SetWindowTitle( "rollingmap" )a
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
//SetVSync(1)
// iniaialise variables that dont change
#constant chunksize#=90
#constant chunksizedepth#=128
#constant xMax=80*192
#constant yMax=80*192
#constant gridx=1
#constant gridy=1
#constant gridz=1
// initallise necessary globals that all functions can see and change
global camerastep#=.05
global playermovement#=.05
global player,oldobj
global mySelection=0
global cx#,cy#,cz#, blockcount
global magnetic=0
//camera variables
global mouse,angx#,angy#,startx#,starty#,cameray#,camerax#,cameraz#,lookmodey#,lookmodez#
// initalise the area map (192x192x256 - this will store locations of each added / deleted block
// this will be used to do Load/Save feature later on and move with the map
map as integer[200,200,256]
global playerblocks // stored the players object of which will use to add/destroy
global currentselectedplayblock
type _playblocks
spr
red
green
blue
endtype
global playblocks as _playblocks[10]
// 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
global textures as _textures[8]
// this is the main play chunk which will be used through out - it will live with the player and dynamically updated
// with map data when move around
type _chunk
x#,y#,z#
id
biome as string
texture
alpha
damage
endtype
global chunk as _chunk[chunksize#,chunksize#,chunksizedepth#]
global chunkplanes as integer[4] // four planes that sit on the out side of the chunk
global worldplane as integer
type _breakcube
id
x#
y#
z#
texture
endtype
global breakcube as _breakcube[10]
type _clouds
x#,y#,z#
id
endtype
global clouds as _clouds[chunksize#,chunksize#]
player = CreateObjectSphere(.05,20,20)
setupinventoryitems()
createblockpointer()
CreateInfoText()
definetextures()
setupplayerblocks()
setupclouds()
setupchunk()
setupskyandfog()
InitialiseStartingBlocks()
framestep#=timer()
lightningphasetimer#=random(20,50)
do
displayinventoryandhealth()
movecamerawithmouse()
checkkeypresses()
movecamera()
// cull_objs_behind_camera(1)
settextstring(17,"Frame Rate = "+str(ScreenFPS()))
print ("Blocks - " + str(blockcount) + " - FPS " + str(ScreenFPS()))
//start the lightning off and set of the sky lightning colour
if (timer()-framestep#>lightningphasetimer#)
SetSkyBoxSkyColor(200,200,200) //lightning charge
// SetFogMode(0)
endif
// wait a fraction before reseting back to skys original
if (timer()-framestep#>lightningphasetimer#+.03)
SetSkyBoxSkyColor(90,132,150)//nice horizon blue
// SetFogMode(1)
endif
// wait a fraction to add an extra lightning charge (realty we tend to see a few burts in one flash
if (timer()-framestep#>lightningphasetimer#+.06)
SetSkyBoxSkyColor(200,200,200)//lightniing charge
// SetFogMode(1)
endif
// wait a fraction before reseting back to skys original
if (timer()-framestep#>lightningphasetimer#+.09)
SetSkyBoxSkyColor(90,132,150)//nice horizon blue
// SetFogMode(1)
// reset the timer so that the lightning occures again, but spread it out abit
framestep#=timer()
lightningphasetimer=random(20,50)
endif
Sync()
loop
function movecamera()
///movecameras local to the player
SetObjectPosition(player,cx#,cy#,cz#)
cx#=getobjectx(player)
cz#=getobjectz(player)
cy#=getobjecty(player)
SetCameraPosition(1,cx#+camerax#,cy#+cameray#+lookmodey#+2,cz#-lookmodez#)
endfunction
function checkkeypresses()
if GetRawKeyState(40) then shiftmap(0,-camerastep#) //key down
if GetRawKeyState(38) then shiftmap(0,camerastep#) //key up
if GetRawKeyState(39) then shiftmap(camerastep#,0) //key right
if GetRawKeyState(37) then shiftmap(-camerastep#,0) //key left
if GetRawKeyPressed(76) // Key L - Look mode
if GetTextString(12) ="L Toggle at the chunk - Chunk mode"
SetTextString(12,"L Toggle at the chunk - Play mode")
lookmodey#=20
lookmodez#=40
else
SetTextString(12,"L Toggle at the chunk - Chunk mode")
lookmodey#=0
lookmodez#=0
endif
endif
//A - rotate camera
/* if GetRawKeyState(65) then RotateObjectLocalY(player,-camerastep#*50) //Key A
if GetRawKeyState(68) then RotateObjectLocalY(player,camerastep#*50) //key D
if GetRawKeyState(87) then RotateObjectLocalX(player,-camerastep#*5) //key W
if GetRawKeyState(83) then RotateObjectLocalX(player,camerastep#*5) //key S
*/
// 1-8 for textures
//if GetRawKeyPressed(48) // 0 - Loads editor
for a=49 to 58
if GetRawKeyPressed(a) then changeplayblock(a-49)
next
if GetRawKeyState(65) then dec camerax# //Key A
if GetRawKeyState(68) then inc camerax# //key D
if GetRawKeyState(87) then dec cameraz# //key W
if GetRawKeyState(83)
RotateObjectLocalX(player,camerastep#*10) //key S
RotateObjectLocalZ(player,camerastep#*10) //key S
endif
// 69 UP camera 67 downcamera
if GetRawKeyState(69) then inc cameray#,camerastep# //KEY_E
if GetRawKeyState(67) then dec cameray#,camerastep# //KEY_C
if mySelection <> 0
if GetObjectExists(mySelection)
// magneticPlace(mySelection,GetObjectSizeMaxX(mySelection),GetObjectSizeMaxX(mySelection))
// SetObjectColor(mySelection,255,255,255,255)
endif
endif
mySelection=0
/*
SetObjectScale(ObjectID,1.03,1.03,1.03)
SetObjectCullMode(ObjectID,2)
SetObjectColor(ObjectID,0,0,0,255)
DrawObject(ObjectID)
SetObjectScale(ObjectID,1,1,1)
SetObjectCullMode(ObjectID,1)
SetObjectColor(ObjectID,255,255,255,255) // Reset to old object color
*/
// attack / delete - maybe each type of cube with a certain texture as a damage ratio attached. like damage=10 = 10 hits before it deletes
if GetRawMouseRightPressed()
RotateObjectLocalX(player,camerastep#*5)
RotateObjectLocalZ(player,camerastep#*5) //key S
selectedObj=Click3dObject()
if GetObjectExists(selectedObj) and mySelection=0 then mySelection=selectedObj
if mySelection>0
// SetObjectColor(mySelection,150,150,150,20)
nx=1
nz=chunksizedepth#
ny=1
chunk[nx,ny,nz].id=CreateObjectBox(1,1,1)
chunk[nx,ny,nz].texture=textures[1].id
SetObjectImage(chunk[nx,ny,nz].id,chunk[nx,ny,nz].texture,1)
chunk[nx,ny,nz].x#=nx
chunk[nx,ny,nz].y#=nz+1
chunk[nx,ny,nz].z#=ny
chunk[nx,ny,nz].biome="land"
SetObjectPosition(chunk[nx,ny,nz].id,chunk[nx,ny,nz].x#,chunk[nx,ny,nz].z#,chunk[nx,ny,nz].y#)
SetObjectCullMode(chunk[nx,ny,nz].id,1)
if chunk[nx,ny,nz].biome="land" then chunk[nx,ny,nz].damage=5
chunk[nx,ny,nz].alpha=255
inc blockcount
DeleteObject(mySelection)
// shiftPiece(mySelection)
endif
endif
if GetRawMouseLeftPressed()
RotateObjectLocalX(player,camerastep#*50) //key S
RotateObjectLocalZ(player,camerastep#*50) //key S
selectedObj=Click3dObject()
if GetObjectExists(selectedObj) and mySelection=0 then mySelection=selectedObj
if mySelection>0
bl=CreateObjectBox(1,1,1)
SetObjectPosition(bl,getobjectx(myselection),getobjecty(myselection)+1,getobjectz(myselection))
// add the block according to what the play has in his hand
SetObjectImage(bl,textures[currentselectedplayblock].id,1)
// produce a count for debug purposes
inc blockcount
// store details some how in an map extension array
endif
endif
mouseOver=Click3dObject()
if GetObjectExists(mouseOver)
if getObjectExists(OldObj) then SetObjectColor(oldObj,255,255,255,255)
SetObjectColor(mouseOver,100,100,100,255)
oldObj=mouseOver
else
// SetObjectColor(oldObj,255,255,255,255)
endif
if GetRawKeyPressed(27) then end
endfunction
function initialisestartingblocks()
cx#=getobjectx(chunk[chunksize#/2,chunksize#/2,chunksizedepth#].id)
cy#=getobjecty(chunk[chunksize#/2,chunksize#/2,chunksizedepth#].id)+1
cz#=getobjectz(chunk[chunksize#/2,chunksize#/2,chunksizedepth#].id)+1
SetCameraPosition(1,cx#,cy#,cz#-200)
SetCameraRange(1,0.01,9000)
cameray#=0
//Get the starting coordingates for the mouse (the mouse always stays in centre of screen and the camera's move
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
// End
endfunction
function movecamerawithmouse()
SetSpritePosition(mouse,getpointerx(),getpointery())
fDiffX# = (GetPointerX() - startx#)
fDiffY# = (GetPointerY() - starty#)
newX# = angx# + fDiffY#
if ( newX# > 40 ) then newX# = 40
if ( newX# < -60 ) then newX# = -60
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
SetSpriteAngle(player,angy# + fDiffX#)
// These positions the block/weapon as if in the hand
// SetObjectRotation(playerblocks[0],newX#,angy#+fDiffX#,0)
SetObjectPosition(playerblocks,.012,1.95,-.1)
SetObjectRotation(player,3.6,fDiffX#,angy#)
endfunction
function setupskyandfog()
// setup a skybox
SetSunActive(0)
SetSkyBoxHorizonSize(4.1,4)
SetSkyBoxHorizonColor(90,132,150)//nice horizon blue
SetSkyBoxSkyColor(0,122,193)//thunder horison thunderblue
// SetSkyBoxHorizonColor(240,81,51)//sunset horiz
//SetSkyBoxSkyColor(253,187,48)//sunset sky
SetSkyBoxVisible(1)
SetFogColor(155,155,155)
SetFogRange(0,80)
SetFogMode(1)
endfunction
function setupchunk()
for a=0 to chunksize#
for b=0 to chunksize#
for z=0 to chunksizedepth#
// dont have a full block full of cubes, randomise it abit - so one, we conserve memory and 2 it will look like a cave
// the ground level have a complete flat surface for now until perlin noise comes
// otherwise shake underneath a bit.
// if random(1,10)>8 or z=chunksizedepth#-4
if z>chunksizedepth#-1
chunk[a,b,z].id=CreateObjectBox(1,1,1)
chunk[a,b,z].texture=textures[0].id
SetObjectImage(chunk[a,b,z].id,chunk[a,b,z].texture,1)
chunk[a,b,z].x#=a
chunk[a,b,z].y#=z
chunk[a,b,z].z#=b
chunk[a,b,z].biome="land"
SetObjectPosition(chunk[a,b,z].id,chunk[a,b,z].x#,chunk[a,b,z].z#,chunk[a,b,z].y#)
SetObjectCullMode(chunk[a,b,z].id,1)
if chunk[a,b,z].biome="land" then chunk[a,b,z].damage=5
chunk[a,b,z].alpha=255
inc blockcount
endif
next
next
next
// create the outsides
// front
/*
chunkplanes[0]=CreateObjectPlane(chunksize#,chunksizedepth#)
SetObjectPosition(chunkplanes[0],chunksize#/2,chunksizedepth#/2,0)
//right
chunkplanes[1]=CreateObjectPlane(chunksize#,chunksizedepth#)
SetObjectRotation(chunkplanes[1],0,90,0)
SetObjectPosition(chunkplanes[1],chunksize#,chunksizedepth#/2,chunksize#/2)
// back
chunkplanes[2]=CreateObjectPlane(chunksize#,chunksizedepth#)
SetObjectPosition(chunkplanes[2],chunksize#/2,chunksizedepth#/2,chunksize#)
//left
chunkplanes[3]=CreateObjectPlane(chunksize#,chunksizedepth#)
SetObjectRotation(chunkplanes[3],0,90,0)
SetObjectPosition(chunkplanes[3],0,chunksizedepth#/2,chunksize#/2)
// bottom
chunkplanes[4]=CreateObjectPlane(chunksize#,chunksize#)
SetObjectRotation(chunkplanes[4],90,90,0)
SetObjectPosition(chunkplanes[4],chunksize#/2,0,chunksize#/2)
for a=0 to 4
SetObjectImage(chunkplanes[a],textures[0].id,1)
SetImageWrapU(textures[0].id,1)
SetImageWrapv(textures[0].id,1)
// SetObjectUVScale(textures[0].id,0,1000,1000)
next
// worldplane = CreateObjectPlane(20000,20000)
//SetObjectRotation(worldplane,90,0,0)
//SetObjectPosition(worldplane,0,chunksizedepth#,0)
*/// display the chunks
shiftmap(0,0)
endfunction
function setupclouds()
// setup clouds
for a=1 to chunksize#/2
for b=1 to chunksize#/2
clouds[a,b].id=CreateObjectbox(random(1000,2000),random(1000,2000),2)
SetAmbientColor(255,255,255)
SetObjectRotation(clouds[a,b].id,270,0,0)
clouds[a,b].x#=random2(-20000,20000)
clouds[a,b].z#=random2(-20000,20000)
clouds[a,b].y#=random(500,600)
SetObjectPosition(clouds[a,b].id,clouds[a,b].x#,clouds[a,b].y#,clouds[a,b].z#)
SetObjectColor(clouds[a,b].id,255,255,255,255)
next
next
endfunction
function shiftPiece(mySelection as integer)
if GetRawKeyState(40) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection)-.05, GetObjectZ(mySelection) ) //key down
if GetRawKeyState(38) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection)+.05, GetObjectZ(mySelection) ) //key up
if GetRawKeyState(39) then SetObjectPosition( mySelection, GetObjectX(mySelection)-.05, GetObjectY(mySelection), GetObjectZ(mySelection) ) //key right
if GetRawKeyState(37) then SetObjectPosition( mySelection, GetObjectX(mySelection)+.05, GetObjectY(mySelection), GetObjectZ(mySelection) ) //key left
if GetRawKeyState(65) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection), GetObjectZ(mySelection)-.05 ) //Key A
if GetRawKeyState(90) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection), GetObjectZ(mySelection)+.05 ) //Key Z
for a=0 to chunksize#
for b=0 to chunksize#
for z=0 to chunksizedepth#
if chunk[a,b,z].id=mySelection
chunk[a,b,z].x#=GetObjectX(mySelection)
chunk[a,b,z].y#=GetObjectY(mySelection)
chunk[a,b,z].z#=GetObjectZ(mySelection)
endif
next z
next b
next a
endfunction
function shiftmap(xvalue#,zvalue#)
z=chunksizedepth#
for a=0 to chunksize#
for b=0 to chunksize#
inc chunk[a,b,z].x#,xvalue#
inc chunk[a,b,z].z#,zvalue#
inc clouds[a,b].x#,xvalue#
inc clouds[a,b].z#,zvalue#
if GetObjectExists(chunk[a,b,z].id )
if chunk[a,b,z].x#>chunksize#
chunk[a,b,z].x#=0
endif
if chunk[a,b,z].x#<0
chunk[a,b,z].x#=chunksize#
endif
if chunk[a,b,z].z#>chunksize#
chunk[a,b,z].z#=0
endif
if chunk[a,b,z].z#<0
chunk[a,b,z].z#=chunksize#
endif
SetObjectPosition(chunk[a,b,z].id,chunk[a,b,z].x#,chunk[a,b,z].y#,chunk[a,b,z].z#)
// if a>0 and a<50 and b>0 and b<50 then SetObjectPosition(clouds[a,b].id,clouds[a,b].x#,clouds[a,b].y#,clouds[a,b].z#)
endif
next
next
endfunction
function moveclouds()
endfunction
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=80 :textures[0].dg=100
textures[0].b=0 :textures[0].db=50
//dirt
textures[1].r=139 :textures[1].dr=20
textures[1].g=69:textures[1].dg=20
textures[1].b=19:textures[1].db=20
//goldgold=createtexture(8,8,255,215,100,1)
textures[2].r=255 :textures[2].dr=100
textures[2].g=215 :textures[2].dg=10
textures[2].b=100 :textures[2].db=10
// water=createtexture(8,8,0,0,100,1)
textures[3].r=0 :textures[3].dr=50
textures[3].g=0 :textures[3].dg=10
textures[3].b=100 :textures[3].db=10
// emeralds=createtexture(8,8,39,89,45,1)
textures[4].r=39 :textures[4].dr=5
textures[4].g=89 :textures[4].dg=5
textures[4].b=45 :textures[4].db=5
// create the texturs
textures[0].id = CreateTextures(64,64,4,0,0) // top
textures[1].id = CreateTextures(64,64,4,1,1) // bottom
textures[2].id = CreateTextures(64,64,4,2,2) // sides
textures[3].id = CreateTextures(64,64,4,3,3) // sides
textures[4].id = CreateTextures(64,64,4,4,4) // sides
endfunction
function Click3dObject()
myX as float
myY as float
my3dX as float
my3dY as float
my3dZ as float
rayStartX as float
rayStartY as float
rayStartZ as float
rayEndX as float
rayEndY as float
rayEndZ as float
myX=GetPointerX()
myY=GetPointerY()
my3dX=Get3DVectorXFromScreen(myX,myY)
my3dY=Get3DVectorYFromScreen(myX,myY)
my3dZ=Get3DVectorZFromScreen(myX,myY)
rayStartX=my3dX+GetCameraX(1)
rayStartY=my3dY+GetCameraY(1)
rayStartZ=my3dZ+GetCameraZ(1)
rayEndX=800*my3dX+GetCameraX(1)
rayEndY=800*my3dY+GetCameraY(1)
rayEndZ=800*my3dZ+GetCameraZ(1)
theObjectHit= ObjectRayCast(0,rayStartX,rayStartY,rayStartZ,rayEndX,rayEndY,rayEndZ)
for a=0 to 4
if theObjectHit=chunkplanes[a] then theObjectHit=0
next
Print(theObjectHit)
endfunction theObjectHit
function magneticPlace(mySelection,x#,y#)
X1#=GetObjectX(mySelection)
Y1#=GetObjectY(mySelection)
Z1#=GetObjectZ(mySelection)
if magnetic=1
X1#=floor(X1#/gridx)
Y1#=floor(Y1#/gridy)
Z1#=floor(Z1#/gridz)
endif
SetObjectPosition( mySelection, X1#, Y1#, Z1# )
shiftPiece(mySelection)
endfunction
// this creates the centre pointer
function createblockpointer()
swap()
DrawLine(0,5,10,5,MakeColor(255,255,0),MakeColor(255,255,0))
DrawLine(5,0,5,10,MakeColor(255,255,0),MakeColor(255,255,0))
DrawEllipse(5,5,5,5,MakeColor(255,255,0),MakeColor(255,255,0),0)
render()
mouse = CreateSprite(GetImage(0,0,10,10))
SetRawMousePosition(screenwidth/2,screenheight/2)
SetRawMouseVisible(0)
endfunction
function CreateInfoText()
createtext(1,"CraftLite") // Create the text to display current level number ******
createtext(2,"Left Arrow move left.") //create the text to keep track of how many objects we have so far
createtext(3,"Right Arrow move left.")
createtext(4,"Up Arrow move forward.")
createtext(5,"Down Arrow move back.")
createtext(6,"W Rotate up")
CreateText(7,"A Rotate left.")
CreateText(8,"S Rotate down.")
CreateText(9,"D Rotate Right.")
CreateText(10,"E Move Up.")
CreateText(11,"C Move Down.")
CreateText(12,"L Toggle at the chunk - Play mode")
CreateText(13,"Hold down shift to select.")
CreateText(14,"Selection="+str(mySelection))
CreateText(15,"M toggle snap to grid.")
CreateText(16,"Magnetic ="+str(magnetic))
CreateText(17,"Esc exit.")
CreateText(18,"Frame Rate=")
settextsize(1,20)
settextsize(2,20)
settextsize(3,20)
settextsize(4,20)
SetTextSize(5,20)
settextsize(6,20)
settextsize(7,20)
settextsize(8,20)
settextsize(9,20)
settextsize(10,20)
settextsize(11,20)
settextsize(12,20)
settextsize(13,20)
settextsize(14,20)
settextsize(15,20)
settextsize(16,20)
settextsize(17,20)
settextsize(18,20)
settextposition(1,10,20)
settextposition(2,10,40)
settextposition(3,10,60)
settextposition(4,10,80)
settextposition(5,10,100)
settextposition(6,10,120)
settextposition(7,10,140)
settextposition(8,10,160)
settextposition(9,10,180)
settextposition(10,10,200)
settextposition(11,10,220)
settextposition(12,10,240)
settextposition(13,10,260)
settextposition(14,10,280)
settextposition(15,10,300)
settextposition(16,10,320)
settextposition(17,10,340)
settextposition(18,10,340)
FixTextToScreen(1,1)
FixTextToScreen(2,1)
FixTextToScreen(3,1)
FixTextToScreen(4,1)
FixTextToScreen(5,1)
FixTextToScreen(6,1)
FixTextToScreen(7,1)
FixTextToScreen(8,1)
FixTextToScreen(9,1)
FixTextToScreen(10,1)
FixTextToScreen(11,1)
FixTextToScreen(12,1)
FixTextToScreen(13,1)
FixTextToScreen(14,1)
FixTextToScreen(15,1)
FixTextToScreen(16,1)
FixTextToScreen(17,1)
FixTextToScreen(18,1)
SetTextColor(1,0,200,0,255)
SetTextColor(17,200,0,0,255)
endfunction
// this creates the hand weapon to distroy /block to add and places on bottom right corner of the camera
function setupplayerblocks()
playerblocks = CreateObjectBox(.02,.02,.04)
SetObjectImage(playerblocks,textures[0].id,1)
FixObjectToObject(playerblocks,player)
SetObjectRotation(playerblocks,-25,-10,-2)
currentselectedblock=0
endfunction
function screenselector()
// Develop a combo style list to choose a screen resolution
/*
Fullscreen
1920x1080
1680x1050
1600x900
1440x900
1440x1050
1366x768
1360x768
1280x1024
1280x800
1280x768
1280x720
1024x768
800x600
*/
endfunction
function changeplayblock(id)
SetObjectImage(playerblocks,textures[id].id,1)
currentselectedplayblock=id
endfunction
function GetObjectInFront(obj, cam)
x1# = GetCameraX(cam)
y1# = GetCameraY(cam)
z1# = GetCameraZ(cam)
dx# = GetObjectX(obj) - x1#
dy# = GetObjectY(obj) - y1#
dz# = GetObjectZ(obj) - z1#
d# = sqrt(dx#*dx# + dy#*dy# + dz#*dz#)
ux1# = dx#/d#
uy1# = dy#/d#
uz1# = dz#/d#
d# = 3
MoveCameraLocalZ(cam, d#)
dx# = GetCameraX(cam) - x1#
dy# = GetCameraY(cam) - y1#
dz# = GetCameraZ(cam) - z1#
MoveCameraLocalZ(cam, -d#)
ux2# = dx#/d#
uy2# = dy#/d#
uz2# = dz#/d#
res# = ux1# * ux2# + uy1# * uy2# + uz1# * uz2#
angle# = acos(res#)
inFront = 0
////////CHANGE THIS////////////
if angle# < 30 then inFront = 1
endfunction inFront
function cull_objs_behind_camera(mode) /// adapted to my own project but the jist is too cull all objects
z=0
for x = 0 to chunksize#
for y = 0 to chunksize#
// for z=0 to chunksizedepth#
if GetObjectExists( chunk[x,y,z].id )
v = GetObjectInFront( chunk[x,y,z].id, 1 )
if mode=1
if v = 0 then SetBoxVisible( x,y,z, 0 )
if v = 1 then SetBoxVisible( x,y,z, 1 )
else
SetBoxVisible(x,y,z,0)
endif
endif
// next
next
next
endfunction
function SetBoxVisible (x,y,z, mode)
if mode=1
SetObjectVisible(chunk[x,y,z].id,1)
// SetObjectVisible(cube.top,0)
else
SetObjectVisible(chunk[x,y,z].id,0)
// SetObjectPosition(blocks[x,y],bl//ocks[x,y]-playareax,0,blockpositiony-playareay)
endif
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)
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()
SetSpritePosition(mouse,getpointerx(),getpointery())
for a=0 to 9
SetSpritePosition(playblocks[a].spr,(screenwidth/2-(50*5))+a*50,screenheight-150)
next
endfunction
// interopolation for RGB
// send in colorfrom
// colorto - this maybe sky color
// t - time it takes so this could be travelling down to earth
/*
to be converted
public static Color LerpRGB (Color a, Color b, float t)
{
return new Color
(
a.r + (b.r - a.r) * t,
a.g + (b.g - a.g) * t,
a.b + (b.b - a.b) * t,
a.a + (b.a - a.a) * t
);
}
*/