Hi there .
Here's my old tank in action ! . At the moment no bombs ...just showing the trail where it passes . I hope you like it .
// Project: Caterpillar
// Created: 2018-12-02
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Caterpillar" )
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 texture
`floor
createobjectbox(5000,2300,1,2300)
setobjectcolor(5000,100,80,20,0)
SetObjectPosition(5000,0,-3,0)
`our Sky
createobjectcylinder(5001,1000,1000,40)
SetObjectCullMode(5001,0)
SetObjectColor(5001,150,150,255,0)
`caterpillar body
Createobjectbox(1,10,4,15) :col(1)
setobjectposition(1,0,4,0)
CreateObjectSphere(5002,8,15,15) :col(5002)
setobjectscale(5002,1,1,1.5)
RotateObjectLocalX(5002,5)
setobjectposition(5002,0,1,-1.5)
FixObjectToObject(5002,1)
createobjectbox(5003,15,3,12) :col(5003)
FixObjectToObject(5003,1)
CreateObjectCylinder(5004,25,2,15) :col(5004)
setobjectrotation(5004,90,0,0)
setobjectposition(5004,0,3,8)
FixObjectToObject(5004,1)
`left caterpillar wheel
createobjectcylinder(2,8,15,30)
SetObjectScale(2,0.4,0.4,1.5)
SetObjectTransparency(2,1)
SetObjectCullMode(2,0)
setobjectrotation(2,0,0,90)
FixObjectPivot(2)
setobjectposition(2,-7,0,0)
fixobjecttoobject(2,1)
setobjectimage(2,100,0)
mesh = CreateMemblockFromObjectMesh(2,1)
verts= GetMemblockInt( mesh, 0 )
for i= 0 to verts-1
x#=GetMeshMemblockVertexX(mesh,i)
y#=GetMeshMemblockVertexy(mesh,i)
z#=GetMeshMemblockVertexz(mesh,i)
if i<90 then SetMeshMemblockVertexPosition(mesh,i, 0,0,0)
if i>360-90 then SetMeshMemblockVertexPosition(mesh,i, 0,0,0)
next i
`fixing caterpillar mesh
SetObjectMeshFromMemblock(2,1,mesh)
`right caterpillar wheel
cloneobject(3,2)
setobjectposition(3,7,0,0)
fixobjecttoobject(3,1)
`making an object that follows the main body to check distance and create trail
sensor=50000
createobjectbox(sensor,0,0,0)
setobjectposition(sensor,getobjectx(1),0,getobjectz(1))
SetCameraPosition(1,-70,70,-130)
SetCameraLookAt(1,0,0,0,0)
trail=25000
do
`scrolling texture system
co#=co#+0.01
if co#>0.08 then co#=0
if co#<-0.08 then co#=0
if ( GetRawKeyState( 39 ) )
RotateObjectGlobalY(1,2 )
SetObjectUVOffset(2,0,-co#,0)
SetObjectUVOffset(3,0,co#,0)
endif
if ( GetRawKeyState( 37 ) )
RotateObjectGlobalY( 1, -2 )
SetObjectUVOffset(2,0,co#,0)
SetObjectUVOffset(3,0,-co#,0)
endif
if ( GetRawKeyState( 38 ) )
MoveObjectLocalZ( 1,0.5)
SetObjectUVOffset(2,0,-co#,0)
SetObjectUVOffset(3,0,-co#,0)
endif
if ( GetRawKeyState( 40 ) )
MoveObjectLocalZ( 1,-0.5)
SetObjectUVOffset(2,0,co#,0)
SetObjectUVOffset(3,0,co#,0)
endif
`follow sensor ==================================================================================
`distance from sensor to caterpillar cabin
dx#=getobjectworldx(5002)-getobjectx(sensor)
dz#=getobjectworldz(5002)-getobjectz(sensor)
dist#=sqrt((dx#*dx#)+(dz#*dz#))
SetObjectLookAt(sensor,getobjectworldx(5002),0,getobjectworldz(5002),0)
if dist#>1
moveobjectlocalz(sensor,0.6)
inc trail,1
createobjectplane(trail,18,1)
setobjectimage(trail,101,0)
SetObjectTransparency(trail,1)
RotateObjectLocalX(trail,90)
fixobjectpivot(trail)
rotateobjectlocaly(trail,GetObjectAngleY(1))
setobjectposition(trail,getobjectx(sensor),0,getobjectz(sensor))
SetObjectColorEmissive(trail,70,50,0)
endif
`=================================================================================================
setcameraposition(1,getobjectx(1)-50,30,getobjectz(1)-90)
SetCameraLookAt(1,getobjectx(1),0,getobjectz(1),0)
Print( "FPS "+ STR(screenfps( )))
print("Trail " +str(trail-25000))
Sync()
loop
function col(ob)
cl=random(0,50)
SetObjectColor(ob,80-cl,80-cl,80-cl,0)
endfunction
texture:
`caterpillar texture
gray=makecolor(10,10,10)
drawbox(0,0,100,50,gray,gray,gray,gray,1)
for i= 1 to 100 step 4
drawline(i,0,i,50,0,0)
next
getimage (100,0,0,100,50)
`trail texture
ClearScreen()
drawbox(0,0,20,40,gray,gray,gray,gray,1)
drawbox(80,0,100,40,gray,gray,gray,gray,1)
getimage(101,0,0,100,50)
return
Cheers.
I'm not a grumpy grandpa