Esempio n. 1
0
 // Perlin
 void DetermineLandmass()
 {
     waters.Clear();
     var noise = new Noise(seed);
     foreach (var i in Polygons)
     {
         int total = 0;
         int water = 0;
         foreach (var j in i.Nodes)
         {
             //var n = noise[(int)((j.X + 1) / 2 * 255), (int)((j.Y + 1) / 2 * 255)];
             var n = noise.GetNoise((j.X + 1) * 2, (j.Y + 1) * 2, 0);
             var d = j.X * j.X + j.Y * j.Y;
             if (n < d * 0.7 ||
                 (Math.Abs(j.X) > 0.9 || Math.Abs(j.Y) > 0.9))
             {
                 j.IsWater = true;
                 waters.Add(j);
                 water++;
             }
             total++;
         }
     }
 }
Esempio n. 2
0
 static Bitmap RenderNoiseBmp(int w, int h)
 {
     Bitmap bmp = new Bitmap(w, h);
     BitmapBuffer buff = new BitmapBuffer(bmp);
     buff.Lock();
     var noise = new Noise(Environment.TickCount);
     for (int y = 0; y < w; y++)
         for (int x = 0; x < h; x++)
         {
             uint color = 0x00ffffff;
             color |= (uint)(noise.GetNoise(x / (double)w * 2, y / (double)h * 2, 0) * 255) << 24;
             buff[x, y] = color;
         }
     buff.Unlock();
     return bmp;
 }
Esempio n. 3
0
        void AddNoiseAndBiome(TerrainTile[,] buff, Dictionary<MapPolygon, double> moist)
        {
            int w = buff.GetLength(0);
            int h = buff.GetLength(1);
            var elevationNoise = new Noise(rand.Next());
            var moistureNoise = new Noise(rand.Next());
            //var elevationNoise = PerlinNoise.GetPerlinNoise(rand.Next(), 256, 256, 2);
            //var moistureNoise = PerlinNoise.GetPerlinNoise(rand.Next(), 256, 256, 2);
            for (int y = 0; y < w; y++)
                for (int x = 0; x < h; x++)
                {
                    var tile = buff[x, y];
                    if (tile.PolygonId != -1)
                    {
                        var poly = map.Polygons[tile.PolygonId];

                        tile.Elevation = Math.Min(1, (float)(poly.DistanceToCoast + poly.DistanceToCoast *
                            elevationNoise.GetNoise(x * 128.0 / w, y * 128.0 / h, 0.3) * 0.01f) * 2);
                        if (tile.Elevation > 1) tile.Elevation = 1;
                        else if (tile.Elevation < 0) tile.Elevation = 0;
                        tile.Elevation = (float)Math.Pow(tile.Elevation, 1.5);

                        tile.Moisture = (float)(moist[poly] + moist[poly] *
                            moistureNoise.GetNoise(x * 128.0 / w, y * 128.0 / h, 0.3) * 0.01f);
                        if (tile.Moisture > 1) tile.Moisture = 1;
                        else if (tile.Moisture < 0) tile.Moisture = 0;
                    }

                    tile.Biome = GetBiome(tile);
                    var biomeGround = GetBiomeGround(tile.Biome);
                    if (biomeGround != 0)
                        tile.TileId = biomeGround;

                    buff[x, y] = tile;
                }
        }
