//default map constructor, makes a concrete bitmap with nothing on it public Map(ContentManager content, int screenWidth, int screenHeight) { tileSize = screenWidth / 20; tileMap = new Texture2D[20, 100]; objectMap = new MapObject[tileMap.GetLength(0), tileMap.GetLength(1)]; tileRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)]; objRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)]; //loops through entire tileMap array and sets each value to concrete for (int i = 0; i < tileMap.GetLength(0); i++) { for (int j = 0; j < tileMap.GetLength(1); j++) { tileMap[i, j] = content.Load<Texture2D>("ConcreteCorner"); } } //loops through objectMap array and sets edges to noTexture for (int i = 0; i < objectMap.GetLength(0); i++) { for (int j = 0; j < objectMap.GetLength(1); j++) { objectMap[i, j] = new MapObject(content, true, "NoTexture", i, j); } } for (int i = 1; i < objectMap.GetLength(0) - 1; i++) { for (int j = 1; j < objectMap.GetLength(1) - 1; j++) { objectMap[i, j] = null; } } for (int i = 1; i < objectMap.GetLength(0); i += 6) { for (int j = 0; j < objectMap.GetLength(1) - 3; j++) { objectMap[i, j] = new MapObject(content, true, "NoTexture", i, j); } } }
// constructor that reads fro a file map.cs public Map(ContentManager content, string filename, Camera c, Character player, List<Enemy> enemies, int screenWidth) { Texture2D empTexture = content.Load<Texture2D>("EmptyTile"); tileSize = screenWidth / 20; BinaryReader input = new BinaryReader(File.OpenRead("Content/" + filename)); int mapWidth = input.ReadInt32(); int mapHeight = input.ReadInt32(); tileMap = new Texture2D[mapWidth, mapHeight]; objectMap = new MapObject[mapWidth, mapHeight]; tileRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)]; objRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)]; for (int i = 0; i < tileMap.GetLength(0); i++) { for (int j = 0; j < tileMap.GetLength(1); j++) { string txtrString = input.ReadString(); if (!txtrString.Equals("null")) { Texture2D texture = content.Load<Texture2D>(txtrString); tileMap[i, j] = texture; } else { tileMap[i, j] = empTexture; } } } for (int i = 0; i < tileMap.GetLength(0); i++) { for (int j = 0; j < tileMap.GetLength(1); j++) { tileRot[i, j] = input.ReadInt32(); } } for (int i = 0; i < objectMap.GetLength(0); i++) { for (int j = 0; j < objectMap.GetLength(1); j++) { string txtrString = input.ReadString(); if (!txtrString.Equals("null")) { objectMap[i, j] = new MapObject(content, true, txtrString, i, j); } else { objectMap[i, j] = null; } } } for (int i = 0; i < objectMap.GetLength(0); i++) { for (int j = 0; j < objectMap.GetLength(1); j++) { objRot[i, j] = input.ReadInt32(); } } int entWidth = input.ReadInt32(); int entHieght = input.ReadInt32(); int[,] entRot = new int[entWidth, entHieght]; for (int i = 0; i < entRot.GetLength(0); i++) { for (int j = 0; j < entRot.GetLength(1); j++) { entRot[i, j] = input.ReadInt32(); } } for (int x = 0; x < entWidth; x++) { for (int y = 0; y < entHieght; y++) { string txtrString = input.ReadString(); if (txtrString.Equals("null")) { continue; } else if (txtrString.Equals("Enemy")) { CreateEnemy.CreateNormalEnemy(ref enemies, content, c, this, x, y, entRot[x,y] * -1.5708f); } else if (txtrString.Equals("RiotEnemy")) { CreateEnemy.CreateRiotEnemy(ref enemies, content, c, this, x, y, entRot[x, y] * -1.5708f); } } } string playerPos = input.ReadString(); string[] playerParts = playerPos.Split(','); double distX = player.Loc.X - double.Parse(playerParts[1]); double distY = player.Loc.Y - double.Parse(playerParts[2]); player.Loc.X -= distX; player.Loc.Y -= distY; c.camPos.X += distX; c.camPos.Y += distY; input.Close(); }