Advanced Day/Night Simulation by Yusaku19th Jul 2005 16:17
|
---|
Summary Twenty four hours of programming in the last year to bring you all one of my best programs yet. This newly enhanced version of my day/night simulator used in my DBZ Trunks RPG feat Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com REM :: ADVANCED DAY/NIGHT SIMULATION REM :: TENSHIN SOFT :: 2004-2005 REM :: AUTHOR: KUDOU-YUSAKU sync on : sync rate 60 set display mode 1024,768,32 fog on : fog distance 8000 hide mouse : autocam off set camera range 5,10000 rem Make a sphere and set culling on to show both sides so we can see the inside of the sphere (like a sky). make object sphere 1,9000 set object 1,1,1,0 color object 1,rgb(150,180,255) rem Put some random objects around the level so you can see the change of light better for o=2 to 20 make object cube o,25 position object o,rnd(100*o),12.5,rnd(100*o) next o rem Make an Extra Light make light 1 : set directional light 1,0,0,0 color light 1,rgb(0,0,50) make light 2 : set directional light 2,0,0,0 color light 2,rgb(0,0,50) rem Make a Sun Sun=21 make object sphere Sun,200 color object Sun,rgb(225,180,1) set object Sun,1,1,1,1,0,1,0 rem Make a Moon Moon=22 make object sphere Moon,200 color object Moon,rgb(150,171,150) set object Moon,1,1,1,1,0,1,1 rem Make a matrix texture create bitmap 1,64,64 : cls rgb(0,155,0) : ink rgb(0,145,0),0 : box 4,4,12,12 get image 1,0,0,64,64 : delete bitmap 1 rem Make a matrix to move on make matrix 1,3000,3000,3,3 prepare matrix texture 1,1,64,64 rem If you are going to use a save game function, then take out this next line rem ... and use the variable you load from that instead. Otherwise, the default rem ... time starts at 2AM here, just because. oclock=0 rem Pre-Set Values day=0 srotate#=270 mrotate#=90 cx#=500 cz#=500 do rem Print Values set text font "Verdana" ink rgb(255,255,255),1 set text to bold set text size 20 set text to italic oclock$=str$(oclock) rt2$=str$(realtime#) amb$=str$(amb#) rgb$=str$(rgb#) ls$=str$(lspeed#) fps$=str$(fps#) days$=str$(day-1) hr$=str$(hr) `center text 320,25,"Framerate: "+fps$ text 25,25,oclock$+":"+rt$+" "+xm$ text 25,50,"Hours: "+hr$ text 25,75,"Days: "+days$ text 25,100,"Sr: "+str$(int(srotate#)) text 25,125,"Sx: "+str$(int(sunx#))+" | Sy: "+str$(int(suny#))+" | Sz: "+str$(int(sunz)) rem Positoin Camera position camera cx#,10,cz# rem Move the camera around with this if upkey()=1 then cx#=newxvalue(cx#,ca#,1):cz#=newzvalue(cz#,ca#,1) if downkey()=1 then cx#=newxvalue(cx#,ca#,-1):cz#=newzvalue(cz#,ca#,-1) if leftkey()=1 then ca#=wrapvalue(ca#-1) if rightkey()=1 then ca#=wrapvalue(ca#+1) rotate camera cax#,ca#,caz# cax#=wrapvalue(cax#+mousemovey()*0.3) ca#=wrapvalue(ca#+mousemovex()*0.3) if cax#=<300 and cax#=>90 then cax#=300 if cax#=>60 and cax#=<89 then cax#=60 rem Call on the time control GOSUB TIME_CONTROL rem Call on the satellite control GOSUB SAT_CONTROL sync loop rem This is the real-time Day/Night Simulator TIME_CONTROL: `Time Speed / Rationale `Change timespeed# to .03 for a reasonable time for real games. .530 is very fast and is for showing how the time works. timespeed#=0.300 realtime#=realtime#+timespeed# `Lights and Fog fog color rgb(red#,green#,blue#) ` color light 0,rgb(red#,green#,blue#) set directional light 0,1,1,1 `Red if rl=0 rl#=rl#-(timespeed#*0.30) if rl#=<0 then rl#=0 endif if rl=1 rl#=rl#+(timespeed#*0.18) if rl#=>255 then rl#=255 endif `Green if gl=0 gl#=gl#-(timespeed#*0.35) if gl#=<0 then gl#=0 endif if gl=1 gl#=gl#+(timespeed#*0.16) if gl#=>255 then gl#=255 endif `Blue if bl=0 bl#=bl#-(timespeed#*0.41) if bl#=<50 then bl#=50 endif if bl=1 bl#=bl#+(timespeed#*0.25) if bl#=>255 then bl#=255 endif `On the clock - Red if oclock=>4 and oclock=<16 then rl=1 if oclock=>17 and oclock=<23 then rl=0 if oclock=>0 and oclock=<3 then rl=0 `On the clock - Green if oclock=>5 and oclock=<17 then gl=1 if oclock=>18 and oclock=<23 then gl=0 if oclock=>0 and oclock=<4 then gl=0 `On the clock - Blue if oclock=>0 and oclock=<3 then bl=0 if oclock=>6 and oclock=<18 then bl=1 if oclock=>19 and oclock=<23 then bl=0 ` if oclock=24 then oclock=0 if oclock=>0 and oclock=<11 then xm$="AM" if oclock=>12 and oclock=<23 then xm$="PM" ` if oclock=0 and dstop=0 then day=day+1 : dstop=1 if oclock>1 then dstop=0 `Denote Time if realtime#=>0 and realtime#<10 then rt$="0"+str$(int(realtime#)) if realtime#>=10 and realtime#<60 then rt$=str$(int(realtime#)) if realtime#=>60 then oclock=oclock+1 : realtime#=0 if realtime#=0 then hr=hr+1 `Altering Variables amb#=1+rl#*1.5 red#=rl#*1.5 green#=gl#*1.0 blue#=bl#*1.5 if red#=>255 then red#=255 : if red#=<0 then red#=0 if green#=>255 then green#=255 : if green#=<0 then green#=0 if blue#=>255 then blue#=255 : if blue#=<0 then blue#=0 `Ambient Control if amb#=<20 then amb#=20 if amb#=>75 then amb#=75 set ambient light amb# RETURN rem This is where the moon and the sun rotate around the landscape SAT_CONTROL: rem Sun swide#=2500 if oclock=>0 and oclock=<22 sunx#=swide#*cos(srotate#) suny#=swide#*sin(srotate#) sunz#=swide#*sin(srotate#) position object Sun,sunx#+camera position x(),suny#+camera position y(),sunz#+camera position z() suntime#=suntime#+timespeed# srotate#=suntime#*(timespeed#/1.5) srotate#=wrapvalue(srotate#)-75 endif rem Sun's Light ` color light 1,rgb(red#,green#/2.5,0) set light to object position 1,Sun point object Sun,cx#,cy#,cz# set light to object orientation 1,Sun ` if oclock=23 sunx#=swide#*cos(srotate#) suny#=swide#*sin(srotate#) sunz#=swide#*sin(srotate#) position object Sun,sunx#+camera position x(),suny#+camera position y(),sunz#+camera position z() suntime#=0 srotate#=suntime#*(timespeed#/1.5) srotate#=wrapvalue(srotate#)-75 endif rem Moon mwide#=-2200 moonx#=mwide#*cos(mrotate#) moony#=mwide#*sin(mrotate#) moonz#=mwide#*sin(mrotate#) position object Moon,moonx#+camera position x(),moony#+camera position y(),moonz#+camera position z() moontime#=moontime#+timespeed# mrotate#=moontime#*(timespeed#/1.15) mrotate#=wrapvalue(mrotate#)+245 rem Moon's Light ` color light 2,rgb(0,green#/5,blue#) set light to object position 2,Moon point object Moon,cx#,cy#,cz# set light to object orientation 2,Moon RETURN |