public ManagerMap()
        {
            float[,] noise = Noise2D.GenerateNoiseMap(Warcraft.MAP_SIZE, Warcraft.MAP_SIZE, 20);

            for (int i = 0; i < Warcraft.MAP_SIZE; i++)
            {
                List <Tile> t = new List <Tile>();
                for (int j = 0; j < Warcraft.MAP_SIZE; j++)
                {
                    //if (noise[i, j] < 0.2f)
                    //    t.Add(new Tile(i, j, TileType.WATER));
                    //else if (noise[i, j] >= 0.2f && noise[i, j] < 0.4f)
                    //    t.Add(new Tile(i, j, TileType.DESERT));
                    //else if (noise[i, j] >= 0.4f && noise[i, j] < 0.8f)
                    //    t.Add(new Tile(i, j, TileType.GLASS));
                    //else if (noise[i, j] >= 0.8f)
                    //    t.Add(new Tile(i, j, TileType.FLOREST));
                    if (noise[i, j] < 0.5f)
                    {
                        t.Add(new Tile(i, j, TileType.GLASS));
                    }
                    else if (noise[i, j] >= 0.5f)
                    {
                        t.Add(new Tile(i, j, TileType.DESERT));
                    }
                }

                map.Add(t);
            }


            //Mapping.Add(new int[4] { (int)TileType.WATER, (int)TileType.DESERT, (int)TileType.WATER, (int)TileType.DESERT }, new int[2] { 7, 11 });
            //Mapping.Add(new int[4] { (int)TileType.DESERT, (int)TileType.GLASS, (int)TileType.GLASS, (int)TileType.GLASS }, new int[2] { 4, 14 });
            //Mapping.Add(new int[4] { (int)TileType.GLASS, (int)TileType.GLASS, (int)TileType.DESERT, (int)TileType.DESERT }, new int[2] { 9, 16 });

            //Mapping.Add(new int[4] { (int)TileType.WATER, (int)TileType.DESERT, (int)TileType.DESERT, (int)TileType.DESERT }, new int[2] { 17, 10 });
            //Mapping.Add(new int[4] { (int)TileType.DESERT, (int)TileType.WATER, (int)TileType.DESERT, (int)TileType.DESERT }, new int[2] { 18, 10 });
            //Mapping.Add(new int[4] { (int)TileType.DESERT, (int)TileType.DESERT, (int)TileType.DESERT, (int)TileType.GLASS }, new int[2] { 18, 14 });

            //Mapping.Add(new int[4] { (int)TileType.GLASS, (int)TileType.DESERT, (int)TileType.DESERT, (int)TileType.DESERT }, new int[2] { 14, 14 });

            //Mapping.Add(new int[4] { (int)TileType.GLASS, (int)TileType.FLOREST, (int)TileType.GLASS, (int)TileType.FLOREST }, new int[2] { 3, 7 });
            //Mapping.Add(new int[4] { (int)TileType.GLASS, (int)TileType.FLOREST, (int)TileType.FLOREST, (int)TileType.FLOREST }, new int[2] { 15, 14 });

            // OrganizeMap();
        }
