Hi there. I have done a cave example . I had to make a collision system as I couln't get the commands " GetObjectRayCastSlideX/y/z" to work . The script generate two image to build up the cave . I use the path :
"raw: D:\AGK2\the cave\media\tunel.png") .
Perhaps you will have to change folder path to make it work . Collision are a bit bumpy untill I find out a better way. I hope you like it !!
// Project: The Cave
// Created: 2018-12-24
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "The Cave" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
gosub heightmap
SetSpriteVisible(1,0)
setspritevisible(2,0)
setspritevisible(3,0)
gosub tunel
gosub cavetext
setspritevisible(3,1)
SetSpriteColorAlpha(4,50)
for i= 1 to 4
setspritesize(i,100,100)
next
render()
getimage(5,0,0,100,100)
for i= 1 to 4
setspritevisible(i,0)
next
SaveImage(5,"raw:D:\AGK2\the cave\media\tunel.png")
SaveImage(3,"raw:D:\AGK2\the cave\media\height.png")
`----------------------------------------------------------
CreateObjectFromHeightMap(1,"height.png",300,50,300,1,1)
setobjectcolor(1,60,60,60,0)
SetObjectCullMode(1,0)
setobjectimage(1,60,0)
CreateObjectFromHeightMap(2,"tunel.png",300,55,300,1,1)
setobjectcolor(2,40,40,40,0)
SetObjectCullMode(2,0)
setobjectimage(2,60,0)
`Starting point
setcameraposition(1,71,18,67)
`lighting setup
SetSunActive(0)
SetAmbientColor(0,0,0)
CreatePointLight(1,0,0,0,40,255,255,0)
createpointlight(2,109,25,43,50,255,255,255)
createpointlight(3,170,25,38,50,0,255,0)
`Creating some objects
gosub obj
do
gosub camara
Sync()
loop
heightmap:
`Colours
c1=MakeColor(30,30,30)
c2=makecolor(50,50,50)
c3=makecolor(70,70,70)
c4=makecolor(90,90,90)
c5=makecolor(110,110,110)
`texture
drawbox(0,0,100,100,c1,c4,c1,c2,1)
drawellipse(60,60,40,20,c3,c1,1)
drawellipse(20,20,50,30,c2,c1,1)
drawellipse(70,20,20,10,c4,c2,1)
drawellipse(20,60,20,35,c3,c4,1)
drawbox(30,70,50,100,c2,c1,c3,c2,1)
drawbox(60,20,80,80,c4,c1,c4,c3,1)
getimage(1,0,0,100,100)
createsprite(1,1)
setspritesize(1,30,30) `setting sprite size 30,30
render() `render to get image 2
getimage(2,0,0,30,30)
createsprite(2,2)
setspritesize(1,100,100) `setting back to 100,100
setspritesize(2,100,100)
render() `render to get image 3
`getting last blurred image
getimage(3,0,0,100,100)
createsprite(3,3)
return
tunel:
c1=makecolor(2,2,2)
col=makecolor(150,150,150)
drawbox(0,0,100,100,c1,c1,c1,c1,1)
drawellipse(50,50,40,40,col,col,1)
drawellipse(50,50,35,35,c1,c1,1)
drawbox(0,0,100,50,c1,c1,c1,c1,1)
for i= 1 to 6
drawline(10+i,50,30+i,15,col,col)
drawline(11+i,15,40+i,40,col,col)
drawline(40+i,40,45+i,60,col,col)
drawline(46+i,59,75+i,74,col,col)
drawline(84+i,50,64+i,16,col,col)
drawline(40+i,42,80+i,12,col,col)
drawline(5+i,74,27+i,56,col,col)
next
drawbox(31,14,70,17,col,col,col,col,1)
drawbox(45,60,50,74,col,col,col,col,1)
drawbox(48,15,52,5,col,col,col,col,1)
drawbox(48,88,55,90,c1,c1,c1,c1,1)
drawellipse(30,55,5,5,col,col,1)
drawellipse(8,73,5,5,col,col,1)
drawellipse(14,14,5,5,col,col,1)
render()
getimage(4,0,0,100,100)
createsprite(4,4)
return
cavetext:
for i= 1 to 125000
a=random(0,500)
b=random(0,500)
v=random(0,50)
col=makecolor(80+v,80+v,60+v)
drawline(a,b,a+2,b+2,col,col)
next
Render()
getimage(60,0,0,500,500)
return
camara:
if ( GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, 0.2 ) // cursor up
if ( GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -0.2 ) // cursor down
if ( GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -0.2 ) // cursor iz
if ( GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, 0.2 ) // cursor derecha
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if ( GetPointerState() = 1 )
fDiffX# = (GetPointerX() - startx#)/1.0
fDiffY# = (GetPointerY() - starty#)/1.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
x#=getcamerax(1)
y#=GetObjectHeightMapHeight( 1, x#, z# ) `first terrain
y2#=GetObjectHeightMapHeight( 2, x#, z# ) `second terrain
z#=getcameraz(1)
`Terrain Collision system
xd#=GetObjectHeightMapHeight(2,x#+2,z#)
xi#=GetObjectHeightMapHeight(2,x#-2,z#)
zf#=GetObjectHeightMapHeight(2,x#,z#+2)
zb#=GetObjectHeightMapHeight(2,x#,z#-2)
if xd#+1<y2# then dec x#,0.2
if xi#+1<y2# then inc x#,0.2
if zf#+1<y2# then dec z#,0.2
if zb#+1<y2# then inc z#,0.2
setcameraposition(1,x#,y#+2,z#)
setpointlightposition(1,x#,y#+10,z#)
return
obj:
createobjectcylinder(301,2,2,18)
setobjectposition(301,88,16,136)
SetObjectColor(301,100,100,0,0)
createobjectbox(302,1,1,1)
setobjectposition(302,174,9,39)
SetObjectColorEmissive(302,0,255,0)
createobjectsphere(303,2,10,10)
setobjectposition(303,41,10,255)
SetObjectColorEmissive(303,255,0,255)
createobjectbox(304,1,1,1)
setobjectposition(304,146,10,270)
SetObjectColorEmissive(304,0,255,0)
CreateObjectSphere(305,2,10,10)
setobjectposition(305,149,10,118)
SetObjectColorEmissive(305,255,155,0)
CreateObjectCylinder(306,35,0.3,16)
setobjectposition(306,179,16,107)
setobjectcolor(306,0,0,0,0)
cloneobject(307,306)
setobjectposition(307,179,16,104)
cloneobject(308,306)
setobjectposition(308,178,14,109)
cloneobject(309,306)
setobjectposition(309,179,14,105)
cloneobject(310,306)
setobjectposition(310,179,14,206)
return
Cheers.
I'm not a grumpy grandpa