Esempio n. 4
0
        public void RenderSetPiece(World world, IntPoint pos)
        {
            int[,] t = new int[33, 33];

            for (int x = 0; x < 33; x++)                    //Grassing
                for (int y = 0; y < 33; y++)
                {
                    if (Math.Abs(x - Size / 2) / (Size / 2.0) + rand.NextDouble() * 0.3 < 0.95 &&
                        Math.Abs(y - Size / 2) / (Size / 2.0) + rand.NextDouble() * 0.3 < 0.95)
                        t[x, y] = 1;
                }

            for (int x = 12; x < 21; x++)                   //Outer
                for (int y = 4; y < 29; y++)
                    t[x, y] = 2;
            t = SetPieces.rotateCW(t);
            for (int x = 12; x < 21; x++)
                for (int y = 4; y < 29; y++)
                    t[x, y] = 2;

            for (int x = 13; x < 20; x++)                   //Inner
                for (int y = 5; y < 28; y++)
                    t[x, y] = 4;
            t = SetPieces.rotateCW(t);
            for (int x = 13; x < 20; x++)
                for (int y = 5; y < 28; y++)
                    t[x, y] = 4;

            for (int i = 0; i < 4; i++)                     //Ext
            {
                for (int x = 13; x < 20; x++)
                    for (int y = 5; y < 7; y++)
                        t[x, y] = 3;
                t = SetPieces.rotateCW(t);
            }

            for (int i = 0; i < 4; i++)                     //Pillars
            {
                t[13, 7] = rand.Next() % 3 == 0 ? 6 : 5;
                t[19, 7] = rand.Next() % 3 == 0 ? 6 : 5;
                t[13, 10] = rand.Next() % 3 == 0 ? 6 : 5;
                t[19, 10] = rand.Next() % 3 == 0 ? 6 : 5;
                t = SetPieces.rotateCW(t);
            }

            Noise noise = new Noise(Environment.TickCount); //Perlin noise
            for (int x = 0; x < 33; x++)
                for (int y = 0; y < 33; y++)
                    if (noise.GetNoise(x / 33f * 8, y / 33f * 8, .5f) < 0.2)
                        t[x, y] = 0;

            for (int x = 0; x < 33; x++)                    //Rendering
                for (int y = 0; y < 33; y++)
                {
                    if (t[x, y] == 1)
                    {
                        var tile = world.Map[x + pos.X, y + pos.Y].Clone();
                        tile.TileId = Grass; tile.ObjType = 0;
                        world.Obstacles[x + pos.X, y + pos.Y] = 0;
                        world.Map[x + pos.X, y + pos.Y] = tile;
                    }
                    else if (t[x, y] == 2)
                    {
                        var tile = world.Map[x + pos.X, y + pos.Y].Clone();
                        tile.TileId = TileDark; tile.ObjType = 0;
                        world.Obstacles[x + pos.X, y + pos.Y] = 0;
                        world.Map[x + pos.X, y + pos.Y] = tile;
                    }
                    else if (t[x, y] == 3)
                    {
                        var tile = world.Map[x + pos.X, y + pos.Y].Clone();
                        tile.TileId = Tile; tile.ObjType = 0;
                        world.Obstacles[x + pos.X, y + pos.Y] = 0;
                        world.Map[x + pos.X, y + pos.Y] = tile;
                    }
                    else if (t[x, y] == 4)
                    {
                        var tile = world.Map[x + pos.X, y + pos.Y].Clone();
                        tile.TileId = Stone; tile.ObjType = 0;
                        world.Obstacles[x + pos.X, y + pos.Y] = 0;
                        world.Map[x + pos.X, y + pos.Y] = tile;
                    }
                    else if (t[x, y] == 5)
                    {
                        var tile = world.Map[x + pos.X, y + pos.Y].Clone();
                        tile.TileId = Stone; tile.ObjType = PillarA;
                        if (tile.ObjId == 0) tile.ObjId = world.GetNextEntityId();
                        world.Obstacles[x + pos.X, y + pos.Y] = 2;
                        world.Map[x + pos.X, y + pos.Y] = tile;
                    }
                    else if (t[x, y] == 6)
                    {
                        var tile = world.Map[x + pos.X, y + pos.Y].Clone();
                        tile.TileId = Stone; tile.ObjType = PillarB;
                        if (tile.ObjId == 0) tile.ObjId = world.GetNextEntityId();
                        world.Obstacles[x + pos.X, y + pos.Y] = 2;
                        world.Map[x + pos.X, y + pos.Y] = tile;
                    }
                }

            Entity skull = Entity.Resolve(0x0d56);          //Skulls!
            skull.Move(pos.X + Size / 2f, pos.Y + Size / 2f);
            world.EnterWorld(skull);
        }