So far
// Project: rollingmap
// Created: 2018-02-13
// show all errors
SetErrorMode(2)
#constant screenwidth=1024
#constant screenheight = 768
// set window properties
SetWindowTitle( "rollingmap" )
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( 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
#constant chunksize#=80
#constant xMax=80*192
#constant yMax=80*192
#constant gridx=1
#constant gridy=1
#constant gridz=1
#constant KEY_F1 = 112
#constant KEY_F2 = 113
#constant KEY_W = 87
#constant KEY_A = 65
#constant KEY_S = 83
#constant KEY_D = 68
#constant KEY_Left = 37
#constant KEY_Right = 39
#constant KEY_Up = 38
#constant KEY_Down = 40
#constant KEY_Shift = 16
#constant KEY_M = 77
#constant KEY_E = 69
#constant KEY_C = 67
#constant KEY_Escape = 27
#constant KEY_Backspace= 8
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]
map as integer[192,192,256]
type _chunk
x#,y#,z#
id
biome as string
texture
alpha
endtype
global chunk as _chunk[chunksize#,chunksize#]
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#]
global camerastep#=.05
global player
global mySelection=0
global cx#,cy#,cz#, blockcount
global magnetic=0
player = CreateObjectSphere(.05,20,20)
//camera variables
global mouse,angx#,angy#,startx#,starty#,cameray#
createblockpointer()
CreateInfoText()
definetextures()
setupclouds()
setupchunk()
setupskyandfog()
InitialiseStartingBlocks()
lockSelection=0
do
SetObjectPosition(player,cx#,cy#,cz#)
if lockSelection=0
selectedObj=Click3dObject()
if GetObjectExists(selectedObj) then SetObjectColor(selectedObj,100,100,100,255)
if GetObjectExists(mySelection) and mySelection<>selectedObj then SetObjectColor(mySelection,255,255,255,255)
mySelection=selectedObj
endif
movecamerawithmouse()
if GetRawMouseLeftPressed()
lockSelection=0
if GetObjectExists(selectedObj) and mySelection=0 then mySelection=selectedObj
if mySelection>0
oldX#=getObjectX(mySelection)
oldY#=getObjectY(mySelection)
oldZ#=getObjectZ(mySelection)
texture=getTexture(mySelection)
setupFirework(1,texture,getObjectX(mySelection),getObjectY(mySelection),getObjectZ(mySelection))
//Update3DParticles(1,0)
DeleteObject(mySelection)
mySelection=0
endif
endif
if GetRawMouseRightPressed()
if lockSelection=0
lockSelection=1
else
lockSelection=0
endif
endif
if GetRawMouseRightState()
//if GetObjectExists(selectedObj) and mySelection=0
// mySelection=selectedObj
//else
// mySelection=0
//endif
if mySelection=selectedObj
if GetObjectExists(mySelection)
if GetRawKeyState(KEY_Down) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection)-.05, GetObjectZ(mySelection) ) //key down
if GetRawKeyState(KEY_Up) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection)+.05, GetObjectZ(mySelection) ) //key up
if GetRawKeyState(KEY_Right) then SetObjectPosition( mySelection, GetObjectX(mySelection)-.05, GetObjectY(mySelection), GetObjectZ(mySelection) ) //key right
if GetRawKeyState(KEY_LEFT) then SetObjectPosition( mySelection, GetObjectX(mySelection)+.05, GetObjectY(mySelection), GetObjectZ(mySelection) ) //key left
if GetRawKeyState(KEY_W) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection), GetObjectZ(mySelection)-.05 ) //Key A
if GetRawKeyState(KEY_S) then SetObjectPosition( mySelection, GetObjectX(mySelection), GetObjectY(mySelection), GetObjectZ(mySelection)+.05 ) //Key Z
if GetRawKeyState(KEY_A) then SetObjectRotation( mySelection, GetObjectAngleX(mySelection), (GetObjectAngleY(mySelection)-0.5),GetObjectAngleZ(mySelection))
if GetRawKeyState(KEY_D) then SetObjectRotation( mySelection, GetObjectAngleX(mySelection), (GetObjectAngleY(mySelection)+0.5),GetObjectAngleZ(mySelection))
magneticPlace(mySelection)
endif
elseif mySelection=0
bl=CreateObjectBox(1,1,1)
SetObjectPosition(bl,getobjectx(myselection),getobjecty(myselection)+1,getobjectz(myselection))
// check which BIOME we are in and set the texture for that, for now just do land
SetObjectImage(bl,textures[0].id,1)
inc blockcount
shiftPiece(mySelection)
// store details some how in an map extension array
endif
else
if GetRawKeyState(KEY_Down) then shiftmap(0,-.5) //key down
if GetRawKeyState(KEY_Up) then shiftmap(0,.5) //key up
if GetRawKeyState(KEY_Right) then shiftmap(.5,0) //key right
if GetRawKeyState(KEY_Left) then shiftmap(-.5,0) //key left
endif
if GetRawKeyPressed(KEY_Escape) then end
//movecameras
cx#=getobjectx(player)
cz#=getobjectz(player)
cy#=getobjecty(player)
SetCameraPosition(1,cx#,cy#+cameray#,cz#)
// setcamerarotation(1,GetObjectAngleX(player),getobjectangley(player),GetObjectAngleZ(player))
if GetRawKeyPressed(Key_M) //M
if magnetic=0
magnetic=1
settextstring(15,"Magnetic = On")
else
magnetic=0
settextstring(15,"Magnetic = Off")
endif
endif
setTextString(13,"Selection="+str(mySelection))
settextstring(17,"Frame Rate = "+str(ScreenFPS()))
if Get3DParticlesExists(1) //and lockSelection=0
if Get3DParticlesLife(1)>1.0 then Delete3DParticles(1)
endif
Sync()
loop
function initialisestartingblocks()
cx#=getobjectx(chunk[chunksize#/2,chunksize#/2].id)
cy#=getobjecty(chunk[chunksize#/2,chunksize#/2].id)+1
cz#=getobjectz(chunk[chunksize#/2,chunksize#/2].id)+1
SetCameraPosition(1,cx#,cy#,cz#)
// RotateObjectLocalY(player,180)
SetCameraRange(1,0.01,9000)
cameray#=1
//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# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
cameray#=tan(GetRawMouseWheel()/360)*1000
endfunction
function setupskyandfog()
// setup a skybox
SetSunActive(0)
SetSkyBoxHorizonSize(4.0,4)
SetSkyBoxHorizonColor(255,255,255)
SetSkyBoxSkyColor(135,206,250)
SetSkyBoxVisible(1)
SetFogColor(155,155,155)
SetFogRange(0,180)
SetFogMode(1)
endfunction
function setupchunk()
for a=0 to chunksize#
for b=0 to chunksize#
chunk[a,b].id=CreateObjectBox(1,1,1)
SetObjectPosition(chunk[a,b].id,a,1,b)
SetObjectCullMode(chunk[a,b].id,1)
k=random(1,2)
if k=1 then chunk[a,b].texture=textures[0].id
if k=2 then chunk[a,b].texture=textures[1].id
SetObjectImage(chunk[a,b].id,chunk[a,b].texture,1)
chunk[a,b].x#=a
chunk[a,b].y#=random(0,1)
chunk[a,b].z#=b
chunk[a,b].biome="land"
chunk[a,b].alpha=255
inc blockcount
next
next
// display the chunks
shiftmap(0,0)
endfunction
function setupclouds()
// setup clouds
for a=1 to 50
for b=1 to 50
clouds[a,b].id=CreateObjectPlane(random(40,80),random(4,80))
SetAmbientColor(255,255,255)
SetObjectRotation(clouds[a,b].id,270,0,0)
clouds[a,b].x#=random2(-9000,9000)
clouds[a,b].z#=random2(-9000,9000)
clouds[a,b].y#=128
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)
for a=0 to chunksize#
for b=0 to chunksize#
if chunk[a,b].id=mySelection and GetObjectExists(mySelection)
chunk[a,b].x#=GetObjectX(mySelection)
chunk[a,b].y#=GetObjectY(mySelection)
chunk[a,b].z#=GetObjectZ(mySelection)
endif
next b
next a
endfunction
function getTexture(mySelection as integer)
texture=0
for a=0 to chunksize#
for b=0 to chunksize#
if chunk[a,b].id=mySelection and GetObjectExists(mySelection)
texture=chunk[a,b].texture
endif
next b
next a
endfunction texture
function shiftmap(xvalue#,zvalue#)
for a=0 to chunksize#
for b=0 to chunksize#
inc chunk[a,b].x#,xvalue#
inc chunk[a,b].z#,zvalue#
inc clouds[a,b].x#,xvalue#
inc clouds[a,b].z#,zvalue#
if GetObjectExists(chunk[a,b].id )
if chunk[a,b].x#>chunksize#
chunk[a,b].x#=0
chunk[a,b].y#=random(0,1)
endif
if chunk[a,b].x#<0
chunk[a,b].x#=chunksize#
chunk[a,b].y#=random(0,1)
endif
if chunk[a,b].z#>chunksize#
chunk[a,b].z#=0
chunk[a,b].y#=random(0,1)
endif
if chunk[a,b].z#<0
chunk[a,b].z#=chunksize#
chunk[a,b].y#=random(0,1)
endif
SetObjectPosition(chunk[a,b].id,chunk[a,b].x#,chunk[a,b].y#,chunk[a,b].z#)
SetObjectCullMode(chunk[a,b].id,2)
SetObjectColor(chunk[a,b].id,0,0,0,255)
DrawObject(chunk[a,b].id)
SetObjectCullMode(chunk[a,b].id,1)
SetObjectColor(chunk[a,b].id,255,255,255,255) // Reset to old object color
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)
//fire=createtexture(8,8,255,0,0,1)
//sand=createtexture(8,8,194,178,128,1)
//wood=createtexture(8,8,102,51,0,1)
//grassfull=createtexture(64,64,0,200,0,8)
//SetObjectImage(plane,grassfull,1)
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(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#)
endif
sleep(0)
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=1
textures[2].b=100 :textures[2].db=1
// water=createtexture(8,8,0,0,100,1)
textures[3].r=0 :textures[3].dr=50
textures[3].g=0 :textures[3].dg=1
textures[3].b=100 :textures[3].db=1
// 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,0,1) // 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)
Print(theObjectHit)
endfunction theObjectHit
function magneticPlace(mySelection)
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
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,"Select by clicking with mouse.")
CreateText(13,"Selection="+str(mySelection))
CreateText(14,"M toggle snap to grid.")
CreateText(15,"Magnetic ="+str(magnetic))
CreateText(16,"Esc exit.")
CreateText(17,"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)
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)
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)
SetTextColor(1,0,200,0,255)
SetTextColor(17,200,0,0,255)
endfunction
function setupFirework(obj as integer,texture as integer,x as float,y as float,z as float)
if Get3DParticlesExists(obj) then Delete3DParticles(obj)
Create3DParticles(obj,x,y,z) //id,x,y
Set3DParticlesSize(obj,.22) //pixel size of particles
Set3DParticlesImage( obj, texture )
Set3DParticlesLife(obj,1) //sets the length of 1 seconds the particles live
Set3DParticlesMax(obj,50) //max number of particles set to 25 f
Set3DParticlesDirectionRange( obj,180, 180 )
`SetParticlesActive(1,0)
//Add3DParticlesForce(obj,1,4,x,y,z) //The time a particle has to wait before forces apply
Set3DParticlesFrequency(obj,100) //Sets the frequency of new particle generation
Set3DParticlesVelocityRange(obj,2,4) //velocity factor of particles ranging from min of 2 to 4
Set3DParticlesColorInterpolation(obj,0) //1 smooth 0 none
//Set3DParticlesVisible( obj, 0 ) //hide particles when they first created so as timer can be used
endfunction
There is now an explosion of particles when you delete one and you can move around world again
but only when you are not holding down the right mouse
fubar