[bb] Day To Night Function by David819 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : Day To Night Function
Author : David819
Posted : 1+ years ago

Description : This code changes 2 sky boxes around one being day and the other being night and allows them to switch using alpha on them.

Code :
Code (blitzbasic) Select
;You will need to change this to the sky boxes you are using!
Const Sky_Day$ = "sky17/sky17.3ds"
Const Sky_Night$ = "sky08/sky08.3ds"

Type Sky
Field SKY_AT_DAY
Field SKY_AT_NIGHT
Field Size
Field DAV#
Field NAV#
Field TS#
End Type

Function DTN( SBD$, SBN$, SIZE#, DAV#, NAV# )

D.Sky = New sky
DSKY_AT_DAY = SBD$
DSKY_AT_NIGHT = SBN$
DSIZE = SIZE#
DDAV# = DAV#
DNAV# = NAV#

;Loads The Sky Boxes
DSKY_AT_DAY = LoadMesh(SBD$)
DSKY_AT_NIGHT = LoadMesh(SBN$)

;Scale The Sky Boxes To Chosen Size
ScaleEntity DSKY_AT_DAY, DSIZE, DSIZE, DSIZE
ScaleEntity DSKY_AT_NIGHT, DSIZE, DSIZE, DSIZE

End Function

Function DTNU()
For D.Sky=Each Sky
;Turns The Sky Boxes Around
TurnEntity DSky_At_Day, 0, 0.001, 0
TurnEntity DSky_At_Night, 0, 0.001, 0

;Set The Alpha Values
EntityAlpha DSky_At_Day, DDAV#
EntityAlpha DSky_At_Night, DNAV#
Next
End Function

Function Basic_Con()
For D.Sky=Each Sky
If MilliSecs()- Time < 28000 Then ; 7000 means 7:00 hours
      Status$="Night"
   ElseIf MilliSecs() - Time < 76000 Then ; 19000 means 19:00 hours
      Status$="Day"
   Else ; the else is because it isn't day time, so it must be night time
      Status$="Night"
   End If

If status$="Day" Then
If DDAV#<=0 Then DDAV#=DDAV#+0.0005
If DDAV#<1 And  DDAV#>0 Then DDAV#=DDAV#+0.0005
If DDAV#=>1 Then DDAV#=1
If DNAV#=>1 Then DNAV#=DNAV#-0.0005
If DNAV#>0 And DNAV#<1 Then DNAV#=DNAV#-.0005
If DNAV#<=0 Then DNAV#=0
EndIf

If status$="Night" Then
If DDAV#=>1 Then DDAV#=DDAV#-0.0005
If DDAV#>0 And DDAV#<1 Then DDAV#=DDAV#-.0005
If DDAV#<=0 Then DDAV#=0
If DNAV#<=0 Then DNAV#=DNAV#+0.0005
If DNAV#<1 And  DNAV#>0 Then DNAV#=DNAV#+0.0005
If DNAV#=>1 Then DNAV#=1
EndIf

   If MilliSecs() - Time > 96000 Then ; check to see if 24 hours has past, and if so, start a new day.
      Time = Time + 96000 ; wrap the day back round to midnight again
   End If


Next
End Function

;Example You may need to change the screen's width and height
Include "DTN FUNCTION Final test.bb"

;Example Of Use
Global Time = MilliSecs()
Global Status$

;Costants
Const Width = 1280
Const Height = 1024
Const Depth = 32
Const SType = 1
Const EndKey = 1

;Set Graphics mode
Graphics3D Width, Height, Depth, SType
SetBuffer BackBuffer()

;Create Camera
CHAR_Cam = CreateCamera()
CameraRange CHAR_Cam, 1, 2000
PositionEntity CHAR_Cam, 0, 1, 0

;Day And Night Values
D#=0
N#=1

;Main Part
DTN( Sky_Day$, Sky_Night$, 100, D#, N# )

;Main Loop
While Not KeyHit (EndKey)
Basic_Con()
DTNU()
UpdateWorld
RenderWorld
   Text 0,0, " Day or Night:"+status$
   Text 0,10," Hour:"+((MilliSecs()-Time)/1000/4)
Flip False
Wend
End


Comments :


David819(Posted 1+ years ago)

 oh, just in case you dont wish to wait long just goto the Basic_Con() function and change :DDAV#+0.0005andDNAV#-0.0005DDAV#-0.0005andDNAV#+0.0005to DDAV#+0.05andDNAV#-0.05DDAV#-0.05andDNAV#+0.05enjoy!


puki(Posted 1+ years ago)

 And use pretextured skyboxes or else you end up watching a grey and black screen.