Пример #1
0
    private void GenerateGrid(int gridDimensions, float chunkSize)
    {
        _gridLevel.gridDimensions = gridDimensions;
        _gridLevel.chunkSize      = chunkSize;
        _gridLevel.chunkPrefabs   = chunkPrefabs;
        _gridLevel.comptoirPrefab = comptoirPrefab;

        int comptoirI = Random.Range(0, gridDimensions);
        int comptoirJ = Random.Range(0, gridDimensions);

        int letterID = 0;

        for (int j = gridDimensions - 1; j >= 0; j--)
        {
            for (int i = 0; i < gridDimensions; i++)
            {
                Vector3 position = new Vector3(chunkSize * i, 0, chunkSize * j);

                GameObject go = null;
                if (i == comptoirI && j == comptoirJ)
                {
                    go = Instantiate(comptoirPrefab, position, Quaternion.identity);
                    go.GetComponent <RoomChunk>().comptoir = true;
                    _gridLevel.comptoirCoordinates         = new Vector2(i, j);
                }
                else
                {
                    go = Instantiate(chunkPrefabs[Random.Range(0, chunkPrefabs.Length)], position, Quaternion.identity);
                }

                RoomChunk chunk = go.GetComponent <RoomChunk>();

                Vector2 gridCoords = new Vector2(i, j);
                chunk.level      = _gridLevel;
                chunk.gridCoords = gridCoords;
                chunk.SetLetterID(letterID++);

                _gridLevel.chunks.Add(gridCoords, chunk);
            }
        }

        _gridLevel.OnLevelGenerated();
    }
Пример #2
0
    private void AddChunkAtRandom()
    {
        bool    horizontal      = true;
        bool    positive        = false;
        bool    replaceComptoir = false;
        int     letterID        = 0;
        Vector2 spawnPosition   = GetRandomSpawnPosition(ref horizontal);

        if (horizontal)
        {
            positive = spawnPosition.x > 0 ? true : false;

            if (positive)
            {
                if (comptoirCoordinates == new Vector2(0, spawnPosition.y))
                {
                    replaceComptoir = true;
                }

                letterID = chunks[new Vector2(0, spawnPosition.y)].letterID;
            }
            else
            {
                if (comptoirCoordinates == new Vector2(gridDimensions - 1, spawnPosition.y))
                {
                    replaceComptoir = true;
                }

                letterID = chunks[new Vector2(gridDimensions - 1, spawnPosition.y)].letterID;
            }
        }
        else
        {
            positive = spawnPosition.y > 0 ? true : false;

            if (positive)
            {
                if (comptoirCoordinates == new Vector2(spawnPosition.x, 0))
                {
                    replaceComptoir = true;
                }

                letterID = chunks[new Vector2(spawnPosition.x, 0)].letterID;
            }
            else
            {
                if (comptoirCoordinates == new Vector2(spawnPosition.x, gridDimensions - 1))
                {
                    replaceComptoir = true;
                }

                letterID = chunks[new Vector2(spawnPosition.x, gridDimensions - 1)].letterID;
            }
        }

        RoomChunk chunk = default;

        if (replaceComptoir)
        {
            chunk = ReplaceComptoir(spawnPosition);
        }
        else
        {
            chunk = GetNewChunk(spawnPosition);
        }

        chunk.SetLetterID(letterID);

        MoveRow(chunk, horizontal, positive);
    }