A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Content;
  3. using Microsoft.Xna.Framework.Graphics;
  4. using System.IO;
  5. // All extension methods on built-in types (of C# or MonoGame) go in this file.
  6. // Methods are ordered alphabetically by type name.
  7. namespace SemiColinGames {
  8. public static class ExtensionMethods {
  9. // ContentManager
  10. public static string LoadString(this ContentManager content, string path) {
  11. string fullPath = Path.Combine(content.RootDirectory, path);
  12. return File.ReadAllText(fullPath);
  13. }
  14. // Point
  15. public static void Deconstruct(this Point point, out int x, out int y) =>
  16. (x, y) = (point.X, point.Y);
  17. // Rectangle
  18. public static Vector2 HalfSize(this Rectangle rect) {
  19. return new Vector2(rect.Width / 2, rect.Height / 2);
  20. }
  21. // SpriteFont
  22. public static Vector2 CenteredOn(this SpriteFont font, string text, Point position) {
  23. Vector2 size = font.MeasureString(text);
  24. return new Vector2(position.X - (int) size.X / 2, position.Y - (int) size.Y / 2);
  25. }
  26. // Vector2
  27. public static Vector2 Rotate(this Vector2 point, float angle) {
  28. float cos = FMath.Cos(angle);
  29. float sin = FMath.Sin(angle);
  30. return new Vector2(
  31. point.X * cos - point.Y * sin,
  32. point.Y * cos + point.X * sin);
  33. }
  34. }
  35. }