public void CreateContinents()
    {
        while (true)
        {
            Vector2 center         = new Vector2((int)Random.Range(worldWidth * 0.1f, worldWidth * 0.9f), (int)Random.Range(worldHeight * .15f, worldHeight * .85f));
            int     centerTectonic = Points[center].plateNumber;
            if (Plates.First(p => p.plateNumber == centerTectonic).oceanic)
            {
                continue;
            }
            int contSize = Random.Range(5, 8);
            Dictionary <Vector2, bool> newContinentMap = new ZoomLandCreation(contSize, contSize).Create(3);

            bool ContinentalCollision = Random.Range(0, 10) == 0;
            foreach (Vector2 v in newContinentMap.Keys)
            {
                Vector2 worldMapPos = GetWorldMapPos(center + v - new Vector2(13, 13));
                if (!Points.ContainsKey(worldMapPos))
                {
                    continue;//offmap
                }
                if (newContinentMap[v] && (Points[worldMapPos].plateNumber == centerTectonic || ContinentalCollision))
                {
                    Points[worldMapPos].height = 5;
                }
            }
            float land  = Points.Values.Count(p => p.height == 5);
            float ocean = Points.Count - land;
            Debug.Log(land / ocean);
            if (land / ocean > 0.29f)
            {
                break;
            }
        }
        foreach (Plate plate in Plates)
        {
            List <EarthPoint> platePoints = Points.Values.Where(p => p.plateNumber == plate.plateNumber).ToList();
            if (platePoints.Count(p => p.land) == 0)
            {
                plate.oceanic = true;
            }
        }
        foreach (EarthPoint ep in Points.Values.Where(p => p.land))
        {
            List <EarthPoint> neigh = Neighbors(ep.pos);
            if (neigh.Any(p => !p.land))
            {
                ep.coast = true;
            }
        }
    }
Ejemplo n.º 2
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.º 3
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);
            }
        }