Ejemplo n.º 1
0
 public TileMap(string name, int w, int h, string[] objects, int initialHeight)
 {
     Tag        = "#map";
     Name       = name;
     int[,] map = NoiseMap.GetNotSmoothedNoise(w, h, initialHeight + 1);
     map        = map.MeanBlur(5);
     map        = map.ChangeVariance(objects.Length - 1);
     array      = new DirectionalCollisionObject[h, w];
     for (int y = 0; y < h; y++)
     {
         for (int x = 0; x < w; x++)
         {
             array[y, x] = new DirectionalCollisionObject($"#|{map[y,x]}|WALLtile@{y}-{x}", new Position(x * TileSize, y * TileSize), objects[map[y, x]]);
             array[y, x].AutoFitCollider = true;
             array[y, x].WrapInCollider(true);
         }
     }
 }
Ejemplo n.º 2
0
        public static Bitmap ToBitmap(this int[,] map, Gradient grad)
        {
            Bitmap ret = new Bitmap(map.GetLength(1), map.GetLength(0));

            map.ChangeVariance(255);
            for (int y = 0; y < ret.Height; y++)
            {
                for (int x = 0; x < ret.Width; x++)
                {
                    int c = map[y, x];
                    if (c < 0)
                    {
                        ret.SetPixel(x, y, grad.ColorAt(0));
                        continue;
                    }
                    ret.SetPixel(x, y, grad.ColorAt(c));
                }
            }
            return(ret);
        }
Ejemplo n.º 3
0
        public static Bitmap ToBitmap(this int[,] map)
        {
            Bitmap ret = new Bitmap(map.GetLength(1), map.GetLength(0));

            map.ChangeVariance(255);
            for (int y = 0; y < ret.Height; y++)
            {
                for (int x = 0; x < ret.Width; x++)
                {
                    int c = map[y, x];
                    if (c < 0)
                    {
                        ret.SetPixel(x, y, Color.Black);
                        continue;
                    }
                    ret.SetPixel(x, y, Color.FromArgb(c, c, c));
                }
            }
            return(ret);
        }
Ejemplo n.º 4
0
        public static string[,] GetChunk()
        {
            ChunksGenerated += 1;
            Log.Write($"Generating map chunk #{ChunksGenerated} ...");
            string[,] ret = new string[ChunkSize, ChunkSize];
            int[,] water  = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 100);
            water         = water.MeanBlur(10).MeanBlur(10).MeanBlur(10);
            water         = water.ChangeVariance(110);
            Log.Write("Generated water.");

            int[,] iron = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            iron        = iron.MedianBlur(10).MedianBlur(10).MeanBlur(10);
            iron        = iron.ChangeVariance(110);
            Log.Write("Generated iron.");

            int[,] copper = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            copper        = copper.MedianBlur(10).MedianBlur(10).MeanBlur(10);
            copper        = copper.ChangeVariance(110);
            Log.Write("Generated copper.");

            int[,] stone = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            stone        = stone.MeanBlur(10).MedianBlur(10).MedianBlur(10);
            stone        = stone.ChangeVariance(110);
            Log.Write("Generated stone.");

            int[,] crystal = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            crystal        = crystal.MeanBlur(10).MedianBlur(10).MedianBlur(10);
            crystal        = crystal.ChangeVariance(110);
            Log.Write("Generated crystal.");
            Log.Write("Writing chunk ...");
            for (int y = 0; y < ChunkSize; y++)
            {
                for (int x = 0; x < ChunkSize; x++)
                {
                    // make order:
                    // - stone
                    // - coal
                    // - iron/copper ( random if overlap )
                    // - crystal
                    // - water

                    int    w  = water[y, x];
                    int    i  = iron[y, x];
                    int    p  = copper[y, x];
                    int    s  = stone[y, x];
                    int    c  = crystal[y, x];
                    string ps = $"{x},{y}";
                    int    v  = _r.Next(MinimumRichness * ChunksGenerated, MaximumRichness * ChunksGenerated);
                    if (w >= WaterLevel)
                    {
                        ret[y, x] = "|~~~|";
                        Program.AddMapResource(ps, new Resource("Normal Water", _water, ResourceType.Water, 9999999));
                    }
                    else if (c >= CrystalLevel)
                    {
                        ret[y, x] = "|ccc|";
                        Program.AddMapResource(ps, new Resource("Crystal Vein", _crystal, ResourceType.Crystal, v));
                    }
                    else if (i >= IronLevel && _priority == 0)
                    {
                        ret[y, x] = "|iii|";
                        Program.AddMapResource(ps, new Resource("Iron Vein", _iron, ResourceType.Iron, v));
                        _priority = 1;
                    }
                    else if (p >= CopperLevel && _priority == 1)
                    {
                        ret[y, x] = "|ppp|";
                        Program.AddMapResource(ps, new Resource("Copper Vein", _copper, ResourceType.Copper, v));
                        _priority = 0;
                    }
                    else if (p >= CopperLevel && _priority == 0)
                    {
                        ret[y, x] = "|ppp|";
                        Program.AddMapResource(ps, new Resource("Copper Vein", _copper, ResourceType.Copper, v));
                        _priority = 1;
                    }
                    else if (i >= IronLevel && _priority == 1)
                    {
                        ret[y, x] = "|iii|";
                        Program.AddMapResource(ps, new Resource("Iron Vein", _iron, ResourceType.Iron, v));
                        _priority = 0;
                    }
                    else if (s >= StoneLevel)
                    {
                        ret[y, x] = "|sss|";
                        Program.AddMapResource(ps, new Resource("Stone Vein", _stone, ResourceType.Stone, v));
                    }
                    else
                    {
                        ret[y, x] = " ";
                    }
                }
            }
            Log.Write("Finished writing chunk.");
            return(ret);
        }