+ /// <summary>\r
+ /// The container class for map metadata.\r
+ /// </summary>\r
+ public class Metadata\r
+ {\r
+ public string Name;\r
+ public Mode Type;\r
+ public string Author;\r
+ public HashSet<int> NumPlayers = new HashSet<int>();\r
+ public string Tileset;\r
+ public int GridWidth;\r
+ public int GridHeight;\r
+ }\r
+\r
+ /// <summary>\r
+ /// The container class for information about an entity defined in the map.\r
+ /// </summary>\r
+ public class RawEntity\r
+ {\r
+ public char Id;\r
+ public Point Position;\r
+ public Dictionary<string, string> Attributes = new Dictionary<string, string>();\r
+ }\r
+\r
+ #endregion\r
+\r
+\r
+ #region Public Properties\r
+\r
+ /// <summary>\r
+ /// Get the name of the map.\r
+ /// </summary>\r
+ public string Name { get { return mData.Metadata.Name; } }\r
+\r
+ /// <summary>\r
+ /// Get the type of the map.\r
+ /// </summary>\r
+ public Mode Type { get { return mData.Metadata.Type; } }\r
+\r
+ /// <summary>\r
+ /// Get the author of the map.\r
+ /// </summary>\r
+ public string Author { get { return mData.Metadata.Author; } }\r
+\r
+ /// <summary>\r
+ /// Get a set of integers containing each allowable number of players.\r
+ /// </summary>\r
+ public HashSet<int> NumPlayers { get { return mData.Metadata.NumPlayers; } }\r
+\r
+ /// <summary>\r
+ /// Get the width of the map, in grid units.\r
+ /// </summary>\r
+ public int Width { get { return mData.Metadata.GridWidth; } }\r
+\r
+ /// <summary>\r
+ /// Get the height of the map, in grid units.\r
+ /// </summary>\r
+ public int Height { get { return mData.Metadata.GridHeight; } }\r
+\r
+ /// <summary>\r
+ /// Get the name of the tileset.\r
+ /// </summary>\r
+ public string Tileset { get { return mData.Metadata.Tileset; } }\r
+\r
+ /// <summary>\r
+ /// Get the current grid of open cells. On the grid, true means\r
+ /// the cell is open (i.e. an entity can occupy that cell), and false\r
+ /// means the cell is closed. Note that, just like Map.IsCellOpen,\r
+ /// only static scenery is considered; the grid cannot tell you\r
+ /// whether or not an entity is already occupying the cell.\r
+ /// </summary>\r
+ public bool[,] Grid { get { return mData.Grid; } }\r
+\r
+ /// <summary>\r
+ /// Get a list of the raw entity containers loaded with the map. If you\r
+ /// want to get the actual entity objects, use Map.GetEntities and\r
+ /// Map.GetAllEntities instead.\r
+ /// </summary>\r
+ public List<RawEntity> RawEntities { get { return mData.Entities; } }\r
+\r
+\r
+ /// <summary>\r
+ /// Get and set the coordinate of the grid cell that should be in\r
+ /// the center of the screen when the map is drawn. Setting this\r
+ /// will change the viewport of the map and will effect the return\r
+ /// values of Map.GetPointFromCoordinates and Map.GetRectangleFromCoordinates.\r
+ /// </summary>\r
+ public Vector2 CenterCell\r
+ {\r
+ get { return mView.CenterCell; }\r
+ set { mView.CenterCell = value; }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get and set the tilemap with its associated texture and tile\r
+ /// character to coordinate mappings. This effects what the map looks\r
+ /// like when it is drawn.\r
+ /// </summary>\r
+ public Tilemap Tilemap\r
+ {\r
+ get { return mView.Tilemap; }\r
+ set { mView.Tilemap = value; }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get and set the zoom of the map view. The default zoom is\r
+ /// Map.PixelsToUnitSquares.\r
+ /// </summary>\r
+ public float Zoom\r
+ {\r
+ get { return mView.Zoom; }\r
+ set { mView.Zoom = value; }\r
+ }\r
+\r
+ #endregion\r
+\r
+\r
+ #region Public Methods\r
+\r
+ /// <summary>\r
+ /// Construct a map with the provided map data.\r
+ /// </summary>\r
+ /// <param name="metadata">The metadata.</param>\r
+ /// <param name="grid">The grid.</param>\r
+ /// <param name="entities">The entities.</param>\r
+ public Map(Metadata metadata, char[,] grid, char defaultTile,\r
+ List<RawEntity> entities, Point[] playerPositions)\r
+ {\r
+ mData = new Model(metadata, grid, defaultTile, entities, playerPositions);\r
+ mView = new View(mData);\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Draw a representation of the map to the screen.\r
+ /// </summary>\r
+ /// <param name="spriteBatch">The jeewiz.</param>\r
+ public void Draw(SpriteBatch spriteBatch)\r
+ {\r
+ mView.Draw(spriteBatch);\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Get a point in screen-space from a coordinate in gridspace.\r
+ /// </summary>\r
+ /// <param name="x">X-coordinate.</param>\r
+ /// <param name="y">Y-coordinate.</param>\r
+ /// <returns>Transformed point.</returns>\r
+ public Point GetPointFromCoordinates(float x, float y)\r
+ {\r
+ return mView.GetPointFromCoordinates(x, y);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get a point in screen-space from a coordinate in gridspace.\r
+ /// </summary>\r
+ /// <param name="point">X,Y-coordinates.</param>\r
+ /// <returns>Transformed point.</returns>\r
+ public Point GetPointFromCoordinates(Vector2 point)\r
+ {\r
+ return mView.GetPointFromCoordinates(point.X, point.Y);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get a rectangle in screen-space centered around a coordinate in gridspace.\r
+ /// </summary>\r
+ /// <param name="x">X-coordinate.</param>\r
+ /// <param name="y">Y-coordinate.</param>\r
+ /// <returns>Transformed rectangle.</returns>\r
+ public Rectangle GetRectangleFromCoordinates(float x, float y)\r
+ {\r
+ return mView.GetRectangleFromCoordinates(x, y);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get a rectangle in screen-space centered around a coordinate in gridspace.\r
+ /// </summary>\r
+ /// <param name="point">X,Y-coordinates.</param>\r
+ /// <returns>Transformed rectangle.</returns>\r
+ public Rectangle GetRectangleFromCoordinates(Vector2 point)\r
+ {\r
+ return mView.GetRectangleFromCoordinates(point.X, point.Y);\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Determine whether or not a cell can be occupied by a game entity.\r
+ /// </summary>\r
+ /// <param name="x">X-coordinate.</param>\r
+ /// <param name="y">Y-coordinate.</param>\r
+ /// <returns>True if cell can be occupied, false otherwise.</returns>\r
+ public bool IsCellOpen(int x, int y)\r
+ {\r
+ return mData.IsCellOpen(x, y);\r
+ }\r
+\r
+ /// <summary>\r
+ /// created by Brady for AI precalculations\r
+ /// </summary>\r
+ /// <param name="x">X-coordinate.</param>\r
+ /// <param name="y">Y-coordinate.</param>\r
+ public bool IsWall(int x, int y)\r
+ {\r
+ return mData.IsWall(x, y);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Determine whether or not a cell can be occupied by a game entity.\r
+ /// </summary>\r
+ /// <param name="point">X,Y-coordinates.</param>\r
+ /// <returns>True if cell can be occupied, false otherwise.</returns>\r
+ public bool IsCellOpen(Point point)\r
+ {\r
+ return mData.IsCellOpen(point.X, point.Y);\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Get the starting position of a player.\r
+ /// </summary>\r
+ /// <param name="playerNumber">The number of the player (i.e. 1-4).\r
+ /// This number must be a valid player number.</param>\r
+ /// <returns>The starting position of the player.</returns>\r
+ public Point GetStartingPositionForPlayer(int playerNumber)\r
+ {\r
+ Debug.Assert(1 <= playerNumber && playerNumber <= NumPlayers.Max());\r
+ return mData.PlayerPositions[playerNumber];\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Get all the entities loaded from the map file. Exceptions could be\r
+ /// thrown if there are entities without associated classes.\r
+ /// </summary>\r
+ /// <param name="game">The game reference to be passed to entities.</param>\r
+ /// <returns>List of entity objects loaded.</returns>\r
+ public List<IEntity> GetAllEntities(Game game)\r
+ {\r
+ return mData.GetAllEntities(game);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get the entities of a certain type loaded from the map file. Exceptions\r
+ /// could be thrown if there are entities without associated classes.\r
+ /// </summary>\r
+ /// <param name="game">The game reference to be passed to entities.</param>\r
+ /// <typeparam name="T">Type of the entity you want a list of.</typeparam>\r
+ /// <returns>List of entity objects loaded.</returns>\r
+ public List<T> GetEntities<T>(Game game)\r
+ {\r
+ return mData.GetEntities<T>(game);\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Set the tile of a cell.\r
+ /// </summary>\r
+ /// <param name="x">X-coordinate.</param>\r
+ /// <param name="y">Y-coordinate.</param>\r
+ /// <param name="tile">The character representing the tile.</param>\r
+ public void SetCell(int x, int y, char tile)\r
+ {\r
+ mData.SetCell(x, y, tile);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Set the tile of a cell.\r
+ /// </summary>\r
+ /// <param name="point">X,Y-coordinates.</param>\r
+ /// <param name="tile">The character representing the tile.</param>\r
+ public void SetCell(Point point, char tile)\r
+ {\r
+ mData.SetCell(point.X, point.Y, tile);\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Clear a cell to the default tile.\r
+ /// </summary>\r
+ /// <param name="x">X-coordinate.</param>\r
+ /// <param name="y">Y-coordinate.</param>\r
+ public void ClearCell(int x, int y)\r
+ {\r
+ mData.ClearCell(x, y);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Clear a cell to the default tile.\r
+ /// </summary>\r
+ /// <param name="point">X,Y-coordinates.</param>\r
+ public void ClearCell(Point point)\r
+ {\r
+ mData.ClearCell(point.X, point.Y);\r
+ }\r
+\r
+\r
+ /// <summary>\r
+ /// Reset the map to the state it was at right after loading.\r
+ /// </summary>\r
+ public void Reset()\r
+ {\r
+ mData.Reset();\r
+ mView.Reset();\r
+ }\r
+\r