public void LoadData() { const float SCALE = 0.008f; float baseX = X * SCALE * SIZE; float baseY = Y * SCALE * SIZE; float min = float.MaxValue; float max = float.MinValue; noise.SetPerlinPersistence(0.4f); for (int x = 0; x < SIZE; x++) { for (int y = 0; y < SIZE; y++) { float n = noise.GetPerlin(baseX + x * SCALE, baseY + y * SCALE, 0); // Remap noise form -1 -> 1 to 0 -> 1 n *= 0.5f; n += 0.5f; Color c = Color.Blue; if (n > 0.9f) { c = Color.NavajoWhite; } else if (n > 0.8f) { c = Color.DarkSlateGray; } else if (n > 0.65f) { c = Color.DimGray; } else if (n > 0.5f) { c = Color.LawnGreen; } else if (n > 0.25f) { c = Color.SandyBrown; } else if (n > 0.2f) { c = Color.Yellow; } if (n > max) { max = n; } if (n < min) { min = n; } tiles[GetIndex(x, y, 0)] = new Tile(1, ColorCache.EnsureColor(c)); if (c == Color.LawnGreen || c == Color.SandyBrown) { if (Rand.Chance(0.3f)) { tiles[GetIndex(x, y, 1)] = new Tile(3, ColorCache.EnsureColor(Color.White)); } } } } }
public override void Draw(SpriteBatch spr, Tile tile, Chunk chunk, int localX, int localY, int z) { spr.Draw(CalculateSprite(localX + chunk.X * Chunk.SIZE, localY + chunk.Y * Chunk.SIZE, z), new Rectangle(localX * SIZE, localY * SIZE, SIZE, SIZE), ColorCache.GetColor(tile.ColorRef)); }