/TTengine/util/TTutil.cs

http://github.com/trancetrance/TTengine · C# · 55 lines · 34 code · 4 blank · 17 comment · 3 complexity · 3b50fae0bb9eccfbcde9265f6366cb1f MD5 · raw file

  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. namespace TTengine.Util
  7. {
  8. /**
  9. * general utility methods that are handy in creating your games
  10. */
  11. public class TTUtil
  12. {
  13. /// <summary>
  14. /// Rounds the components of a Vector2 in-place
  15. /// </summary>
  16. /// <param name="input">Vector2 to round</param>
  17. public static void Round(ref Vector2 input)
  18. {
  19. input.X = (float)Math.Round(input.X);
  20. input.Y = (float)Math.Round(input.Y);
  21. }
  22. /// <summary>
  23. /// Count the number of lines in a string
  24. /// </summary>
  25. /// <param name="s">The string</param>
  26. /// <returns>The linecount, or 0 if empty string</returns>
  27. public static int LineCount(string s)
  28. {
  29. if (s.Length == 0)
  30. return 0;
  31. int result = 1;
  32. foreach (char c in s)
  33. {
  34. if (c.Equals('\n'))
  35. {
  36. result++;
  37. }
  38. }
  39. return result;
  40. }
  41. /// <summary>
  42. /// Invert color
  43. /// </summary>
  44. /// <param name="c">color to invert</param>
  45. /// <returns>Inverted color, "1-c"</returns>
  46. public static Color InvertColor(Color c)
  47. {
  48. return new Color(new Vector3(1f, 1f, 1f) - c.ToVector3());
  49. }
  50. }
  51. }