public EditorForm() { InitializeComponent(); totalMapsAmount = scanMaps(); scanBackgrounds(); loadBackground(backgroundBox.SelectedIndex); //tiles = new Tilemap(120, 51, 16, Properties.Resources.tileset); currentTile = 0; currentTool = 0; currentTeam = 0; currentFlagTeam = 0; tiles = null; solidObjects = null; harmfulObjects = null; dominationPlates = null; flagPlaces = null; statue = null; //solidObjects = new List<SolidObject>(); //harmfulObjects = new List<HarmfulObject>(); //dominationPlates = new List<DominationPlate>(); //flagPlaces = new FlagPlace[] { new FlagPlace(48, 48, 0), new FlagPlace(48, 48, 1), new FlagPlace(48, 48, 2), new FlagPlace(48, 48, 3) }; //flagPlaces = new List<FlagPlace>(); //statue = new StatueHarvester(32, 48); spawnPoints = new Point[] { new Point(32, 32), new Point(32, 32), new Point(32, 32), new Point(32, 32) }; shift = new Point(0, 0); loadMap(1); }
private void newMap_Click(object sender, EventArgs e) { tiles = new Tilemap((int)numericWidth.Value, (int)numericHeight.Value, 16, Properties.Resources.tileset); solidObjects = new List <SolidObject>(); harmfulObjects = new List <HarmfulObject>(); dominationPlates = new List <DominationPlate>(); flagPlaces = new List <FlagPlace>(); //flagPlaces = new FlagPlace[] { new FlagPlace(48, 48, 0), new FlagPlace(48, 48, 1), new FlagPlace(48, 48, 2), new FlagPlace(48, 48, 3) }; statue = new StatueHarvester(32, 48); spawnPoints = new Point[] { new Point(32, 32), new Point(32, 32), new Point(32, 32), new Point(32, 32) }; writeMap(totalMapsAmount + 1); totalMapsAmount = scanMaps(); mapListBox.SelectedIndex = totalMapsAmount - 1; }
private void loadMap(int index) { StreamReader sr = null; string file = null; if (File.Exists("./map_" + index + ".map")) { //load server data sr = new StreamReader("./map_" + index + ".map"); file = sr.ReadToEnd(); sr.Close(); string[] mapParts = file.Split('#'); //load spawn points string[] spawnData = mapParts[0].Split('\n'); for (int i = 0; i < spawnData.Length; i++) { string[] spwnP = spawnData[i].Split(':'); int x = int.Parse(spwnP[0]); int y = int.Parse(spwnP[1]); spawnPoints[i] = new Point(x, y); } //load solid objects solidObjects = new List <SolidObject>(); string[] solidObjs = mapParts[1].Split('\n'); for (int i = 0; i < solidObjs.Length; i++) { string[] obj = solidObjs[i].Split(':'); int x = int.Parse(obj[0]); int y = int.Parse(obj[1]); int w = int.Parse(obj[2]); int h = int.Parse(obj[3]); bool ss = bool.Parse(obj[4]); solidObjects.Add(new SolidObject(x, y, w, h, ss)); } //load harmful objects harmfulObjects = new List <HarmfulObject>(); if (mapParts.Length > 2 && mapParts[2].Length > 0) { string[] harmObjs = mapParts[2].Split('\n'); for (int i = 0; i < harmObjs.Length; i++) { string[] obj = harmObjs[i].Split(':'); int x = int.Parse(obj[0]); int y = int.Parse(obj[1]); int w = int.Parse(obj[2]); int h = int.Parse(obj[3]); int d = int.Parse(obj[4]); harmfulObjects.Add(new HarmfulObject(x, y, w, h, d)); } } //load domination plates dominationPlates = new List <DominationPlate>(); if (mapParts.Length > 3 && mapParts[3].Length > 0) { string[] domPlates = mapParts[3].Split('\n'); for (int i = 0; i < domPlates.Length; i++) { string[] obj = domPlates[i].Split(':'); int x = int.Parse(obj[0]); int y = int.Parse(obj[1]); dominationPlates.Add(new DominationPlate(x, y, 4)); } } //load flag places flagPlaces = new List <FlagPlace>(); if (mapParts.Length > 4 && mapParts[4].Length > 0) { string[] flgPlces = mapParts[4].Split('\n'); for (int i = 0; i < flgPlces.Length; i++) { string[] obj = flgPlces[i].Split(':'); int x = int.Parse(obj[0]); int y = int.Parse(obj[1]); int team = int.Parse(obj[2]); flagPlaces.Add(new FlagPlace(x, y, team)); } } //load harvester statue if (mapParts.Length > 5 && mapParts[5].Length > 0) { string[] stat = mapParts[5].Split(':'); int x = int.Parse(stat[0]); int y = int.Parse(stat[1]); statue = new StatueHarvester(x, y); } } if (File.Exists("./map_" + index + ".tiles")) { //load client data sr = new StreamReader("./map_" + index + ".tiles"); file = sr.ReadToEnd(); sr.Close(); string[] tileDat = file.Split('#'); //load tilemap width and height int tileX = int.Parse(tileDat[0].Split(':')[0]); int tileY = int.Parse(tileDat[0].Split(':')[1]); numericWidth.Value = tileX; numericHeight.Value = tileY; //load tiles data tiles = new Tilemap(tileX, tileY, 16, Properties.Resources.tileset); string[] tileRows = tileDat[1].Split('\n'); for (int j = 0; j < tileRows.Length; j++) { string[] tileCols = tileRows[j].Split(' '); for (int i = 0; i < tileCols.Length; i++) { tiles.setTile(i, j, short.Parse(tileCols[i])); } } if (tileDat.Length > 2 && tileDat[2].Length > 0) { int bckgrNumber = int.Parse(tileDat[2]); backgroundBox.SelectedIndex = bckgrNumber + 1; } } }
private void screen_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { mousePressed = false; int mouseX = e.X - shift.X; int mouseY = e.Y - shift.Y; if (currentTool == 0) { int x = mouseX / 16 * 16 + 16; int y = mouseY / 16 * 16 + 16; endP = new Point(x, y); solidObjects.Add(new SolidObject(startP.X, startP.Y, endP.X - startP.X, endP.Y - startP.Y, false)); } else if (currentTool == 2) { int x = mouseX / 16 * 16 + 16; int y = mouseY / 16 * 16 + 16; endP = new Point(x, y); Point sP = new Point(Math.Min(startP.X, endP.X), Math.Min(startP.Y, endP.Y)); Point eP = new Point(Math.Max(startP.X, endP.X), Math.Max(startP.Y, endP.Y)); solidObjects.Add(new SolidObject(sP.X, sP.Y, eP.X - sP.X, eP.Y - sP.Y, true)); } else if (currentTool == 4) { int x = mouseX / 16 * 16 + 16; int y = mouseY / 16 * 16 + 16; endP = new Point(x, y); Point sP = new Point(Math.Min(startP.X, endP.X), Math.Min(startP.Y, endP.Y)); Point eP = new Point(Math.Max(startP.X, endP.X), Math.Max(startP.Y, endP.Y)); harmfulObjects.Add(new HarmfulObject(sP.X, sP.Y, eP.X - sP.X, eP.Y - sP.Y, 10)); } else if (currentTool == 1) { int x = mouseX / 16 * 16 + 16; int y = mouseY / 16 * 16 + 16; endP = new Point(x, y); Point sP = new Point(Math.Min(startP.X, endP.X), Math.Min(startP.Y, endP.Y)); Point eP = new Point(Math.Max(startP.X, endP.X), Math.Max(startP.Y, endP.Y)); for (int i = sP.X / 16; i < eP.X / 16; i++) { for (int j = sP.Y / 16; j < eP.Y / 16; j++) { tiles.setTile(i, j, currentTile); } } } else if (currentTool == 3) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; spawnPoints[currentTeam] = new Point(x, y); } else if (currentTool == 7) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; statue = new StatueHarvester(x, y); } else if (currentTool == 5) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; dominationPlates.Add(new DominationPlate(x, y, 4)); } else if (currentTool == 6) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; //flagPlaces[currentFlagTeam] = new FlagPlace(x, y, currentFlagTeam); flagPlaces.Add(new FlagPlace(x, y, currentFlagTeam)); } } else if (e.Button == MouseButtons.Right) { int mouseX = e.X - shift.X; int mouseY = e.Y - shift.Y; if (currentTool == 0 || currentTool == 2) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; for (int i = solidObjects.Count - 1; i >= 0; i--) { if (x >= solidObjects[i].box.X && x < solidObjects[i].box.X + solidObjects[i].box.Width && y >= solidObjects[i].box.Y && y < solidObjects[i].box.Y + solidObjects[i].box.Height) { solidObjects.RemoveAt(i); } } } else if (currentTool == 4) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; for (int i = harmfulObjects.Count - 1; i >= 0; i--) { if (x >= harmfulObjects[i].box.X && x < harmfulObjects[i].box.X + harmfulObjects[i].box.Width && y >= harmfulObjects[i].box.Y && y < harmfulObjects[i].box.Y + harmfulObjects[i].box.Height) { harmfulObjects.RemoveAt(i); } } } else if (currentTool == 1) { int x = mouseX / 16; int y = mouseY / 16; tiles.setTile(x, y, -1); } else if (currentTool == 5) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; for (int i = dominationPlates.Count - 1; i >= 0; i--) { if (dominationPlates[i].getSprite.checkCollision(new Rectangle(x, y, 16, 16))) { dominationPlates.RemoveAt(i); } } } else if (currentTool == 6) { int x = mouseX / 16 * 16; int y = mouseY / 16 * 16; for (int i = flagPlaces.Count - 1; i >= 0; i--) { if (flagPlaces[i].GetSprite.checkCollision(new Rectangle(x, y, 16, 16))) { flagPlaces.RemoveAt(i); } } } } }