using System; using Microsoft.Xna.Framework; namespace DepthsBelow { /// /// Global grid utility functions. /// public static class Grid { /// /// The size of a tile in pixels. /// public const int TileSize = 32; /// /// Converts a grid position into a world position. /// /// The grid position to convert. /// Returns a Vector2 world position. public static Vector2 GridToWorld(Point gridPos) { return new Vector2(gridPos.X * TileSize, gridPos.Y * TileSize); } /// /// Converts a world position into a grid position. /// /// The world position to convert. /// Returns a Point grid position. public static Point WorldToGrid(Vector2 screenPos) { return new Point( (int)Math.Floor(screenPos.X / TileSize), (int)Math.Floor(screenPos.Y / TileSize) ); } } }