private static Tile GenerateTile(Point position) { Tile tile = new Tile(position, map.TileSize); int rNumber = rand.Next(100); int chance = 30; if (rNumber < chance) { TerrainEntity rockEntity = new TerrainEntity(tile); Texture2D texture = rock; Rectangle destinationRectangle = tile.Rect; Rectangle sourceRectangle = Rectangle.Empty; if (texture == null) { sourceRectangle = Rectangle.Empty; } rockEntity.SetDrawData(texture, destinationRectangle, sourceRectangle, 0.5f); rockEntity.IsBlocked = true; tile.AddEntity(rockEntity); } TerrainEntity terrainEntity = new TerrainEntity(tile); rNumber = rand.Next(100); chance = 80; if (rNumber < chance) { Texture2D texture2 = tile_green; Rectangle destinationRectangle2 = tile.Rect; Rectangle sourceRectangle2 = Rectangle.Empty; if (texture2 == null) { sourceRectangle2 = Rectangle.Empty; } terrainEntity.SetDrawData(texture2, destinationRectangle2, sourceRectangle2, 0.2f); } else { Texture2D texture3 = tile_brown; Rectangle destinationRectangle3 = tile.Rect; Rectangle sourceRectangle3 = Rectangle.Empty; if (texture3 == null) { sourceRectangle3 = Rectangle.Empty; } terrainEntity.SetDrawData(texture3, destinationRectangle3, sourceRectangle3, 0.2f); } tile.AddEntity(terrainEntity); //tile.MapIndex = map.AddTile(tile); return tile; }
private Map BuildEmptyMap(int width, int height) { Map result = new Map(new Point(50, 50), 256, width, height); Point size = result.TileSize; int xMax = size.X * width; int yMax = size.Y * height; var noise = new PerlinNoise(100, 100); for (int x = 0; x < xMax; x = x + size.X) { for (int y = 0; y < yMax; y = y + size.Y) { int tileSelection = random.Next(0, 3); Vector2 position = new Vector2((float)x, (float)y); Tile newTile = new Tile(position, size); var perlin = noise.GetRandomHeight((position.X / xMax) * 100, (position.Y / yMax) * 100, 1.0f, 1.0f, 0.0000000001f, 1.0f, 4); if (perlin < 0.5f && perlin >= 0.0f) newTile.AddEntity(new DirtEntity(newTile, this.dirtTexture[tileSelection], Color.White, false)); if (perlin < 0.9f && perlin >= 0.5f) newTile.AddEntity(new MudEntity(newTile, this.muckTexture[tileSelection], Color.White, false)); if (perlin <= 1.0f && perlin >= 0.9f) newTile.AddEntity(new SludgeEntity(newTile, this.sludgeTexture[tileSelection], Color.White, false)); result.Add(newTile); } } result.CalculateAdjacentTiles(); result.CalculateTileIntensity(); return result; }