예제 #1
0
    // Use this for initialization
    void Start()
    {
        MapGenerator = FindObjectOfType <MapGeneratorBehaviour> ();

        //fetch the chuncksize from the MapGenerator
        chunkSize = MapGeneratorBehaviour.MAP_CHUNK_SIZE - 1;                      // 241 but the actual size is 240 x 240
        chunksVisibleInViewDistance = Mathf.RoundToInt(MAX_VIEW_DIST / chunkSize); //the number of chuncks is an integer
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        MapGenerator = FindObjectOfType <MapGeneratorBehaviour> ();

        MaxViewDist = DetailLevels [DetailLevels.Length - 1].visibleDistanceThreshold;

        //fetch the chuncksize from the MapGenerator
        chunkSize = MapGeneratorBehaviour.MAP_CHUNK_SIZE - 1;                    // 241 but the actual size is 240 x 240
        chunksVisibleInViewDistance = Mathf.RoundToInt(MaxViewDist / chunkSize); //the number of chuncks is an integer
        UpdateVisibleChunks();                                                   //since the condition(2) may not be evaluate to true at the start
    }
예제 #3
0
    public override void OnInspectorGUI()
    {
        MapGeneratorBehaviour mapGen = (MapGeneratorBehaviour)target;

        if (DrawDefaultInspector())
        {
            if (mapGen.AutoUpdate)
            {
                mapGen.GenerateMap();
            }
        }

        if (GUILayout.Button("Generate"))
        {
            mapGen.GenerateMap();
        }
    }
예제 #4
0
 private void Awake()
 {
     instance = this;
 }
    /**
     * Get the id based on its position
     * @return int id
     */
    public virtual int GetID()
    {
        Vector3 position = this.tile.GetPosition();
        int     x        = Mathf.RoundToInt(position.x);
        int     z        = Mathf.RoundToInt(position.z);

        Tile topLeftTile     = MapGeneratorBehaviour.IsTileExists(x - 1, z + 1) ? MapGeneratorBehaviour.Tiles[x - 1][z + 1].GetComponent <TileBehaviour>().GetTile() : null;
        Tile topTile         = MapGeneratorBehaviour.IsTileExists(x, z + 1) ? MapGeneratorBehaviour.Tiles[x][z + 1].GetComponent <TileBehaviour>().GetTile() : null;
        Tile topRightTile    = MapGeneratorBehaviour.IsTileExists(x + 1, z + 1) ? MapGeneratorBehaviour.Tiles[x + 1][z + 1].GetComponent <TileBehaviour>().GetTile() : null;
        Tile leftTile        = MapGeneratorBehaviour.IsTileExists(x - 1, z) ? MapGeneratorBehaviour.Tiles[x - 1][z].GetComponent <TileBehaviour>().GetTile() : null;
        Tile rightTile       = MapGeneratorBehaviour.IsTileExists(x + 1, z) ? MapGeneratorBehaviour.Tiles[x + 1][z].GetComponent <TileBehaviour>().GetTile() : null;
        Tile bottomLeftTile  = MapGeneratorBehaviour.IsTileExists(x - 1, z - 1) ? MapGeneratorBehaviour.Tiles[x - 1][z - 1].GetComponent <TileBehaviour>().GetTile() : null;
        Tile bottomTile      = MapGeneratorBehaviour.IsTileExists(x, z - 1) ? MapGeneratorBehaviour.Tiles[x][z - 1].GetComponent <TileBehaviour>().GetTile() : null;
        Tile bottomRightTile = MapGeneratorBehaviour.IsTileExists(x + 1, z - 1) ? MapGeneratorBehaviour.Tiles[x + 1][z - 1].GetComponent <TileBehaviour>().GetTile() : null;

        // 8-bit binary
        Char[] binary = new char[8];

        // check top left
        if (topLeftTile != null && topLeftTile.GetType() == TileType.Water)
        {
            binary[7] = '1';
        }
        else
        {
            binary[7] = '0';
        }

        // check top tile
        if (topTile != null && topTile.GetType() == TileType.Water)
        {
            binary[6] = '1';
        }
        else
        {
            binary[6] = '0';
        }

        // check top tile
        if (topRightTile != null && topRightTile.GetType() == TileType.Water)
        {
            binary[5] = '1';
        }
        else
        {
            binary[5] = '0';
        }

        // check left tile
        if (leftTile != null && leftTile.GetType() == TileType.Water)
        {
            binary[4] = '1';
        }
        else
        {
            binary[4] = '0';
        }

        // check right tile
        if (rightTile != null && rightTile.GetType() == TileType.Water)
        {
            binary[3] = '1';
        }
        else
        {
            binary[3] = '0';
        }

        // check bottom left tile
        if (bottomLeftTile != null && bottomLeftTile.GetType() == TileType.Water)
        {
            binary[2] = '1';
        }
        else
        {
            binary[2] = '0';
        }

        // check bottom left tile
        if (bottomTile != null && bottomTile.GetType() == TileType.Water)
        {
            binary[1] = '1';
        }
        else
        {
            binary[1] = '0';
        }

        // check bottom right tile
        if (bottomRightTile != null && bottomRightTile.GetType() == TileType.Water)
        {
            binary[0] = '1';
        }
        else
        {
            binary[0] = '0';
        }

        // Convert binary to int
        int value = (int)TileID.Center;

        int start = 0;

        for (int i = binary.Length - 1; i > -1; i--)
        {
            if (binary[i].Equals('1'))
            {
                value = value + (int)Math.Pow(2, start);
            }

            start = start + 1;
        }

        Debug.Log(value);


        return(value);
    }
 private void Awake()
 {
     instance       = this;
     tileAmountHalf = tileAmount / 2;
 }