If you want to add moon also, put the attached image into your project folder again and change the code into following:
Its all ambient based, so any object you put in your level will be effected by the light.
Rem Project: forumDayNightCycle
Rem Created: 26.06.2006 17:03:19
Rem ***** Main Source File *****
Set Display Mode 640, 480, 16
AutoCam Off
Set Camera Range 1,200000
Color BackDrop Rgb(100,100,100)
Fog On
Fog Color Rgb(100,100,100)
Fog Distance 45000
Sync On
Print "Making Terrain....."
Sync
Sync
terrain = terrainCreate("ter3", 50.0, 0.0, 0.0, 0.0)
Print "Making Sun....."
Sync
Sync
imgSun = freeImage()
Load Image "sun.bmp", imgSun, 1
dummySun = freeObject()
Make Object Plain dummySun, 512, 512
Scale Object dummySun, 1000, 1000, 1000
Position Object dummySun, 50, 50, 0
Set Object Light dummySun, 0
Set Object Fog dummySun, 0
Texture Object dummySun, imgSun
Ghost Object On dummySun, 0
Disable Object zWrite dummySun
m_sunFlares()
imgMoon = freeImage()
Load Image "Moon.bmp", imgMoon, 1
dummyMoon = freeObject()
Make Object Plain dummyMoon, 512, 512
Scale Object dummyMoon, 1000, 1000, 1000
Position Object dummyMoon, 50, 50, 0
Set Object Light dummyMoon, 0
Set Object Fog dummyMoon, 0
Texture Object dummyMoon, imgMoon
Ghost Object On dummyMoon, 0
Disable Object zWrite dummyMoon
Position Camera 0, 3470, 0
Do
Update Terrain terrain
a# = wrapvalue(a# + 0.07058823529)
sunX# = Sin(a#)*Object Size X(terrain)/1.5
sunY# = -Cos(a#)*Object Size X(terrain)/1.5
Position Object dummySun, sunX#, sunY#, 0.0
Point Object dummySun, camera position x(), camera position y(), camera position z()
r_sunFlares(dummySun)
Position Object dummyMoon, -sunX#, -sunY#, 0.0
Point Object dummyMoon, camera position x(), camera position y(), camera position z()
ax# = WrapValue(ax# + mouseMoveY())
ay# = WrapValue(ay# + mouseMoveX())
Rotate Camera ax#, ay#, 0.0
If MouseClick()=1 Then Move Camera 500
If MouseClick()=2 Then Move Camera -500
Scroll Object Texture 2, 0, 0.0005
Scroll Object Texture 3, 0, 0.0001
blue# = blue# + bInc#
if blue# =>255 Then bInc# = -0.1
if blue# =<0 Then bInc# = 0.1
Color BackDrop Rgb(0,0,blue#)
Color Ambient Light Rgb(blue#,blue#,blue#)
Set Ambient Light 100
Set Object Light terrain, 1
Fog Color Rgb(blue#/2,blue#/2,blue#/2)
Sync
Loop
Type ordinaryObject
tImg As Integer
vObj As Integer
EndType
Function m_sunFlares()
DIM sunFlares(3) As ordinaryObject
For i = 1 To 3
sunFlares(i).tImg = freeImage()
Load Image "Flare"+Str$(i)+".bmp", sunFlares(i).tImg
sunFlares(i).vObj = freeObject()
Make Object Plain sunFlares(i).vObj, 30+(i*5), 30+(i*5)
Lock Object On sunFlares(i).vObj
Texture Object sunFlares(i).vObj, sunFlares(i).tImg
Set Object Fog sunFlares(i).tImg, 0
Set Object Light sunFlares(i).tImg, 0
Ghost Object On sunFlares(i).tImg, 0
Disable Object zWrite sunFlares(i).tImg
Fix Object Pivot sunFlares(i).tImg
Next i
EndFunction
Function r_sunFlares(sunObject As Integer)
if object in screen(sunObject)=1
lensx#=(Object Screen X(sunObject)-(Screen Width()/2.0))*-0.15625
lensy#=(Object Screen Y(sunObject)-(Screen Height()/2.0))*0.15625
position object sunFlares(1).vObj, lensx#*-0.5, lensy#*-0.5, 100
position object sunFlares(2).vObj, lensx#*0.2, lensy#*0.2, 100.001
position object sunFlares(3).vObj, lensx#*0.9, lensy#*0.9, 100.002
For i = 1 To 3
Show Object sunFlares(i).vObj
Next i
Else
For i = 1 To 3
Hide Object sunFlares(i).vObj
Next i
EndIf
EndFunction
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function terrainCreate(folder As String, s As Float, x As Float, y As Float, z As Float)
imgC = freeImage() : Load Image folder + "/color.jpg", imgC
imgD = freeImage() : Load Image folder + "/detail.tga", imgD
oTer = freeObject()
Make Object Terrain oTer
Set Terrain Heightmap oTer, folder + "/height.bmp"
Set Terrain Scale oTer, 5.0*s, 1.0*s, 5.0*s
Set Terrain Split oTer, 16
Set Terrain Tiling oTer, 2
`Set Terrain Light oTer, x#, y#, z#, 1, 1, 0.78, 0.5
Set Terrain Texture oTer, imgC, imgD
Build Terrain oTer
Position Object oTer, x-Object Size X(oTer)/2.0, y, z-Object Size Z(oTer)/2.0
imgCloud = freeImage()
objCloud = freeObject()
Load Image "clouds.png", imgCloud, 1
For a = objCloud To objCloud+1
Make Object Plain a, 500000, 500000
xRotate Object a, 90
Position Object a, 5000, a*1500+object size y(oTer), 5000
Texture Object a, imgCloud
Ghost Object On a, 0
Scale Object Texture a, 5, 5
`Set Object Light a, 0
Set Object Fog a, 0
Next a
EndFunction oTer
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
lbl_functionsFree:
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeDll()
Repeat
Inc i
Until DLL Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeMemblock()
Repeat
Inc i
Until MemBlock Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeObject()
Repeat
Inc i
Until Object Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeSound()
Repeat
Inc i
Until Sound Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeMusic()
Repeat
Inc i
Until Music Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeAnimation()
Repeat
Inc i
Until Animation Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeBitmap()
Repeat
Inc i
Until Bitmap Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeEffect()
Repeat
Inc i
Until Effect Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeImage()
Repeat
Inc i
Until Image Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeLight()
Repeat
Inc i
Until Light Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeLimb()
Repeat
Inc i
Until Limb Exist(i,i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeMatrix()
Repeat
Inc i
Until Matrix Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeMesh()
Repeat
Inc i
Until Mesh Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freePixelshader()
Repeat
Inc i
Until Pixel Shader Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeParticles()
`Repeat
Inc i
`Until Particles Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeSprite()
Repeat
Inc i
Until Sprite Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeTerrain()
Repeat
Inc i
Until Terrain Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeVertexshader()
Repeat
Inc i
Until Vertex Shader Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeFile()
Repeat
Inc i
Until File Open(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<