public TerrainDisplay(TerrainTile[,] tiles) { mode = Mode.Erase; this.tilesBak = (TerrainTile[,])tiles.Clone(); this.tiles = tiles; ClientSize = new Size(800, 800); BackColor = Color.Black; WindowState = FormWindowState.Maximized; panel = new Panel() { Dock = DockStyle.Fill, AutoScroll = true, Controls = { (pic = new PictureBox() { Image = bmp = RenderColorBmp(tiles), SizeMode = PictureBoxSizeMode.AutoSize, }) } }; panel.HorizontalScroll.Enabled = true; panel.VerticalScroll.Enabled = true; panel.HorizontalScroll.Visible = true; panel.VerticalScroll.Visible = true; Controls.Add(panel); pic2 = new PictureBox() { Image = bmp, Width = 250, Height = 250, SizeMode = PictureBoxSizeMode.Zoom }; Controls.Add(pic2); pic2.BringToFront(); Text = mode.ToString(); pic.MouseMove += new MouseEventHandler(pic_MouseMove); pic.MouseDoubleClick += new MouseEventHandler(pic_MouseDoubleClick); }
void Randomize(TerrainTile[,] buff) { int w = buff.GetLength(0); int h = buff.GetLength(1); TerrainTile[,] tmp = (TerrainTile[,])buff.Clone(); for (int y = 10; y < h - 10; y++) for (int x = 10; x < w - 10; x++) { var tile = buff[x, y]; if (tile.TileId == TileTypes.Water && tile.Elevation >= elevationThreshold[3]) tile.TileId = TileTypes.SnowRock; else if (tile.TileId != TileTypes.Water && tile.TileId != TileTypes.Road && tile.TileId != TileTypes.Beach && tile.TileId != TileTypes.MovingWater && tile.TileId != TileTypes.DeepWater) { var id = tmp[x + rand.Next(-3, 4), y + rand.Next(-3, 4)].TileId; while (id == TileTypes.Water || id == TileTypes.Road || id == TileTypes.Beach || id == TileTypes.MovingWater || id == TileTypes.DeepWater) id = tmp[x + rand.Next(-3, 4), y + rand.Next(-3, 4)].TileId; tile.TileId = id; } //if (tile.TileId == TileTypes.Beach) // tile.Region = TileRegion.Spawn; string biome = tile.Biome; if (tile.TileId == TileTypes.Beach) biome = "beach"; else if (tile.TileId == TileTypes.MovingWater) biome = "coast"; var biomeObj = Decoration.GetDecor(biome, rand); if (biomeObj != null) { tile.TileObj = biomeObj; var size = Decoration.GetSize(biomeObj, rand); if (size != null) tile.Name = "size:" + size; } float elevation = 0; int c = 0; for (int dy = -1; dy <= 1; dy++) for (int dx = -1; dx <= 1; dx++) { if (x + dx < 0 || x + dx >= w || y + dy < 0 || y + dy >= h) continue; elevation += tmp[x + dx, y + dy].Elevation; c++; } tile.Elevation = elevation / c; buff[x, y] = tile; } }