2020-02-25 01:45:38 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2020-03-04 21:16:41 +00:00
|
|
|
|
using Microsoft.Xna.Framework.Content;
|
2020-02-27 20:46:16 +00:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2020-03-04 21:16:41 +00:00
|
|
|
|
using System.IO;
|
2020-02-25 01:45:38 +00:00
|
|
|
|
|
|
|
|
|
// All extension methods on built-in types (of C# or MonoGame) go in this file.
|
2020-02-27 20:46:16 +00:00
|
|
|
|
// Methods are ordered alphabetically by type name.
|
2020-02-25 01:45:38 +00:00
|
|
|
|
|
|
|
|
|
namespace SemiColinGames {
|
2020-03-09 16:22:33 +00:00
|
|
|
|
public static class ExtensionMethods {
|
2020-03-04 21:16:41 +00:00
|
|
|
|
// ContentManager
|
|
|
|
|
public static string LoadString(this ContentManager content, string path) {
|
|
|
|
|
string fullPath = Path.Combine(content.RootDirectory, path);
|
|
|
|
|
return File.ReadAllText(fullPath);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-27 20:46:16 +00:00
|
|
|
|
// Point
|
|
|
|
|
public static void Deconstruct(this Point point, out int x, out int y) =>
|
|
|
|
|
(x, y) = (point.X, point.Y);
|
|
|
|
|
|
2020-03-10 21:10:09 +00:00
|
|
|
|
// Rectangle
|
|
|
|
|
public static Vector2 HalfSize(this Rectangle rect) {
|
|
|
|
|
return new Vector2(rect.Width / 2, rect.Height / 2);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-27 20:46:16 +00:00
|
|
|
|
// SpriteFont
|
|
|
|
|
public static Vector2 CenteredOn(this SpriteFont font, string text, Point position) {
|
|
|
|
|
Vector2 size = font.MeasureString(text);
|
|
|
|
|
return new Vector2(position.X - (int) size.X / 2, position.Y - (int) size.Y / 2);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-25 01:45:38 +00:00
|
|
|
|
// Vector2
|
|
|
|
|
public static Vector2 Rotate(this Vector2 point, float angle) {
|
|
|
|
|
float cos = FMath.Cos(angle);
|
|
|
|
|
float sin = FMath.Sin(angle);
|
|
|
|
|
return new Vector2(
|
|
|
|
|
point.X * cos - point.Y * sin,
|
|
|
|
|
point.Y * cos + point.X * sin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|