January 26, 2021, 06:38:42 AM

### Author Topic: [bb] Day To Night Function by David819 [ 1+ years ago ]  (Read 1284 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Day To Night Function by David819 [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
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
1. ;You will need to change this to the sky boxes you are using!
2. Const   Sky_Day\$ = "sky17/sky17.3ds"
3. Const   Sky_Night\$ = "sky08/sky08.3ds"
4.
5. Type Sky
6. Field SKY_AT_DAY
7. Field SKY_AT_NIGHT
8. Field Size
9. Field DAV#
10. Field NAV#
11. Field TS#
12. End Type
13.
14. Function DTN( SBD\$, SBN\$, SIZE#, DAV#, NAV# )
15.
16. D.Sky = New sky
17. DSKY_AT_DAY = SBD\$
18. DSKY_AT_NIGHT = SBN\$
19. DSIZE = SIZE#
20. DDAV# = DAV#
21. DNAV# = NAV#
22.
26.
27. ;Scale The Sky Boxes To Chosen Size
28. ScaleEntity DSKY_AT_DAY, DSIZE, DSIZE, DSIZE
29. ScaleEntity DSKY_AT_NIGHT, DSIZE, DSIZE, DSIZE
30.
31. End Function
32.
33. Function DTNU()
34. For D.Sky=Each Sky
35. ;Turns The Sky Boxes Around
36. TurnEntity DSky_At_Day, 0, 0.001, 0
37. TurnEntity DSky_At_Night, 0, 0.001, 0
38.
39. ;Set The Alpha Values
40. EntityAlpha DSky_At_Day, DDAV#
41. EntityAlpha DSky_At_Night, DNAV#
42. Next
43. End Function
44.
45. Function Basic_Con()
46. For D.Sky=Each Sky
47. If MilliSecs()- Time < 28000 Then ; 7000 means 7:00 hours
48.       Status\$="Night"
49.    ElseIf MilliSecs() - Time < 76000 Then ; 19000 means 19:00 hours
50.       Status\$="Day"
51.    Else ; the else is because it isn't day time, so it must be night time
52.       Status\$="Night"
53.    End If
54.
55. If status\$="Day" Then
56. If DDAV#<=0 Then DDAV#=DDAV#+0.0005
57. If DDAV#<1 And  DDAV#>0 Then DDAV#=DDAV#+0.0005
58. If DDAV#=>1 Then DDAV#=1
59. If DNAV#=>1 Then DNAV#=DNAV#-0.0005
60. If DNAV#>0 And DNAV#<1 Then DNAV#=DNAV#-.0005
61. If DNAV#<=0 Then DNAV#=0
62. EndIf
63.
64. If status\$="Night" Then
65. If DDAV#=>1 Then DDAV#=DDAV#-0.0005
66. If DDAV#>0 And DDAV#<1 Then DDAV#=DDAV#-.0005
67. If DDAV#<=0 Then DDAV#=0
68. If DNAV#<=0 Then DNAV#=DNAV#+0.0005
69. If DNAV#<1 And  DNAV#>0 Then DNAV#=DNAV#+0.0005
70. If DNAV#=>1 Then DNAV#=1
71. EndIf
72.
73.    If MilliSecs() - Time > 96000 Then ; check to see if 24 hours has past, and if so, start a new day.
74.       Time = Time + 96000 ; wrap the day back round to midnight again
75.    End If
76.
77.
78. Next
79. End Function
80.
81. ;Example You may need to change the screen's width and height
82. Include "DTN FUNCTION Final test.bb"
83.
84. ;Example Of Use
85. Global Time = MilliSecs()
86. Global Status\$
87.
88. ;Costants
89. Const   Width           =               1280
90. Const   Height          =               1024
91. Const   Depth           =               32
92. Const   SType           =               1
93. Const   EndKey          =               1
94.
95. ;Set Graphics mode
96. Graphics3D      Width, Height, Depth, SType
97. SetBuffer       BackBuffer()
98.
99. ;Create Camera
100. CHAR_Cam        =       CreateCamera()
101. CameraRange     CHAR_Cam, 1, 2000
102. PositionEntity  CHAR_Cam, 0, 1, 0
103.
104. ;Day And Night Values
105. D#=0
106. N#=1
107.
108. ;Main Part
109. DTN( Sky_Day\$, Sky_Night\$, 100, D#, N# )
110.
111. ;Main Loop
112. While Not KeyHit (EndKey)
113. Basic_Con()
114. DTNU()
115. UpdateWorld
116. RenderWorld
117.    Text 0,0, " Day or Night:"+status\$
118.    Text 0,10," Hour:"+((MilliSecs()-Time)/1000/4)
119. Flip False
120. Wend
121. End

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.