Basic Day/Night Cycle by MikeS6th Nov 2004 23:06
|
---|
Summary A barebones Day/Night Cycle. Description A barebones Day/Night Cycle. Almost all games have them, so it's important you get them in your games, so you can make that standard. This will teach you how to manipulate lighting and color to make an appearrance of day and night. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com sync on : sync rate 60 set display mode 1024,768,32 make object cube 1,1 `Dummy object so we can view effects of lighting and backdrop SkyChange=4 `How fast the day/night cycles. Larger values increase the cycle length. do `Initialize our loop gosub SkyCycle `Go to our gosub sync `Refresh the screen loop `Loop our loop SkyCycle: `Here's our gosub DayNight=DayNight+1 if DayNight=SkyChange `Basically, when DayNight= our Skychange variable, it's updated. if Darken>199 then Add=0 `These two lines tell us whether to darken or lighten the sky. if Darken<1 then Add=1 If Add=1 then Darken=Darken+1 `If we need more light add it. If Add=0 then Darken=Darken-1 `If we need less light, take it away set ambient light Darken `Increase or decrease the scene lighting `These next two parts are where the sky actually changes color. `The backdrop won't effect objects, but the ambient lights will. if Add=1 COLOR BACKDROP rgb(0,0,55+Darken) color ambient light rgb(55+Darken,55+Darken,55+Darken) else COLOR BACKDROP rgb(55,55,55+Darken) color ambient light rgb(55+Darken,55+Darken,55+Darken) endif DayNight=0 endif Return `Feel free to tweak this command as you like. `:) |