Beispiel #2
0
        public void CreateInsland(int x, int y, int width, int height)
        {
            List <List <Tile> > map   = new List <List <Tile> >();
            List <List <int> >  match = new List <List <int> >();
            List <Tile>         walls = new List <Tile>();

            float[,] noise = Noise2D.GenerateNoiseMap(width, height, 20);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    float  distance_x = Math.Abs(i - width * 0.5f);
                    float  distance_y = Math.Abs(j - height * 0.5f);
                    double distance   = Math.Sqrt(distance_x * distance_x + distance_y * distance_y);

                    float  max_width = width * 0.4f;
                    double delta     = distance / max_width;
                    double gradient  = delta * delta;

                    noise[i, j] *= (float)Math.Max(0.0f, 1.0f - gradient);
                }
            }

            for (int i = 0; i < width; i++)
            {
                List <Tile> t = new List <Tile>();
                for (int j = 0; j < height; j++)
                {
                    if (noise[i, j] < 0.1f)
                    {
                        t.Add(new Tile(x + i, y + j, TileType.WATER));
                    }
                    else if (noise[i, j] >= 0.1f && noise[i, j] < 0.4f)
                    {
                        t.Add(new Tile(x + i, y + j, TileType.DESERT));
                    }
                    else if (noise[i, j] >= 0.4f && noise[i, j] < 0.9f)
                    {
                        t.Add(new Tile(x + i, y + j, TileType.GRASS));
                    }
                    else if (noise[i, j] >= 0.9f)
                    {
                        t.Add(new Tile(x + i, y + j, TileType.FLOREST));
                    }
                }

                map.Add(t);
            }


            for (int i = 1; i < width + 2; i++)
            {
                List <int> t = new List <int>();
                for (int j = 1; j < height + 2; j++)
                {
                    int X = Math.Min(i, width);
                    int Y = Math.Min(j, height);

                    t.Add((int)map[X - 1][Y - 1].tileType);
                }

                match.Add(t);
            }

            Dictionary <int[], int[]> matches = new Dictionary <int[], int[]>(new MyEqualityComparer());

            // Water to Desert
            matches.Add(new int[] { 0, 0, 0, 1 }, new int[] { 11, 11 });
            matches.Add(new int[] { 0, 0, 1, 0 }, new int[] { 0, 12 });
            matches.Add(new int[] { 0, 0, 1, 1 }, new int[] { 2, 11 });
            matches.Add(new int[] { 0, 1, 0, 0 }, new int[] { 5, 12 });
            matches.Add(new int[] { 0, 1, 0, 1 }, new int[] { 7, 11 });
            matches.Add(new int[] { 0, 1, 1, 0 }, new int[] { 14, 11 });
            matches.Add(new int[] { 0, 1, 1, 1 }, new int[] { 17, 10 });
            matches.Add(new int[] { 1, 0, 0, 0 }, new int[] { 6, 12 });
            matches.Add(new int[] { 1, 0, 0, 1 }, new int[] { 8, 12 });
            matches.Add(new int[] { 1, 0, 1, 0 }, new int[] { 16, 11 });
            matches.Add(new int[] { 1, 0, 1, 1 }, new int[] { 0, 11 });
            matches.Add(new int[] { 1, 1, 0, 0 }, new int[] { 2, 12 });
            matches.Add(new int[] { 1, 1, 0, 1 }, new int[] { 5, 11 });
            matches.Add(new int[] { 1, 1, 1, 0 }, new int[] { 12, 11 });
            // Desert to Grass
            matches.Add(new int[] { 1, 1, 1, 2 }, new int[] { 18, 14 });
            matches.Add(new int[] { 1, 1, 2, 1 }, new int[] { 7, 15 });
            matches.Add(new int[] { 1, 1, 2, 2 }, new int[] { 9, 14 });
            matches.Add(new int[] { 1, 2, 1, 1 }, new int[] { 11, 15 });
            matches.Add(new int[] { 1, 2, 1, 2 }, new int[] { 13, 14 });
            matches.Add(new int[] { 1, 2, 2, 1 }, new int[] { 3, 15 }); //
            matches.Add(new int[] { 1, 2, 2, 2 }, new int[] { 4, 14 });
            matches.Add(new int[] { 2, 1, 1, 1 }, new int[] { 13, 15 });
            matches.Add(new int[] { 2, 1, 1, 2 }, new int[] { 17, 14 });
            matches.Add(new int[] { 2, 1, 2, 1 }, new int[] { 5, 15 });
            matches.Add(new int[] { 2, 1, 2, 2 }, new int[] { 6, 14 });
            matches.Add(new int[] { 2, 2, 1, 1 }, new int[] { 8, 15 });
            matches.Add(new int[] { 2, 2, 1, 2 }, new int[] { 11, 14 });
            matches.Add(new int[] { 2, 2, 2, 1 }, new int[] { 0, 15 });
            // Grass to Florest
            matches.Add(new int[] { 2, 2, 2, 3 }, new int[] { 3, 7 });
            matches.Add(new int[] { 2, 2, 3, 2 }, new int[] { 18, 6 });
            matches.Add(new int[] { 2, 2, 3, 3 }, new int[] { 11, 5 }); //
            matches.Add(new int[] { 2, 3, 2, 2 }, new int[] { 16, 6 });
            matches.Add(new int[] { 2, 3, 2, 3 }, new int[] { 2, 7 });
            //matches.Add(new int[] { 2, 3, 3, 2 }, new int[] { 0, 0 }); //
            matches.Add(new int[] { 2, 3, 3, 3 }, new int[] { 10, 5 }); ////
            matches.Add(new int[] { 3, 2, 2, 2 }, new int[] { 15, 6 }); //
                                                                        //matches.Add(new int[] { 3, 2, 2, 3 }, new int[] { 0, 0 });
            matches.Add(new int[] { 3, 2, 3, 2 }, new int[] { 0, 7 });
            //matches.Add(new int[] { 3, 2, 3, 3 }, new int[] { 12, 5 });
            matches.Add(new int[] { 3, 3, 2, 2 }, new int[] { 10, 6 });
            matches.Add(new int[] { 3, 3, 2, 3 }, new int[] { 13, 5 });//
            matches.Add(new int[] { 3, 3, 3, 2 }, new int[] { 0, 6 });

            for (int i = 0; i < match.Count - 1; i++)
            {
                for (int j = 0; j < match[i].Count - 1; j++)
                {
                    int[] key = { match[i][j], match[i + 1][j], match[i][j + 1], match[i + 1][j + 1] };
                    for (int k = 0; k < matches.Count; k++)
                    {
                        if (matches.ContainsKey(key))
                        {
                            map[i][j].ChangeTexture(matches[key][0], matches[key][1]);
                            break;
                        }
                    }

                    if (key[0] == 0 || key[1] == 0 || key[2] == 0 || key[3] == 0)                     //  || key[0] == 3 || key[1] == 3 || key[2] == 3 || key[3] == 3
                    {
                        water.Add(new Tile(i, j));
                    }
                }
            }

            //for (int i = 0; i < water.Count; i++)
            //{
            //    water[i].isWater = true;
            //    walls.Add(water[i]);
            //}

            //       for (int i = map.Count - 1; i >= 0; i--)
            //       {
            //           for (int j = map[i].Count - 1; j >= 0; j--)
            //           {
            //for (int k = 0; k < water.Count; k++)
            //{
            //if (i == water[k].TileX && j == water[k].TileY)
            //            {
            //                map[i].RemoveAt(j);
            //            }
            //        }
            //    }
            //}

            FULL_MAP = map;
            WALLS    = walls;
        }