/// <summary> /// Gets the modified ambient light <see cref="Color"/> for the specified <see cref="GameDateTime"/>. /// </summary> /// <param name="ambient">The ambient light color.</param> /// <param name="time">The game time to get the ambient light for.</param> /// <returns>The modified ambient light for the specified <paramref name="time"/>.</returns> public Color GetModifiedAmbientLight(Color ambient, GameDateTime time) { var multiplier = CalculateNightMultiplier(time); var modAmbient = ApplyNightMultiplier(multiplier, ambient); return(modAmbient); }
public void LessThanOperatorTest() { var less = new GameDateTime(100); var more = new GameDateTime(200); Assert.IsTrue(less < more); Assert.IsFalse(more < less); }
public void GreaterThanOperatorTest() { var less = new GameDateTime(100); var more = new GameDateTime(200); Assert.IsFalse(less > more); Assert.IsTrue(more > less); }
public void AddOperatorTest() { var a = new GameDateTime(50); var b = new GameDateTime(25); Assert.AreEqual(new GameDateTime(75), a + b); Assert.AreEqual(new GameDateTime(75), b + a); }
public void GreaterThanOrEqualToOperatorTest() { var less = new GameDateTime(100); var more = new GameDateTime(200); var less2 = new GameDateTime(100); Assert.IsFalse(less >= more); Assert.IsTrue(more >= less); Assert.IsTrue(less >= less2); Assert.IsTrue(less2 >= less); }
public void EqualsOperatorTest() { var a = new GameDateTime(512); var b = new GameDateTime(512); var c = new GameDateTime(312); Assert.IsTrue(a == b); Assert.IsTrue(b == a); Assert.IsFalse(a == c); Assert.IsFalse(b == c); }
public void EqualsTest() { var a = new GameDateTime(512); var b = new GameDateTime(512); var c = new GameDateTime(312); Assert.AreEqual(a, b); Assert.AreEqual(b, a); Assert.AreNotEqual(a, c); Assert.AreNotEqual(b, c); Assert.IsTrue(a.Equals(b)); Assert.IsTrue(b.Equals(a)); Assert.IsFalse(a.Equals(c)); Assert.IsFalse(b.Equals(c)); }
/// <summary> /// Gets the multiplier value to apply to the ambient light to calculate the new ambient lighting value for /// simulating night-time. /// </summary> /// <param name="time">The current game time.</param> /// <returns>The ambient light multiplier.</returns> protected virtual float CalculateNightMultiplier(GameDateTime time) { // Check if we are even in night-time if (time.Hour <= NightStartHour && time.Hour >= NightEndHour) { return(1); } // Get the light modifier based on the world time. We do this by finding the "percent" of darkness, // and multiplying the RGB values of the light by that. // How long darkness lasts in minutes (time between nightStartHour and nightEndHour) var minutesOfDarkness = (int)((GameDateTime.HoursPerDay - NightStartHour) + NightEndHour); minutesOfDarkness *= (int)GameDateTime.MinutesPerHour; var halfMinutesOfDarkness = minutesOfDarkness / 2f; // How far into the darkness we are with the current time (will be between 0 and hoursOfDarkness) int minutesIntoDarkness; if (time.Hour > NightStartHour) { minutesIntoDarkness = time.Hour - NightStartHour; } else { minutesIntoDarkness = (int)(GameDateTime.HoursPerDay - NightStartHour) + time.Hour; } minutesIntoDarkness *= (int)GameDateTime.MinutesPerHour; minutesIntoDarkness += time.Minute; // Since hoursOfDarkness/2 is the darkest point, get the difference of how many hours we are into // darkness and half the total hours of darkness as a percent. This will give us a scale from // [-1, 1] where -1 is the start of night, 0 is the darkest point of night, and 1 is the end of night. var nightMultiplier = (halfMinutesOfDarkness - minutesIntoDarkness) / halfMinutesOfDarkness; // Get the absolute value of the night multiplier so that it instead of -1 to 1, it goes from 1 to 0 to 1 nightMultiplier = Math.Abs(nightMultiplier); // Finally, add the product of the night multiplier to the minMultiplier to "amplify" the darkness nightMultiplier += (1 - nightMultiplier) * MinAmbientMultiplier; return(nightMultiplier); }
/// <summary> /// Determines if this <see cref="GameDateTime"/> is equal to another <see cref="GameDateTime"/>. /// </summary> /// <param name="other">The other <see cref="GameDateTime"/>.</param> /// <returns>True if this <see cref="GameDateTime"/> is equal to the <paramref name="other"/>; otherwise false.</returns> public bool Equals(GameDateTime other) { return(other._day == _day && other._hour == _hour && other._minute == _minute && other._month == _month && other._year == _year); }
/// <summary> /// Determines if this <see cref="GameDateTime"/> is equal to another <see cref="GameDateTime"/>. /// </summary> /// <param name="other">The other <see cref="GameDateTime"/>.</param> /// <returns>True if this <see cref="GameDateTime"/> is equal to the <paramref name="other"/>; otherwise false.</returns> public bool Equals(GameDateTime other) { return other._day == _day && other._hour == _hour && other._minute == _minute && other._month == _month && other._year == _year; }
public void ToFromMinutesTest() { const int minutes = 123123; var gt = new GameDateTime(minutes); Assert.AreEqual(minutes, (int)gt.TotalRealMinutes); Assert.AreEqual(gt, new GameDateTime((int)gt.TotalRealMinutes)); }
public void SubtractOperatorTest() { var a = new GameDateTime(50); var b = new GameDateTime(25); Assert.AreEqual(new GameDateTime(25), a - b); }
/// <summary> /// Gets the modified ambient light <see cref="Color"/> for the specified <see cref="GameDateTime"/>. /// </summary> /// <param name="ambient">The ambient light color.</param> /// <param name="time">The game time to get the ambient light for.</param> /// <returns>The modified ambient light for the specified <paramref name="time"/>.</returns> public Color GetModifiedAmbientLight(Color ambient, GameDateTime time) { var multiplier = CalculateNightMultiplier(time); var modAmbient = ApplyNightMultiplier(multiplier, ambient); return modAmbient; }
/// <summary> /// Gets the multiplier value to apply to the ambient light to calculate the new ambient lighting value for /// simulating night-time. /// </summary> /// <param name="time">The current game time.</param> /// <returns>The ambient light multiplier.</returns> protected virtual float CalculateNightMultiplier(GameDateTime time) { // Check if we are even in night-time if (time.Hour <= NightStartHour && time.Hour >= NightEndHour) return 1; // Get the light modifier based on the world time. We do this by finding the "percent" of darkness, // and multiplying the RGB values of the light by that. // How long darkness lasts in minutes (time between nightStartHour and nightEndHour) var minutesOfDarkness = (int)((GameDateTime.HoursPerDay - NightStartHour) + NightEndHour); minutesOfDarkness *= (int)GameDateTime.MinutesPerHour; var halfMinutesOfDarkness = minutesOfDarkness / 2f; // How far into the darkness we are with the current time (will be between 0 and hoursOfDarkness) int minutesIntoDarkness; if (time.Hour > NightStartHour) minutesIntoDarkness = time.Hour - NightStartHour; else minutesIntoDarkness = (int)(GameDateTime.HoursPerDay - NightStartHour) + time.Hour; minutesIntoDarkness *= (int)GameDateTime.MinutesPerHour; minutesIntoDarkness += time.Minute; // Since hoursOfDarkness/2 is the darkest point, get the difference of how many hours we are into // darkness and half the total hours of darkness as a percent. This will give us a scale from // [-1, 1] where -1 is the start of night, 0 is the darkest point of night, and 1 is the end of night. var nightMultiplier = (halfMinutesOfDarkness - minutesIntoDarkness) / halfMinutesOfDarkness; // Get the absolute value of the night multiplier so that it instead of -1 to 1, it goes from 1 to 0 to 1 nightMultiplier = Math.Abs(nightMultiplier); // Finally, add the product of the night multiplier to the minMultiplier to "amplify" the darkness nightMultiplier += (1 - nightMultiplier) * MinAmbientMultiplier; return nightMultiplier; }