TGC Codebase Backup



Snow Racer: Scrolling Matrix Demo by RiiDii

19th May 2005 2:31
Summary

Demo smooth scrolling matrix, heightmap, snow (syncing with scrolling), and reflections.



Description

Started out playing with a heightmap and increased complexity until I got this.
Demos:
Infinate scrolling terrain (w/thanks to Spooky for helping work around a DBPro bug)
Heightmap and skysphere.
Reflective Ice.
Adjustable speed.
Pan around camera which pulls away to show scrolling matrix and other tricks.
Snow. Falling, but also in sync with scrolling terrain.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    
Global ht as Dword
Global wt as Dword
dvd=100
Dim h(dvd,dvd) as Integer

Sync On: Sync Rate 60: Autocam Off
Set Camera Range 50,15000

Load Image "background3.jpg",1,1
Load Image "Cloud3.jpg",2,1
Make Memblock From Image 1,1
wt=Memblock Dword(1,0)
ht=Memblock Dword(1,4)

Create Bitmap 1,wt,ht
Set Current Bitmap 1
Paste Image 1,0,0
For i# = 0.0 to dvd-1.0
   For j# = 0.0 to dvd-1.0
      x=(j#-0.0)/dvd*wt
      y=(i#-0.0)/dvd*ht
      i=i#:j=j#
      h(j,i)=(Rgbr(Point(x,y))+Rgbg(Point(x,y))+rgbb(Point(x,y)))/3
   Next j#
Next i#
Set Current Bitmap 0


Make Matrix 1,10000,10000,dvd,dvd
Set Matrix Texture 1,1,0
Prepare Matrix Texture 1,1,dvd,dvd
t=1
For i=0 to dvd-1
   For j = 0 to dvd-1
      Set Matrix Tile 1,j,(dvd-1)-i,t
      Set Matrix Height 1,j,(dvd-1)-i,h(j,i)
      t=t+1
   Next j
Next i

Update Matrix 1
Sprite 1,1,1,1
Scale Sprite 1,20
Hide Sprite 1
Make Object Sphere 2,1,1,1
Hide Object 2
Make Object Box 3,20,20,40
Make Object Box 4,20,20,40
Set Alpha Mapping On 4,50
Disable Object ZDepth 4
Make Object Sphere 5,-15000,100,100
Texture Object 5,2
Set Object Emissive 5,rgb(150,150,200)
Turn Object Left 5,75
Make Object Plain 6,5000,5000
Texture Object 6,2
Set Alpha Mapping On 6,10
Pitch Object Up 6,90
Roll Object Right 6,45


For i = 1001 to 2000
   Make Object Sphere i,10,4,4
   Set Object Emissive i,Rgb(150,150,150)
   Set Alpha Mapping On i,75
   Position Object i,rnd(10000),rnd(1000),rnd(10000)
Next i


f#=1
fs#=20
counter=0
height=50
Do
   Set Cursor 200,0:Print "Up/Down arrows to change speed: ";dvd-Int(fs#)
   Set Cursor 200,20:Print "Press [S] to show heightmap texture."
   If Lower$(Inkey$())="s" Then Show Sprite 1 Else Hide Sprite 1
   fs#=fs#+downkey()*(fs#<(dvd-10))-upkey()*(fs#>2)
   fm#=10000.0/dvd/fs#
   f#=f#+1
   counter=counter+1
   If counter>5000
      if counter<7000
         height=height+2
      Else
         height=height-2
         if counter=9000 then counter=0
      Endif
   Endif
   If f#>fs#
      Shift Matrix Right 1
      for f=0 to dvd : set matrix height 1,0,f,get matrix height(1,dvd,f) : next f
      Snow_Shift(fs#*fm#)
      f#=1
   Endif
   Update Matrix 1
   Position Object 2,5000.0-f#*fm#,300,5000
   Position Object 5,5000.0-f#*fm#,1000,5000
   Turn Object Right 2,.05
   Move Object 2,4000
   Position Object 3,Object Position X(2),Get Ground Height(1,Object Position X(2),Object Position Z(2))+10,Object Position Z(2)
   Point Object 3,Object Position X(3)-2,Get Ground Height(1,Object Position X(3)-2,Object Position Z(3))+10,Object Position Z(3)
   Position Object 6,Object POsition X(3),110,Object Position Z(3)
   If Object Position Y(3)>120
      Enable Object ZDepth 3
      Hide Object 4
   Else
      Position Object 4,Object Position X(3),Object Position Y(3),Object POsition Z(3)
      Set Object To Object Orientation 4,3
      Move Object Down 4,15.0+rnd(50.0)/10.0
      Disable Object ZDepth 3
      Show Object 4
   Endif
   Move Object 2,400
   Snow()
   Position Camera Object Position X(2),Object Position Y(2)+height,Object Position Z(2)
   Point Camera Object Position X(3),150,Object Position Z(3)
   Sync
Loop

Function Snow()
   For i = 1001 to 2000
      Move Object Down i,1
      If Object Position Y(i)<0 Then Move OBject Up i,1000
   Next i
EndFunction

Function Snow_Shift(of#)
   For i = 1001 to 2000
      Move Object Right i,of#
      If Object Position X(i)>10000 Then Move Object Left i,10000
   Next i
EndFunction