2020-05-06 16:22:30 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
|
|
|
|
|
class DayNightCycle
|
|
|
|
|
{
|
2020-05-24 21:00:24 +02:00
|
|
|
|
private bool Time = false;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
private int nightTime = 0;
|
|
|
|
|
private int dayTime = 0;
|
2020-05-06 20:48:20 +02:00
|
|
|
|
private int lengthOfDay = 20000;
|
|
|
|
|
private int lengthOfNight = 20000;
|
2020-05-24 21:00:24 +02:00
|
|
|
|
private int Days = 1;
|
|
|
|
|
private int DaysOfYear = 0;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
|
|
|
|
|
public void updateTime(int Speed)
|
|
|
|
|
{
|
2020-05-24 21:00:24 +02:00
|
|
|
|
Time = false;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
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;
|
2020-05-06 20:48:20 +02:00
|
|
|
|
Days++;
|
2020-05-24 21:00:24 +02:00
|
|
|
|
DaysOfYear++;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-24 21:22:17 +02:00
|
|
|
|
if (DaysOfYear == 48)
|
2020-05-24 21:00:24 +02:00
|
|
|
|
{
|
|
|
|
|
DaysOfYear = 0;
|
|
|
|
|
}
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
2020-05-24 21:00:24 +02:00
|
|
|
|
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 21:00:24 +02:00
|
|
|
|
//Season:
|
|
|
|
|
//0 - Whole Year
|
|
|
|
|
//1 - Spring
|
|
|
|
|
//2 - Summer
|
|
|
|
|
//3 - Autumn
|
|
|
|
|
//4 - Winter
|
|
|
|
|
|
2020-05-24 21:22:17 +02:00
|
|
|
|
public string getTimeOfYear()
|
2020-05-06 16:22:30 +02:00
|
|
|
|
{
|
2020-05-24 21:22:17 +02:00
|
|
|
|
if (DaysOfYear < 12)
|
|
|
|
|
return "Spring";
|
|
|
|
|
else if (DaysOfYear < 24)
|
|
|
|
|
return "Summer";
|
|
|
|
|
else if (DaysOfYear < 36)
|
|
|
|
|
return "Autumn";
|
2020-05-06 16:22:30 +02:00
|
|
|
|
else
|
2020-05-24 21:22:17 +02:00
|
|
|
|
return "Winter";
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color GetTimeOfDay()
|
|
|
|
|
{
|
2020-05-23 20:37:11 +02:00
|
|
|
|
int blue, red, brightness, green, potatorate = 255;
|
2020-05-06 20:48:20 +02:00
|
|
|
|
if (nightTime == 0 && dayTime == 0)
|
2020-05-06 16:22:30 +02:00
|
|
|
|
{
|
2020-05-06 20:48:20 +02:00
|
|
|
|
red = 1;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
blue = 1;
|
2020-05-23 20:37:11 +02:00
|
|
|
|
green = 1;
|
2020-05-06 20:48:20 +02:00
|
|
|
|
brightness = 1;
|
|
|
|
|
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-06 20:48:20 +02:00
|
|
|
|
if ((float)dayTime / lengthOfDay < 0.5)
|
|
|
|
|
{
|
2020-05-23 20:37:11 +02:00
|
|
|
|
blue = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)((1.0f - (float)dayTime / lengthOfDay) * potatorate);
|
2020-05-06 20:48:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-23 20:37:11 +02:00
|
|
|
|
blue = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
2020-05-06 20:48:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((float)nightTime / lengthOfNight < 0.5)
|
|
|
|
|
{
|
2020-05-23 20:37:11 +02:00
|
|
|
|
red = (int)((1.0 - (float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
2020-05-06 20:48:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-23 20:37:11 +02:00
|
|
|
|
red = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((float)nightTime / lengthOfNight < 0.5)
|
|
|
|
|
{
|
|
|
|
|
green = (int)((1.0 - (float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
green = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
2020-05-06 20:48:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
2020-05-23 20:37:11 +02:00
|
|
|
|
return Color.FromNonPremultiplied(red, green, blue, 255);
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 21:00:24 +02:00
|
|
|
|
public bool nDay()
|
|
|
|
|
{
|
|
|
|
|
if (Time)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 16:22:30 +02:00
|
|
|
|
public int GetTimeOfDayInt()
|
|
|
|
|
{
|
|
|
|
|
if (Time)
|
|
|
|
|
{
|
2020-05-06 20:48:20 +02:00
|
|
|
|
return (int)(100 * ((float)(dayTime + nightTime) / (lengthOfDay + lengthOfNight))) + 1;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-06 20:48:20 +02:00
|
|
|
|
return (int)(100 * ((float)(lengthOfDay + nightTime) / (lengthOfDay + lengthOfNight))) + 1;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
2020-05-06 20:48:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getDays()
|
|
|
|
|
{
|
|
|
|
|
return Days;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|