public void AddColLayer(string key, CollisionLayer colLayer) { this.colLayers.Add(key, colLayer); }
private void adjustSizeOfMapToolStripMenuItem1_Click(object sender, EventArgs e) { sizeForm form = new sizeForm(); form.ShowDialog(); TileMap tempTileMap = new TileMap(); TileLayer templayer; CollisionLayer tempcolllayer; if (form.OKPressed) { tempTileMap = new TileMap(); if (int.Parse(form.leftNegTextBox.Text) > 0 || int.Parse(form.leftPosTextBox.Text) > 0 || int.Parse(form.upNegTextBox.Text) > 0 || int.Parse(form.upPosTextBox.Text) > 0) { foreach (TileLayer layer in tileMap.Layers) { templayer = new TileLayer(layer.Width + int.Parse(form.leftPosTextBox.Text) - int.Parse(form.leftNegTextBox.Text), layer.Height + int.Parse(form.upPosTextBox.Text) - int.Parse(form.upNegTextBox.Text)); for (int x = 0; x < templayer.Width; x++) { for (int y = 0; y < templayer.Height; y++) { if (y < int.Parse(form.upPosTextBox.Text) - int.Parse(form.upNegTextBox.Text) || x < int.Parse(form.leftPosTextBox.Text) - int.Parse(form.leftNegTextBox.Text)) templayer.SetCellIndex(x, y, -1); else templayer.SetCellIndex(x, y, layer.GetCellIndex(x - int.Parse(form.leftPosTextBox.Text) + int.Parse(form.leftNegTextBox.Text), y - int.Parse(form.upPosTextBox.Text) + int.Parse(form.upNegTextBox.Text))); } } foreach (Texture2D textures in layer.ListofTextures) { templayer.AddTexture(textures); } foreach (TreasureChest chest in layer.ListofChests) { chest.Postition.X += int.Parse(form.leftPosTextBox.Text) - int.Parse(form.leftNegTextBox.Text); chest.Postition.Y += int.Parse(form.upPosTextBox.Text) - int.Parse(form.upNegTextBox.Text); if (chest.Postition.X > templayer.Width || chest.Postition.Y > templayer.Height) continue; templayer.AddChest(chest); } foreach (Door door in layer.ListofDoors) { door.Postition.X += int.Parse(form.leftPosTextBox.Text) - int.Parse(form.leftNegTextBox.Text); door.Postition.Y += int.Parse(form.upPosTextBox.Text) - int.Parse(form.upNegTextBox.Text); if (door.Postition.X > templayer.Width || door.Postition.Y > templayer.Height) continue; templayer.AddDoor(door); } tempTileMap.Layers.Add(templayer); } tempcolllayer = new CollisionLayer(tileMap.CollisionLayer.Width + int.Parse(form.leftPosTextBox.Text) - int.Parse(form.leftNegTextBox.Text), tileMap.CollisionLayer.Height + int.Parse(form.upPosTextBox.Text) - int.Parse(form.upNegTextBox.Text)); for (int x = 0; x < tempcolllayer.Width; x++) { for (int y = 0; y < tempcolllayer.Height; y++) { if (y < int.Parse(form.upPosTextBox.Text) - int.Parse(form.upNegTextBox.Text) || x < int.Parse(form.leftPosTextBox.Text) - int.Parse(form.leftNegTextBox.Text)) tempcolllayer.SetCellIndex(x, y, -1); else tempcolllayer.SetCellIndex(x, y, tileMap.CollisionLayer.GetCellIndex(x - int.Parse(form.leftPosTextBox.Text) + int.Parse(form.leftNegTextBox.Text), y - int.Parse(form.upPosTextBox.Text) + int.Parse(form.upNegTextBox.Text))); } } tempTileMap.CollisionLayer = tempcolllayer; tileMap = tempTileMap; Dictionary<string, TileLayer> templayerdict = new Dictionary<string, TileLayer>(); int count = 0; foreach (string layer in layerDict.Keys) { templayerdict.Add(layer, tileMap.Layers[count]); count++; } layerDict = templayerdict; currentLayer = null; layerListBox.SelectedItem = null; } if (int.Parse(form.rightNegTextBox.Text) > 0 || int.Parse(form.rightPosTextBox.Text) > 0 || int.Parse(form.downNegTextBox.Text) > 0 || int.Parse(form.downPosTextBox.Text) > 0) { tempTileMap = new TileMap(); foreach (TileLayer layer in tileMap.Layers) { templayer = new TileLayer(layer.Width + int.Parse(form.rightPosTextBox.Text) - int.Parse(form.rightNegTextBox.Text), layer.Height + int.Parse(form.downPosTextBox.Text) - int.Parse(form.downNegTextBox.Text)); for (int x = 0; x < templayer.Width; x++) { for (int y = 0; y < templayer.Height; y++) { templayer.SetCellIndex(x, y, layer.GetCellIndex(x, y)); } } foreach (Texture2D textures in layer.ListofTextures) { templayer.AddTexture(textures); } foreach (TreasureChest chest in layer.ListofChests) { if (chest.Postition.X > templayer.Width || chest.Postition.Y > templayer.Height) continue; templayer.AddChest(chest); } foreach (Door door in layer.ListofDoors) { if (door.Postition.X > templayer.Width || door.Postition.Y > templayer.Height) continue; templayer.AddDoor(door); } tempTileMap.Layers.Add(templayer); } tempcolllayer = new CollisionLayer(tileMap.CollisionLayer.Width + int.Parse(form.rightPosTextBox.Text) - int.Parse(form.rightNegTextBox.Text), tileMap.CollisionLayer.Height + int.Parse(form.downPosTextBox.Text) - int.Parse(form.downNegTextBox.Text)); for (int y = 0; y < tempcolllayer.Height; y++) { for (int x = 0; x < tempcolllayer.Width; x++) { tempcolllayer.SetCellIndex(x, y, tileMap.CollisionLayer.GetCellIndex(x, y)); } } tempTileMap.CollisionLayer = tempcolllayer; tileMap = tempTileMap; Dictionary<string, TileLayer> templayerdict = new Dictionary<string, TileLayer>(); int count = 0; foreach (string layer in layerDict.Keys) { templayerdict.Add(layer, tileMap.Layers[count]); count++; } layerDict = templayerdict; currentLayer = null; layerListBox.SelectedItem = null; } } }
public static CollisionLayer FromFile(string rootDirectory, string filename) { CollisionLayer CollisionLayer; ParseState parseState = ParseState.None; List<List<int>> tempLayout = new List<List<int>>(); filename = string.Format("{0}/{1}", rootDirectory, filename); using (StreamReader reader = new StreamReader(filename)) { while (!reader.EndOfStream) { string line = reader.ReadLine().Trim(); if (!string.IsNullOrEmpty(line)) { if (line.Contains("[Layout]")) { parseState = ParseState.Layout; } else { switch (parseState) { case ParseState.Layout: List<int> row = new List<int>(); string[] cells = line.Split(' '); foreach (string c in cells) { if (!string.IsNullOrEmpty(c)) { row.Add(int.Parse(c)); } } tempLayout.Add(row); break; } } } } } int width = tempLayout[0].Count; int height = tempLayout.Count; CollisionLayer = new CollisionLayer(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { CollisionLayer.SetCellIndex(x, y, tempLayout[y][x]); } } return CollisionLayer; }
public static CollisionLayer FromFile(string filename) { CollisionLayer collisionLayer; List<int> tempLayout = new List<int>(); int width = 0; int height = 0; XmlTextReader reader = new XmlTextReader(filename); reader.WhitespaceHandling = WhitespaceHandling.None; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "Layout") { List<int> row = new List<int>(); width = int.Parse(reader["Width"]); height = int.Parse(reader["Height"]); reader.Read(); string[] cells = reader.Value.Split(' '); foreach (string c in cells) { if (!string.IsNullOrEmpty(c)) { if (c.Contains("\r\n")) continue; tempLayout.Add(int.Parse(c)); } } } } } reader.Close(); collisionLayer = new CollisionLayer(width, height); int next = 0; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { collisionLayer.SetCellIndex(x, y, tempLayout[next]); next++; } return collisionLayer; }
public static CollisionLayer FromFile(string filename) { CollisionLayer tileLayer; List<List<int>> tempLayout = new List<List<int>>(); //using statement disposes of everything after the brackets, always use with file IO using (StreamReader reader = new StreamReader(filename)) { bool readingLayout = false; while (!reader.EndOfStream) { string line = reader.ReadLine().Trim(); if (string.IsNullOrEmpty(line)) continue; if (line.Contains("[Layout]")) { readingLayout = true; } else if (readingLayout) { List<int> row = new List<int>(); string[] cells = line.Split(' '); foreach (string c in cells) { if (!string.IsNullOrEmpty(c)) row.Add(int.Parse(c)); } tempLayout.Add(row); } } } //width = Cells in first row int width = tempLayout[0].Count; //number of rows int height = tempLayout.Count; tileLayer = new CollisionLayer(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { tileLayer.SetCellIndex(x, y, tempLayout[y][x]); } } return tileLayer; }