Rem Project: Star Wars Trench Run
Rem Created: 11/2/2005 11:14:01 PM
Rem Created by: RiiDii
 
Rem ***** Main Source File *****
 
 
Sync On: Sync Rate 60:Autocam Off
Set Camera Range .01,100
Color Backdrop 0,rgb(0,0,0)
`Fog On
`Fog Distance 5,50
`Fog Color 0
 
Dim m(64,64) as Float
 
`Lock Pixels
Ink 0,0
Box 0,0,64,64
`Unlock Pixels
Get Image 1,0,0,64,64,1
If File Exist("base 64x64.bmp") Then Delete File "base 64x64.bmp"
Save Image "base 64x64.bmp",1
`Lock Pixels
Ink Rgb(20,20,20),0
Box 0,0,256,256
For i = 1 to 60
   Ink Rgb(230-i*3,230-i*3,220-i*3),0
   Line 0,128-i,256,128-i
   Line 0,127+i,256,127+i
Next i
`Unlock Pixels
Get Image 1,0,0,256,256,1
`Lock Pixels
Ink Rgb(128,128,128),0
Box 0,0,256,256
For i = 1 to 10+rnd(10)
   Ink Rgb(10,10,10),0
   x=rnd(256):y=rnd(256)
   Line 0,y,256,y
   Line x,0,x,256
   s=rnd(20)+30
   c=rnd(50)+150
   ink rgb(c,c,c),0
   x=rnd(256):y=rnd(256)
   Box x,y,x+s,y+s
Next i
`Unlock Pixels
Get Image 2,0,0,256,256
 
Global Limbs as DWord
Dim Trench(5000) as Byte
boxobj=100
Make Object Box boxobj,15,1,1
Texture Object boxobj,2
Scale Object Texture boxobj,15,1
Set Object Fog boxobj,1
t=32
For i = 0 to Array Count(Trench())
   Trench(i)=t
   moveit=rnd(19)
   t=t-(moveit=0)+(moveit=19)
   if t<7 then t=7
   if t>57 then t=57
   if rnd(20)=4 and flag=0
      Position Object boxobj,t-32,rnd(30.0)/10.0+124,i-1
      inc boxobj
      Instance Object boxobj,100
      flag=1
   Else
      flag=0
   endif
Next i
 
 
Make Object Terrain 1
Set Terrain Heightmap 1,"base 64x64.bmp"
Set Terrain Texture 1,1,2
Set Terrain Tiling 1,1
Set Terrain Scale 1,1,1,1
Set Terrain Split 1,1
Build Terrain 1
 
 
 
Perform Checklist for Object Limbs 1
Limbs=Checklist Quantity()
Set Object Cull 1,0
 
 
Position Camera Trench(65)-32.0,200,65
 
lx=0
lz=0
os=1
elevation#=.5
delay=100
Do
   Move Camera .2
   Move Camera (Mouseclick()=1)*.2
   Turn Camera Right mousemovex()*.1
   elevation#=elevation#-mousemovey()*.02
   if elevation#<.2 then elevation#=.2
   if elevation#>3.0 then elevation#=3.0
   Limit_Camera()
   x=int(camera Position X()):z=Int(Camera Position Z())
   if lx<>x or lz<>z
      Morph_Terrain(1,x,z,64)
      Update Terrain
      Position Object 1,x,0,Int(z)
   Endif
   x#=x
   `Scroll Object Texture 1,x#/10.0,0
   lx=x:lz=z
   y#=Get_Ground_Height(1,Camera Position X(),Camera Position Z())
   Position Camera Camera Position X(),y#+elevation#,Camera Position Z()
   Set Cursor 0,0
   Print Screen FPS()
   Print Camera Position X()
   Print Camera Position Y()
   Print Camera Position Z()
   Sync
Loop
 
Function Limit_Camera()
   cx#=Camera Position X(0):cy#=Camera Position Y(0):cz#=Camera Position Z(0)
   If cz#<65
      Position Camera cx#,cy#,65
   Endif
   If cz#>4999-64
      Position Camera cx#,cy#,4999-64
   Endif
   cz#=Camera Position Z(0)
   z=cz#
   if cx#>100 or cy#<10.0 then cx#=0.0
   Position Camera cx#,cy#,cz#
   If cx#<-31
      Position Camera -31,cy#,cz#
   Endif
   If cx#>31
      Position Camera 31,cy#,cz#
   Endif
Endfunction
 
 
Function Get_Ground_Height(TerrainID,x#,z#)
   d#=Intersect Object(TerrainID,x#,500.0,z#,x#,0.0,z#)
   if d#>0 Then d#=500.0-d#
Endfunction d#
 
 
 
Function Morph_Terrain(TerrainID,PosX,PosZ,size)
   For y=0 to Size
      For x=0 to Size
         m(x,y)=128
         if x=Trench(PosZ+y)
            for i =-4 to 4
               m(x+i,y)=124
            next i
         Endif
      Next x
   Next y
 
   For l = 0 to Limbs-1
      Lock VertexData for Limb TerrainID,l
      VIC=Get Vertexdata Index Count()
      For i = 0 to VIC
            tx=Get VertexData Position X(Get IndexData(i))
            tz=Get VertexData Position Z(Get IndexData(i))
            SET VERTEXDATA POSITION Get IndexData(i), tx, m(tx,tz), tz
      Next i
      Unlock VertexData
   offset limb TerrainID,l,-Size/2-PosX,0,-Size/2,1
   Next l
   Set Current Bitmap 0
   Set Cursor 50,0
Endfunction tempobj