I'm new to dbp and have few posts on the forums. As I like to
figure things out, read posts and try the methods that others
have, but this has me baffold. Plus I have seen a post that asked
this same question but did not get an anwser.
As my sun moves in the sky and drops below the terrain, the light
of the sun treats the terrain as if its transparent and the light
shines through it.
I need to keep the sun on constant but may allow for it's
brightness to deminsh as it sets and then increase as the sun
rises. Im not good at finding a way to code this,
( dumb thought -I like 360 as the number of degrees - insted of sin/cosin )
Also - I would like to have shadows of all items on / above terrain
show globaly insted of adding :
`set shadow shading on 3,-1,1000,1
` object, mesh, range, shader
` object=quite obvious really
` mesh=-1 means use objects mesh, but gives option of using lower res mesh
` range=how far to cast shadow - useful as shadows cast on multiple objects through solid objects. Grrrrr
` shader=0=cpu,1=gpu
On every object.
My full code:
` Project: Template
` Created: Wednesday, March 24, 2010
` Created By: Richard ****
`*************************************************** SYSTEM DATA ******************************************************
`Set Display Mode 1024,768,32
Sync on
Sync rate 30
`***************************************************** Credits ********************************************************
REMSTART
SET TEXT SIZE 30
Hide Mouse
Center Text 512,384,"Powered By Dark Game Studio"
Load Music "Music\Lostinthecosmos.mp3" ,1
Play Music 1
Wait 7500
CLS
Wait 1000
Load Animation "Animations\lazy_sun_productions.gif" ,1
Play Animation 1,192,144
Wait 5000
Stop Animation 1
Wait 5000
Delete Animation 1
CLS
Wait 1000
Center Text 512,384,"Produced By: Richard D King"
wait 7500
CLS
Wait 1000
Center Text 512,355,"Music Written & Performed by:"
Center Text 512,384,"Derek R. Audette - (C) MMIV"
Center Text 512,415,"(Creative Commons)"
Wait 7500
CLS
Wait 1000
Center Text 512,384,"A Kiyo's Production Contribution"
Wait 5000
CLS
Wait 1000
CLS
`**************************************************** Game Menu *******************************************************
Load Bitmap "Images\Menu.tga"
Get Image 1,0,0,1024,768
Paste Image 1,0,0
Do
If Keystate(1)=1 Then End `Pressing "Esc" key ends the program to desk top.
Center Text 512,355,"Return to desktop = Esc key"
If Keystate(28)=1 Then Gosub Start `Pressing the "Enter" key starts the game loop.
Center Text 512,415,"Start Game = Enter key"
Loop
Start:
Delete Image 1
REMEND
`*********************************************** Game Texture Creation ************************************************
` Load Images
Load Image "Images\grass-texture.jpg",2
Load Image "Images\sun.tga",3
Load Image "Images\Moon.tga",4
Gosub _Objects `Game Object Creation Area
Show Mouse
Wait 1000
CLS
`*********************************************** Main Program Do…Loop *************************************************
DO
`*********************************************** KeyBoard Commands ****************************************************
If Keystate(17) = 1 Then Move Object 1,.25 `W key
If Keystate(31) = 1 Then Move Object 1,-.25 `S key
If Keystate(30) = 1 Then Move Object Left 1,.25 `A key
If Keystate(32) = 1 Then Move Object Right 1,.25 `D Key
If Keystate(16) = 1 Then Move Object Down 1,.25 `Down arrow key press to move down.
If Keystate(18) = 1 Then Move Object Up 1,.25 `Up arrow key press to move up.
If Keystate(203) = 1 Then Turn Object Left 1,.01 `Left arrow key press to turn left.
If Keystate(205) = 1 Then Turn Object Right 1,.01 `Right arrow key press to turn right.
`Scroll lock press sets flag to "on" ( = 1 ) (only allow a keypress once every half a second)
If Keystate(70) and timer()>tim+500
` Check for the Forwardflag switch
if ForwardFlag = 1
` If it's 1 make it 0
ForwardFlag=0
else
` If it's 0 make it 1
ForwardFlag=1
endif
` Reset timer
tim=timer()
endif
` Check for forward movement
if ForwardFlag=1
Move Object 1,.25
else
endif
`************************************************** Position Camera ***************************************************
Position Camera Object Position x(1),Object Position y(1),Object Position z(1)
Position Object 1, Object Position x(1),Object Position y(1),Object Position z(1)
` * Mouse Camera Movment *
CamY# = CamY# + MouseMoveX()*.1
CamX# = CamX# + MouseMoveY()*.1
If CamX# > 90 And CamX# < 125 then CamX# = 90
If CamX# > 270 And CamX# < 225 then CamX# = 90
Yrotate Camera CamY#
Xrotate Camera CamX#
Yrotate Object 1,CamY#
`********************************************************* Sky Movment ************************************************
set ambient light 25
` Point the sun/moon and light at the player.
Point object 4,object position x(1),object position y(1),object position z(1)
Point object 5,object position x(1),object position y(1),object position z(1)
Point Light 0,0,0,0
`Point light 0,object position x(1),object position y(1),object position z(1)
` Put the light onto the sun/moon.
If light exist(0) then position light 0, object position x(4),object position y(4), object position z(4)
` Move the sun and moon objects.
zangle# = wrapvalue(zangle#+0.2) ` increased rotation speed so I can see it.
position object 4, 2500.0*cos(zangle#), 2500.0*sin(zangle#), 0.0
position object 5, -object position x(4), -object position y(4), 0.0
Sync
Loop
End
`*************************************************** End Of Program ***************************************************
`**************************************************** Subroutines *****************************************************
`***************************************************** Functions ******************************************************
`************************************************** Game Object Creation **********************************************
_Objects:
`set global shadows on : set global shadow shades 1 : set global shadow color 0,0,0,64
` * Sky Objects *
` Making our skybox.
Make Object Sphere 2,5200
Color Object 2,RGB(135,206,250) `Use sky blue color for texture.
Set Object Cull 2,0
` Making the sun object.
Make Object Plain 4,512,512
` Texture sun with targa w alpha channel to get the halo look.
Texture Object 4,3
` Sets the alpha channel so it will mask out the picture edges.
Set Object Transparency 4,1
` Makes the sun glow and Specifically the colour the object emits irrespective of any light or ambience.
Set Object Emissive 4, rgb(255, 255, 255)
` Making the moon object.
Make object plain 5, 256,256
Texture Object 5,4
` Sets the alpha channel so it will mask out the picture edges.
Set Object Transparency 5,1
` Specifically the colour the object emits irrespective of any light or ambience.
Set Object Emissive 5, rgb(255, 255, 0)
`----------------------------------------------------------------------------------------------------------------------
` * Terrain Objects *
` Making terrain for our world.
Make Terrain 1 , "Images\GreyLevels1.bmp"
Position Terrain 1,-256,0,256
Texture Terrain 1,2
Set Object Cull 2,0
`----------------------------------------------------------------------------------------------------------------------
` * Player Objects *
` Making the player from a box name = 1.
Make Object Box 1,10,10,10 ` Size of box 1 =50 width, 50 hight, 50 long.
Color Object 1,RGB(000,255,000) `Use green color for texture.
Position Object 1,0,100,-100 ` Spawn point in 3d space.
`Set shadow shading on 1,-1,1000,1
` object, mesh, range, shader
` object=quite obvious really
` mesh=-1 means use objects mesh, but gives option of using lower res mesh
` range=how far to cast shadow - useful as shadows cast on multiple objects through solid objects. Grrrrr
` shader=0=cpu,1=gpu
`----------------------------------------------------------------------------------------------------------------------
` * Referance object *
` Making a referance sphere name = 3 size =10.
Make Object Sphere 3,10
Color Object 3,RGB(255,000,000) `Use red color for texture.
Position Object 3,0,100,0 `Spawn point in 3d space.
`set shadow shading on 3,-1,1000,1
` object, mesh, range, shader
` object=quite obvious really
` mesh=-1 means use objects mesh, but gives option of using lower res mesh
` range=how far to cast shadow - useful as shadows cast on multiple objects through solid objects. Grrrrr
` shader=0=cpu,1=gpu
Return ` Go back to the gosub point of orgin.
Thank you