Example #1
0
    // Basic land mass generation
    void GenerateLandMass()
    {
        if (waterThreshold == 0)
        {
            waterThreshold = Random.Range(0.0001f, 1);
        }

        for (int i = 0; i < cells.Count; i++)
        {
            MapCell cell = cells[i];

            var x      = cell.Position.x * Random.Range(0, 9999);
            var y      = cell.Position.y * Random.Range(0, 9999);
            var perlin = Mathf.PerlinNoise(x, y);
            Debug.Log(perlin);
            if (perlin < waterThreshold)
            {
                cell.SetBiome(Biomes.GetBiome("Ocean"));
            }
            else
            {
                cell.SetBiome(Biomes.GetBiome("Grasslands"));
            }
        }
    }
Example #2
0
    public IEnumerator TestaTileSet()
    {
        // TileSet tileSet = holder.tileSet;
        // Biomes biomes = holder.biomes;
        //Assert.IsNotNull(biomes);

        Biomes biomes = new Biomes();
        Biome  biome  = new Biome(biomes);

        //TileSet tileSet = biome.tileSet;

        biomes.AddBiome("Tropical", biome);
        Assert.IsTrue(biomes.GetBiome("Tropical") == biome);
        Biome biomeTest = biomes.GetBiome("Tropical");

        Assert.IsNotNull(biomeTest);
        Biome biomeTestNull = biomes.GetBiome("Tropical!!!");

        Assert.IsNull(biomeTestNull);
        Assert.IsTrue(biomeTest == biome);

        Tile tile = world.GetTileAt(0, 0, 0);

        Assert.IsNotNull(tile);

        // TileType TileTypeGround = new TileType();


        biome = world.biome;
        Assert.IsNotNull(biome);
        //  Assert.IsNotNull(biome.TileType);

        /* TileType td = biome.GetTileWithTag(GameConsts.TAG_TILE_TEST);
         * Assert.IsTrue(td.name=="test");
         * Assert.IsTrue(td.fileName == "ISO_Tile_Water_Block");
         * Assert.IsTrue(td.MovementCost == 0.51f);
         * Assert.IsTrue(td.MinHeight == 0);
         * Assert.IsTrue(td.MaxHeight == 0.5f);*/

        yield return(null);
    }
Example #3
0
    //
    public void GenerateMap()
    {
        float[,] noise = GenerateNoiseMap(voronoi.mapWidth, voronoi.mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset);

        for (int i = 0; i < cells.Count; i++)
        {
            MapCell cell   = cells[i];
            int     x      = (int)cell.Position.x;
            int     y      = (int)cell.Position.y;
            float   height = noise[x, y];

            if (height < waterThreshold)
            {
                cell.SetBiome(Biomes.GetBiome("Ocean"));
            }
            else
            {
                cell.SetBiome(Biomes.GetBiome("Grasslands"));
            }
        }
    }
    void Draw()
    {
        texture = new Texture2D(mapWidth, mapHeight);
        cells   = new List <MapCell>();
        Debug.Log(map_points.Count);
        for (int i = 0; i < map_points.Count; i++)
        {
            Vector2 site = map_points[i];
            MapCell cell = new MapCell
            {
                Position   = site,
                edges      = new List <MapEdge>(),
                neighbours = voronoi.NeighborSitesForSite(site),
                ID         = i,
            };
            //cell.isBorder = IsBorder(voronoi.VoronoiBoundaryForSite(site));
            cell.isBorder = HullContainsSite(site);



            foreach (LineSegment segment in voronoi.VoronoiBoundaryForSite(site))
            {
                cell.edges.Add(new MapEdge(segment.P0, segment.P1));
            }


            // Paint edges
            for (int j = 0; j < cell.edges.Count; j++)
            {
                MapEdge        edge   = cell.edges[j];
                List <Vector2> points = new List <Vector2>
                {
                    edge.p0,
                    edge.p1
                };
                Vector2 p0 = points[0];
                Vector2 p1 = points[1];

                int distance = (int)Mathf.Abs(Vector2.Distance(p0, p1));
                for (int k = 0; k <= distance; k++)
                {
                    Vector2 temp = p1 - p0;
                    temp.Normalize();
                    Vector2 pos = k * temp + p0;

                    int x;
                    int y;

                    if ((int)pos.x >= mapWidth)
                    {
                        x = ((int)pos.x) - 1;
                    }
                    else
                    {
                        x = (int)pos.x;
                    }

                    if ((int)pos.y >= mapHeight)
                    {
                        y = ((int)pos.y) - 1;
                    }
                    else
                    {
                        y = (int)pos.y;
                    }

                    texture.SetPixel(x, y, borderColour);
                }
            }

            //Fill Center
            //Temporary fill to have land and water

            int tempx = (int)site.x; int tempy = (int)site.y;
            if (cell.isBorder)
            {
                cell.biome = Biomes.GetBiome("Ocean");
                texture.FloodFillBorder(tempx, tempy, cell.biome.biomeColour, borderColour);
                continue;
            }


            float[,] noiseLayer = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, NOISE_SCALE, OCTAVES, PERSISTANCE, LACUNARITY, new Vector2(0, 0));

            if (noiseLayer[tempx, tempy] > waterThreshold)
            {
                cell.biome = Biomes.GetBiome("Grasslands");
                texture.FloodFillBorder(tempx, tempy, cell.biome.biomeColour, borderColour);
            }

            else
            {
                cell.biome = Biomes.GetBiome("Ocean");
                texture.FloodFillBorder(tempx, tempy, cell.biome.biomeColour, borderColour);
            }
        }
        texture.Apply();
        plane.GetComponent <MeshRenderer>().sharedMaterial.mainTexture = texture;
    }