Here's my code for a day/night cycle. I have it set up so that when time (Statistics.duration) is the right number, the light levels switch. It works great, but I'm at a loss for how to make it work indefinitely - as an actual cycle. How can I make this code work for all numbers up to 10,000? I know there has to be an easy way to do this, but I'm at a loss...
public void updateTime()
{
if (!dawn && (Statistics.duration <= 50 ) && Dungeon.depth <= 100){
dawn = true;
night = false;
Dungeon.nightMode = false;
GLog.i("It is now dawn.");
}
if (!noon && Statistics.duration > 50 && Statistics.duration <= 100 && Dungeon.depth <= 100){
noon = true;
dawn = false;
GLog.i("It is now noon.");
}
if (!dusk && Statistics.duration > 100 && Statistics.duration <= 150 && Dungeon.depth <= 100){
dusk = true;
noon = false;
GLog.i("It is now dusk.");
}
if (!night && Statistics.duration > 150 && Statistics.duration <= 200 && Dungeon.depth <= 100){
night = true;
dusk = false;
GLog.i("It is now night.");
}
if (!dawn && Statistics.duration > 200 && Statistics.duration <= 250 && Dungeon.depth <= 100){
dawn = true;
night = false;
GLog.i("It is now dawn.");
}
}
I'm calling updateTime() whenever the player does something - moving, fighting, sleeping, etc. They perform the action, which gets added to the .duration.
updateTime()
from within your central game loop? \$\endgroup\$