示例#1
0
    public TileInfo GetTileInfoAtPoint(MocVector2int chunk, MocVector3int point)
    {
        float perlin = perlinAtPoint(point);

        if (!tileInfo[chunk].ContainsKey(point))
        {
            if (perlin < 0.35f)
            {
                TileInfo ti = new TileInfo
                {
                    isWater = true
                };
                tileInfo[chunk].Add(point, ti);
            }
            else if (perlin > 0.35f && perlin <= 0.4f)
            {
                TileInfo ti = new TileInfo
                {
                    isWalkableWater = true
                };
                tileInfo[chunk].Add(point, ti);
            }
            else if (perlin > 0.4f && perlin <= 0.8f)
            {
                TileInfo ti = new TileInfo
                {
                    isGrass = true
                };
                tileInfo[chunk].Add(point, ti);
            }
        }
        return(tileInfo[chunk][point]);
    }
示例#2
0
    void DrawChunk(int chunkSize, float scale, float seed, MocVector2int chunk)
    {
        if (!drawnChunks.ContainsKey(chunk) || !drawnChunks[chunk])
        {
            drawnChunks.Add(chunk, true);
            if (tileInfo.ContainsKey(chunk))
            {
                for (int y = chunk.y; y < chunkSize + chunk.y; y++)
                {
                    for (int x = chunk.x; x < chunkSize + chunk.x; x++)
                    {
                        Vector3Int point  = new Vector3Int(x, y, 0);
                        float      xF     = (((float)x + seed) / (float)chunkSize * scale);
                        float      yF     = ((float)y / (float)chunkSize * scale);
                        float      perlin = Mathf.PerlinNoise(xF, yF);


                        LoadTileWithPerlin(perlin, point);
                        //Debug.Log(tileInfo[chunk].Keys);
                        if (tileInfo[chunk].ContainsKey(point))
                        {
                            LoadTile(chunk, point, tileInfo[chunk][point].tileName);
                        }
                    }
                }
            }
            else
            {
                tileInfo.Add(chunk, new Dictionary <MocVector3int, TileInfo>());
                for (int y = chunk.y; y < chunkSize + chunk.y; y++)
                {
                    for (int x = chunk.x; x < chunkSize + chunk.x; x++)
                    {
                        //issue here, points saving to the rw
                        Vector3Int point  = new Vector3Int(x, y, 0);
                        float      xF     = (((float)x + seed) / (float)chunkSize * scale);
                        float      yF     = ((float)y / (float)chunkSize * scale);
                        float      perlin = Mathf.PerlinNoise(xF, yF);

                        //add initial placement here
                        PlaceTileWithPerlin(perlin, chunk, point);
                    }
                }
            }
        }
    }