Hi there . I have been busy for a while . I had to anlock my old trick thread .
Here I show you a easy random dungeon . It has collision but at the moment you can not save the the level. You had better to use you own nice textures . I hope you like it .
- Random Dungeon
// Project: Tiles
// Created: 2018-11-04
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Tiles" )
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( 60, 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
`USE HERE YOUR OWN TEXTURES
`loadimage(1,"stone03b.jpg")
`loadimage(2,"suelo.jpg")
w=makecolor(100,70,20)
drawbox(0,0,100,100,w,w,w,w,1)
w=makecolor(150,100,25)
drawbox(5,5,95,95,w,w,w,w,1)
getimage( 1,0,0,100,100)
for i= 1 to 1000
a=random(10,90)
b=random(10,90)
drawbox(a,b,a+1,b+1,w,w,w,w,1)
next
getimage(2,0,0,100,100)
CreateObjectBox(1000,2,10,2)
SetObjectColor(1000,255,0,0,0)
SetObjectPosition(1000,20,0,-30)
// CAMARA
SetCameraPosition(1,-120,100,-120)
SetCameraLookAt(1,30,0,0,0)
setcamerarange(1,0.1,80000)
CreateObjectSphere(80000,2000,10,10)
SetObjectColorEmissive(80000,0,0,255)
SetObjectCullMode(80000,0)
sleeping=30
ob=1
repeat
oldx# = GetObjectX(1000)
oldy# = GetObjectY(1000)
oldz# = GetObjectZ(1000)
x# = GetObjectX(1000)
y# = GetObjectY(1000)
z# = GetObjectZ(1000)
colli= ObjectRayCast(0,oldx#,oldy#-5,oldz# ,x#,y#+5,z#)
if colli>0 then CreateObjectBox(ob,10,0,10) :SetObjectPosition(ob,x#,y#,z#) :SetObjectimage(ob,2,0): inc ob,1 :MoveObjectLocalZ( 1000,10)
if colli=1000 then SetObjectRotation(1000,0,0+random(0,3)*90,0)
sleep(sleeping) `just for timelapse
print(ob)
SYNC()
until ob=100
`South Walls
pa=170
for t= 1 to ob-1
xx# = GetObjectX(t)
yy# = GetObjectY(t)
zz# = GetObjectZ(t)
SetObjectPosition(1000,xx#,yy#,zz#-10)
oldx# = GetObjectX(1000)
oldy# = GetObjectY(1000)
oldz# = GetObjectZ(1000)
x# = GetObjectX(1000)
y# = GetObjectY(1000)
z# = GetObjectZ(1000)
colli= ObjectRayCast(0,oldx#,oldy#-5,oldz#-5 ,x#,y#+5,z#)
if colli=1000
CreateObjectBox(pa,10,10,0) :SetObjectPosition(pa,x#,y#+5,z#+5) :SetObjectimage(pa,1,0): inc pa,1
endif
next t
`-------------------------------------------------------------------------------------------
`North Walls
for t= 1 to ob-1
xx# = GetObjectX(t)
yy# = GetObjectY(t)
zz# = GetObjectZ(t)
SetObjectPosition(1000,xx#,yy#,zz#+10)
oldx# = GetObjectX(1000)
oldy# = GetObjectY(1000)
oldz# = GetObjectZ(1000)
x# = GetObjectX(1000)
y# = GetObjectY(1000)
z# = GetObjectZ(1000)
colli= ObjectRayCast(0,oldx#,oldy#-5,oldz#-5 ,x#,y#+5,z#)
if colli=1000
CreateObjectBox(pa,10,10,0) :SetObjectPosition(pa,x#,y#+5,z#-5) :SetObjectimage(pa,1,0) :inc pa,1
endif
next t
`-------------------------------------------------------------------------------------------
`Right walls
for t= 1 to ob-1
xx# = GetObjectX(t)
yy# = GetObjectY(t)
zz# = GetObjectZ(t)
SetObjectPosition(1000,xx#+10,yy#,zz#)
oldx# = GetObjectX(1000)
oldy# = GetObjectY(1000)
oldz# = GetObjectZ(1000)
x# = GetObjectX(1000)
y# = GetObjectY(1000)
z# = GetObjectZ(1000)
colli= ObjectRayCast(0,oldx#-5,oldy#-5,oldz# ,x#,y#+5,z#)
if colli=1000
CreateObjectBox(pa,0,10,10) :SetObjectPosition(pa,x#-5,y#+5,z#) :SetObjectimage(pa,1,0) :inc pa,1
endif
next t
`-------------------------------------------------------------------------------------------
`Left Walls
for t= 1 to ob-1
xx# = GetObjectX(t)
yy# = GetObjectY(t)
zz# = GetObjectZ(t)
SetObjectPosition(1000,xx#-10,yy#,zz#)
oldx# = GetObjectX(1000)
oldy# = GetObjectY(1000)
oldz# = GetObjectZ(1000)
x# = GetObjectX(1000)
y# = GetObjectY(1000)
z# = GetObjectZ(1000)
colli= ObjectRayCast(0,oldx#-5,oldy#-5,oldz# ,x#,y#+5,z#)
if colli=1000
CreateObjectBox(pa,0,10,10) :SetObjectPosition(pa,x#+5,y#+5,z#) :SetObjectimage(pa,1,0) :inc pa,1
rem SetCameraPosition(1,getobjectx(1),getobjecty(1)+5,getobjectz(1))
endif
next t
`ceiling
for i= 1 to ob-1
cloneobject(i+3000,ob-1)
setobjectposition(i+3000,getobjectx(i),getobjecty(i)+10,getobjectz(i))
setobjectimage(i+3000,3,0) `asignar textura que no existe para eliminarla
setobjectcolor(i+3000,160,160,160,255)
next
`lights
createpointlight(1,0,0,0,40,255,255,0)
createpointlight(2,getobjectx(2),5,getobjectz(2),40,0,255,0)
createpointlight(3,getobjectx(55),5,getobjectz(55),40,255,0,0)
createpointlight(4,getobjectx(95),5,getobjectz(95),40,0,0,255)
level=0
do
SetObjectPosition(1000,0,1000,0)
if ( GetRawKeyState( 84 ) )
setcameraposition(1,getobjectx(5),getobjecty(5)+5,getobjectz(5))
SetSunActive(0)
SetAmbientColor(0,0,0)
level=1
endif
if level=1
rem Old position
oldx#=GetCameraX(1)
oldy#=GetCameraY(1)
oldz#=GetCameraZ(1)
`
rem Move camera
if ( GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, 0.5 ) `Up
if ( GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -0.5 ) `Down
if ( GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -0.5 ) `Left
if ( GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, 0.5 ) `Right
if ( GetRawKeyState( 27 ) ) then end
rem Gravity on camera
SetCameraPosition(1,getcamerax(1),getcameray(1)-0.5,getcameraz(1))
//SetPointLightPosition(1,getcamerax(1),getcameray(1),getcameraz(1))
rem New position
newx#=GetCameraX(1)
newy#=GetCameraY(1)
newz#=GetCameraZ(1)
`
rem Adjust Y to match floor
if ObjectSphereSlide(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,4)>0
newx#=GetObjectRayCastSlideX(0)
newy#=GetObjectRayCastSlideY(0)
newz#=GetObjectRayCastSlideZ(0)
SetCameraPosition(1,newx#,newy#,newz#)
endif
turn=getpointery()
if turn<330 then turn=330
if turn>420 then turn=420
if turn<331 then SetRawMousePosition( getpointerx(), turn )
if turn>421 then SetRawMousePosition( getpointerx(), turn )
if getpointerx()<2 then SetRawMousePosition(722,getpointery())
if getpointerx()>1022 then SetRawMousePosition(668,getpointery())
setcamerarotation(1,turn,getpointerx(),0)
setpointlightposition(1,getcamerax(1),getcameray(1),getcameraz(1))
endif
print("Press T to Test Level")
Sync()
`
loop
I'm not a grumpy grandpa