Ejemplo n.º 1
0
        public void CreateContinents()
        {
            int Ocean = WorldPointContinents.Count;
            int Land  = 0;

            //for (int i = 0; i < 7; i++)
            while (true)
            {
                Continent cont = new Continent(new WorldPointContinent(new Vector2(Random.Range(0, Width), Random.Range(0, Height))));
                Continents.Add(cont);
                Dictionary <Vector2, bool> Map = new ZoomLandCreation(5, 5).Create(3);
                int            width           = (int)Map.Select(p => p.Key.x).Max() / (int)2;
                List <Vector2> LandPoints      = new List <Vector2>();
                foreach (var pair in Map)
                {
                    if (pair.Value)
                    {
                        LandPoints.Add(pair.Key);
                    }
                }
                foreach (var p in LandPoints)
                {
                    ContinentPoint cp = new ContinentPoint(p - new Vector2(width, width), cont);
                    if (cont.Points.ContainsKey(p - new Vector2(width, width)))
                    {
                        continue;
                    }
                    cont.Points.Add(p - new Vector2(width, width), cp);
                    WorldPointContinent wp = cont.ContinentPointToWorldPoint(cp, this);
                    if (wp != null && wp.contPoint == null)
                    {
                        wp.contPoint = cp;
                        Land++;
                        Ocean--;
                    }
                }
                if ((float)Land / (float)(Ocean + Land) > 0.3f)
                {
                    break;
                }
            }
            foreach (WorldPointContinent wp in WorldPointContinents.Values)
            {
                GameObject go = Instantiate(cubePrefab);
                go.transform.position = wp.Pos;
                go.GetComponent <MeshRenderer>().material       = Resources.Load <Material>("green");
                go.GetComponent <MeshRenderer>().material.color = wp.contPoint == null ? Color.blue : Color.green;
                wp.go = go;
            }
        }
Ejemplo n.º 2
0
        public void CreateContinents()
        {
            List <Vector2> ContinentPoints = new List <Vector2>()
            {
                new Vector2(30, 30), new Vector2(51, 65), new Vector2(106, 53), new Vector2(106, 23), new Vector2(140, 34), new Vector2(138, 74)
            };

            for (int i = 0; i < 6; i++)
            {
                Continent cont = new Continent(new WorldPointContinent(new Vector2(ContinentPoints[i].x, Height - ContinentPoints[i].y)));
                Continents.Add(cont);
                Dictionary <Vector2, bool> Map = new Dictionary <Vector2, bool>();
                while (Map.Count < 2300)
                {
                    Map = new ZoomLandCreation(5, 5).Create(4);
                }
                int            width      = (int)Map.Select(p => p.Key.x).Max() / (int)2;
                List <Vector2> LandPoints = new List <Vector2>();
                foreach (var pair in Map)
                {
                    if (pair.Value)
                    {
                        LandPoints.Add(pair.Key);
                    }
                }
                foreach (var p in LandPoints)
                {
                    ContinentPoint cp = new ContinentPoint(p - new Vector2(width, width), cont);
                    if (cont.Points.ContainsKey(p - new Vector2(width, width)))
                    {
                        continue;
                    }
                    cont.Points.Add(p - new Vector2(width, width), cp);
                    WorldPointContinent wp = cont.ContinentPointToWorldPoint(cp, this);
                    if (wp != null && wp.contPoint == null)
                    {
                        wp.contPoint = cp;
                    }
                }
            }
            foreach (WorldPointContinent wp in WorldPointContinents.Values)
            {
                GameObject go = Instantiate(cubePrefab);
                go.transform.position = wp.Pos;
                go.GetComponent <MeshRenderer>().material       = Resources.Load <Material>("green");
                go.GetComponent <MeshRenderer>().material.color = wp.contPoint == null ? Color.blue : Color.green;
                wp.go = go;
                gos.Add(go);
            }
        }