using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; class DayNightCycle { private bool Time = true; private int nightTime = 0; private int dayTime = 0; private int lengthOfDay = 6000; private int lengthOfNight = 6000; public void updateTime(int Speed) { for (int i = 0; i < Speed; i++) { if (Time) { dayTime++; if (dayTime == lengthOfDay) { Time = false; dayTime = 0; } } else { nightTime++; if (nightTime == lengthOfNight) { Time = true; nightTime = 0; } } } } public string getDayNight() { if (Time) { return "Day"; } else { return "Night"; } } public Color GetTimeOfDay() { int blue, red, brightness; if (nightTime == 0 && dayTime == 0) { red = 1; blue = 1; brightness = 1; } else { if ((float)dayTime / lengthOfDay < 0.5) { blue = (int)(((float)nightTime / lengthOfNight) * 255) + (int)((1.0f - (float)dayTime / lengthOfDay) * 255); } else { blue = (int)(((float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255); } if ((float)nightTime / lengthOfNight < 0.5) { red = (int)((1.0 - (float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255); } else { red = (int)(((float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255); } if (Time) { brightness = 255; } else { if ((float)nightTime / lengthOfNight < 0.5) { brightness = (int)((1.0 - (float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255); } else { brightness = (int)(((float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255); } } } return Color.FromNonPremultiplied(red, 255, blue, brightness); } public int GetTimeOfDayInt() { if (Time) { return dayTime / 60; } else { return nightTime / 60; } } }