コード例 #1
0
        public override void Generate(BoardGenerator boardGenerator)
        {
            GridPosition startPos = null;

            if (useRandomTunnelStartPositions)
            {
                startPos = boardGenerator.GetRandomGridPosition();

                for (int i = 0; i < numTunnels; i++)
                {
                    GridPosition randomGoalPosition = boardGenerator.GetRandomGridPosition();
                    if (spawnRoomsAtTunnelEnds)
                    {
                        SpawnRoomTemplateAtTunnelEnd(boardGenerator, randomGoalPosition);
                    }
                    DigTunnel(boardGenerator, startPos, randomGoalPosition);
                }
            }
            else if (connectLastStrataLayer)
            {
                List <GridPosition> goalPositions = BuildTunnelGoalList(boardGenerator);


                for (int i = 0; i < goalPositions.Count; i++)
                {
                    startPos = goalPositions[i];
                    int          loopingGoalPositionIndex = ((i + 1) % goalPositions.Count);
                    GridPosition targetPosition           = goalPositions[loopingGoalPositionIndex];
                    DigTunnel(boardGenerator, startPos, targetPosition);
                }
            }
        }
コード例 #2
0
ファイル: EnemyGeneration.cs プロジェクト: jk0524/gameDev
 // Use this for initialization
 void Start()
 {
     counter = waveRate;
     num     = 10;
     board   = gameObject.GetComponent <BoardGenerator>();
     tile    = board.GetComponent <Tilemap>();
     //Debug.Log(board);
     for (int i = 0; i < num; i++)
     {
         Vector2 pos = board.GridPositionToVector2(board.GetRandomGridPosition());
         //Debug.Log(pos);
         Vector3Int p = new Vector3Int((int)(pos.x + 2), (int)pos.y + 2, 0);
         //tile.SetColor(p, Color.red);
         //Debug.Log(tile.GetColor(p));
         Instantiate(enemy, p, Quaternion.identity);
     }
     for (int i = 0; i < 5; i++)
     {
         Vector2 pos = board.GridPositionToVector2(board.GetRandomGridPosition());
         //Debug.Log(pos);
         Vector3Int p = new Vector3Int((int)(pos.x + 2), (int)pos.y + 2, 0);
         //tile.SetColor(p, Color.red);
         //Debug.Log(tile.GetColor(p));
         Instantiate(powerpotion, p, Quaternion.identity);
     }
 }
コード例 #3
0
        int GetSurroundingWallCount(int gridX, int gridY, BoardGenerator boardGenerator)
        {
            int wallCount = 0;

            for (int neighbourX = gridX - 1; neighbourX <= gridX + 1; neighbourX++)
            {
                for (int neighbourY = gridY - 1; neighbourY <= gridY + 1; neighbourY++)
                {
                    if (neighbourX >= 0 && neighbourX < boardGenerator.boardGenerationProfile.boardHorizontalSize && neighbourY >= 0 && neighbourY < boardGenerator.boardGenerationProfile.boardVerticalSize)
                    {
                        if (neighbourX != gridX || neighbourY != gridY)
                        {
                            if (boardGenerator.boardGridAsCharacters[neighbourX, neighbourY] == charForFill)
                            {
                                wallCount++;
                            }
                        }
                    }
                    else
                    {
                        wallCount++;
                    }
                }
            }

            return(wallCount);
        }
コード例 #4
0
 void SpawnRoomTemplateAtTunnelEnd(BoardGenerator boardGenerator, GridPosition spawnPosition)
 {
     if (tunnelEndTemplates.Length > 0)
     {
         RoomTemplate templateToSpawn = tunnelEndTemplates[Random.Range(0, tunnelEndTemplates.Length)];
         boardGenerator.DrawTemplate(spawnPosition.x, spawnPosition.y, templateToSpawn, overwriteFilledSpaces, true);
     }
 }
コード例 #5
0
 void GenerateMap(BoardGenerator boardGenerator)
 {
     RandomFillMap(boardGenerator);
     for (int i = 0; i < 5; i++)
     {
         SmoothMap(boardGenerator);
     }
 }
コード例 #6
0
 public override void Generate(BoardGenerator boardGenerator)
 {
     if (useLibraryDefaultEmptyCharForEmptySpace)
     {
         emptySpaceChar = boardGenerator.boardGenerationProfile.boardLibrary.GetDefaultEmptyChar();
     }
     GenerateMap(boardGenerator);
 }
コード例 #7
0
 void RandomFillMap(BoardGenerator boardGenerator)
 {
     for (int x = 0; x < boardGenerator.boardGenerationProfile.boardHorizontalSize; x++)
     {
         for (int y = 0; y < boardGenerator.boardGenerationProfile.boardVerticalSize; y++)
         {
             boardGenerator.WriteToBoardGrid(x, y, (Random.Range(0, 100) < randomFillPercent) ? charForFill : emptySpaceChar, overwriteFilledSpaces, false);
         }
     }
 }
コード例 #8
0
        //public GameObject room = GameObject.Find("Room");

        // Use this for initialization
        void Start()
        {
            board = gameObject.GetComponent <BoardGenerator>();
            Debug.Log(board.name);
            GridPosition doory = board.GetRandomGridPosition();
            Vector2      testy = new Vector2(5, 5);
            Vector2      pos   = board.GetDoorPos();

            Debug.Log(pos);
            Instantiate(door, pos, Quaternion.identity);
        }
コード例 #9
0
        private RoomChain SetupRoomChainComponent(BoardGenerator boardGenerator)
        {
            GameObject oldRoomChain = GameObject.Find("RoomChainHolder");

            if (oldRoomChain != null)
            {
                DestroyImmediate(oldRoomChain);
            }
            RoomChain roomChainComponent = new GameObject("RoomChainHolder").AddComponent <RoomChain>();

            return(roomChainComponent);
        }
コード例 #10
0
        public void DigTunnel(BoardGenerator boardGenerator, GridPosition startPosition, GridPosition tunnelGoal)
        {
            GridPosition currentDigPosition = startPosition;

            for (int i = 0; i < maxLengthPerTunnel; i++)
            {
                if (currentDigPosition.x < tunnelGoal.x)
                {
                    currentDigPosition.x++;
                }
                else if (currentDigPosition.x > tunnelGoal.x)
                {
                    currentDigPosition.x--;
                }
                else
                {
                    if (spawnRoomsAtTunnelEnds)
                    {
                        SpawnRoomTemplateAtTunnelEnd(boardGenerator, currentDigPosition);
                    }

                    break;
                }

                for (int j = 0; j < tunnelWidth; j++)
                {
                    boardGenerator.WriteToBoardGrid(currentDigPosition.x, currentDigPosition.y + j, GetCharToWriteForTunnel(boardGenerator), true, true);
                }
            }
            for (int k = 0; k < maxLengthPerTunnel; k++)
            {
                if (currentDigPosition.y < tunnelGoal.y)
                {
                    currentDigPosition.y++;
                }
                else if (currentDigPosition.y > tunnelGoal.y)
                {
                    currentDigPosition.y--;
                }
                else
                {
                    if (spawnRoomsAtTunnelEnds)
                    {
                        SpawnRoomTemplateAtTunnelEnd(boardGenerator, currentDigPosition);
                    }
                    break;
                }
                for (int s = 0; s < tunnelWidth; s++)
                {
                    boardGenerator.WriteToBoardGrid(currentDigPosition.x + s, currentDigPosition.y, GetCharToWriteForTunnel(boardGenerator), true, true);
                }
            }
        }
コード例 #11
0
        public void BuildBorder(BoardGenerator boardGenerator)
        {
            float leftEdgeX   = -1f;
            float rightEdgeX  = boardGenerator.boardGenerationProfile.boardHorizontalSize + 0f;
            float bottomEdgeY = -1f;
            float topEdgeY    = boardGenerator.boardGenerationProfile.boardVerticalSize + 0f;

            InstantiateVerticalOuterWall(leftEdgeX, bottomEdgeY, topEdgeY, boardGenerator);
            InstantiateVerticalOuterWall(rightEdgeX, bottomEdgeY, topEdgeY, boardGenerator);

            InstantiateHorizontalOuterWall(leftEdgeX + 1f, rightEdgeX - 1f, bottomEdgeY, boardGenerator);
            InstantiateHorizontalOuterWall(leftEdgeX + 1f, rightEdgeX - 1f, topEdgeY, boardGenerator);
        }
コード例 #12
0
        char GetCharToWriteForTunnel(BoardGenerator boardGenerator)
        {
            char charToWrite;

            if (useCustomEmptySpaceCharForTunnels)
            {
                charToWrite = customEmptySpaceChar;
            }
            else
            {
                charToWrite = boardGenerator.boardGenerationProfile.boardLibrary.GetDefaultEmptyChar();
            }
            return(charToWrite);
        }
コード例 #13
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            BoardGenerator myScript = (BoardGenerator)target;

            if (GUILayout.Button("Clear And Generate"))
            {
                myScript.ClearAndRebuild();
            }

            if (GUILayout.Button("Clear"))
            {
                myScript.ClearLevel();
            }
        }
コード例 #14
0
        private void WriteFilledRooms(BoardGenerator boardGenerator, RoomChain roomChainComponent, int horizontalRoomsToFill, int verticalRoomsToFill, RoomTemplate[,] finalRoomGrid)
        {
            int roomChainNumber = 0;

            for (int x = 0; x < horizontalRoomsToFill; x++)
            {
                for (int y = 0; y < verticalRoomsToFill; y++)
                {
                    Vector2      roomPos         = new Vector2(x * roomSizeX, y * roomSizeY);
                    RoomTemplate templateToWrite = finalRoomGrid[x, y];
                    if (templateToWrite != null)
                    {
                        roomChainNumber++;
                        WriteChainRoomToGrid(boardGenerator, roomChainComponent, roomPos, templateToWrite, roomChainNumber, true);
                    }
                }
            }
        }
コード例 #15
0
ファイル: RoomChain.cs プロジェクト: jk0524/gameDev
        public GameObject GenerateRoomPlaceHolderGameObject(BoardGenerator boardGenerator, Vector2 roomOrigin, RoomTemplate roomTemplate, int chainNumber, bool isOnPath, string namePrefix)
        {
            GameObject roomMarker;

            if (isOnPath)
            {
                roomMarker = new GameObject(namePrefix + "Path Room " + chainNumber + " " + roomTemplate.name);
            }
            else
            {
                roomMarker = new GameObject(namePrefix + "Random fill Room " + roomTemplate.name);
            }

            roomMarker.transform.position = roomOrigin;
            roomMarker.transform.SetParent(this.transform);

            return(roomMarker);
        }
コード例 #16
0
        void SmoothMap(BoardGenerator boardGenerator)
        {
            for (int x = 0; x < boardGenerator.boardGenerationProfile.boardHorizontalSize; x++)
            {
                for (int y = 0; y < boardGenerator.boardGenerationProfile.boardVerticalSize; y++)
                {
                    int neighbourWallTiles = GetSurroundingWallCount(x, y, boardGenerator);

                    if (neighbourWallTiles > 4)
                    {
                        boardGenerator.WriteToBoardGrid(x, y, charForFill, overwriteFilledSpaces, false);
                    }
                    else if (neighbourWallTiles < 4)
                    {
                        boardGenerator.WriteToBoardGrid(x, y, emptySpaceChar, overwriteFilledSpaces, false);
                    }
                }
            }
        }
コード例 #17
0
        private List <GridPosition> BuildTunnelGoalList(BoardGenerator boardGenerator)
        {
            List <GridPosition> goalPositions = new List <GridPosition>();

            for (int i = 0; i <= boardGenerator.currentGeneratorIndexIdForEmptySpaceTracking; i++)
            {
                for (int j = 0; j < numTunnels; j++)
                {
                    if (boardGenerator.emptySpaceLists[i].gridPositionList.Count > 0)
                    {
                        int          index         = Random.Range(0, boardGenerator.emptySpaceLists[i].gridPositionList.Count);
                        GridPosition emptyPosition = boardGenerator.emptySpaceLists[i].gridPositionList[index];
                        boardGenerator.emptySpaceLists[i].gridPositionList.RemoveAt(index);
                        goalPositions.Add(emptyPosition);
                    }
                }
            }

            return(goalPositions);
        }
コード例 #18
0
 public override void SpawnBoardSquare(BoardGenerator boardGenerator, Vector2 location, BoardLibraryEntry inputEntry)
 {
     if (inputEntry != null)
     {
         if (inputEntry.prefabToSpawn == null)
         {
             Vector3Int pos = new Vector3Int((int)location.x, (int)location.y, 0);
             boardGenerator.tilemap.SetTile(pos, inputEntry.tile);
         }
         else
         {
             Vector3Int pos         = new Vector3Int((int)location.x, (int)location.y, 0);
             TileBase   defaultTile = boardGenerator.boardGenerationProfile.boardLibrary.GetDefaultTile();
             boardGenerator.tilemap.SetTile(pos, defaultTile);
             Instantiate(inputEntry.prefabToSpawn, location, Quaternion.identity);
         }
     }
     else
     {
         Debug.LogError("Returned null from library, something went wrong when trying to draw tiles.");
     }
 }
コード例 #19
0
        public override void Generate(BoardGenerator boardGenerator)
        {
            int  horizontalRoomsToFill = boardGenerator.boardGenerationProfile.boardHorizontalSize / roomSizeX;
            int  verticalRoomsToFill   = boardGenerator.boardGenerationProfile.boardVerticalSize / roomSizeY;
            int  generationAttempts    = 0;
            bool generationSucceeded   = false;

            while (!generationSucceeded)
            {
                generationAttempts++;
                RoomChain roomChainComponent = SetupRoomChainComponent(boardGenerator);
                RoomTemplate[,] roomTemplateGrid = new RoomTemplate[horizontalRoomsToFill, verticalRoomsToFill];
                roomTemplateGrid = BuildRoomSequence(roomChainComponent, horizontalRoomsToFill, verticalRoomsToFill);
                if (roomTemplateGrid != null)
                {
                    WriteFilledRooms(boardGenerator, roomChainComponent, horizontalRoomsToFill, verticalRoomsToFill, roomTemplateGrid);
                    generationSucceeded = true;
                    Destroy(roomChainComponent.gameObject);
                    break;
                }
                else
                {
                    roomChainComponent = SetupRoomChainComponent(boardGenerator);
                    roomTemplateGrid   = BuildRoomSequence(roomChainComponent, horizontalRoomsToFill, verticalRoomsToFill);
                }
                if (fillEmptySpaceWithRandomRooms)
                {
                    FillUnusedSpaceWithRandomRooms(horizontalRoomsToFill, verticalRoomsToFill, roomTemplateGrid);
                }
                if (generationAttempts > maximumAttempts)
                {
                    Debug.LogError("Generation failed after " + maximumAttempts + " try to tweak your parameters to create something more likely to succeed by lowering minimum generated rooms and raising chance to continue growing.");
                    Destroy(roomChainComponent.gameObject);
                    break;
                }
            }
        }
コード例 #20
0
        private void WriteChainRoomToGrid(BoardGenerator boardGenerator, RoomChain roomChainComponent, Vector2 roomOrigin, RoomTemplate roomTemplate, int chainNumber, bool isOnPath)
        {
#if UNITY_EDITOR
            roomChainComponent.GenerateRoomPlaceHolderGameObject(boardGenerator, roomOrigin, roomTemplate, chainNumber, isOnPath, "Chain Room");
#endif
            int charIndex = 0;
            for (int i = 0; i < roomSizeX; i++)
            {
                for (int j = 0; j < roomSizeY; j++)
                {
                    char selectedChar = roomTemplate.roomChars[charIndex];
                    if (selectedChar != '\0')
                    {
                        Vector2 spawnPos = new Vector2(i, j) + roomOrigin;

                        int x = (int)spawnPos.x;
                        int y = (int)spawnPos.y;

                        boardGenerator.WriteToBoardGrid(x, y, selectedChar, overwriteFilledSpaces, isOnPath);
                    }
                    charIndex++;
                }
            }
        }
コード例 #21
0
        void InstantiateVerticalOuterWall(float xCoord, float startingY, float endingY, BoardGenerator boardGenerator)
        {
            float currentY = startingY;

            while (currentY <= endingY)
            {
                Vector2 spawnPos = new Vector2(xCoord, currentY);
                boardGenerator.CreateMapEntryFromGrid(borderChar, spawnPos);
                currentY++;
            }
        }
コード例 #22
0
        void InstantiateHorizontalOuterWall(float startingX, float endingX, float yCoord, BoardGenerator boardGenerator)
        {
            float currentX = startingX;

            while (currentX <= endingX)
            {
                Vector2 spawnPos = new Vector2(currentX, yCoord);
                boardGenerator.CreateMapEntryFromGrid(borderChar, spawnPos);
                currentX++;
            }
        }
コード例 #23
0
ファイル: BoardGenerator.cs プロジェクト: jk0524/gameDev
        public GridPosition GetRandomEmptyGridPositionFromLastEmptySpaceGeneratorInStack(BoardGenerator boardGenerator)
        {
            int genIndex = 0;

            for (int i = 0; i < boardGenerationProfile.generators.Length; i++)
            {
                if (boardGenerationProfile.generators[i].generatesEmptySpace)
                {
                    genIndex = i;
                }
            }
            GridPosition randPosition = emptySpaceLists[genIndex].gridPositionList[UnityEngine.Random.Range(0, emptySpaceLists[genIndex].gridPositionList.Count)];

            return(randPosition);
        }
コード例 #24
0
 public override void Generate(BoardGenerator boardGenerator)
 {
     BuildBorder(boardGenerator);
 }
コード例 #25
0
 public abstract void SpawnBoardSquare(BoardGenerator boardGenerator, Vector2 location, BoardLibraryEntry inputEntry);
コード例 #26
0
ファイル: DoorController.cs プロジェクト: jk0524/gameDev
        //public GameObject room = GameObject.Find("Room");

        // Use this for initialization
        void Start()
        {
            tilemap = GameObject.Find("Grid");
            board   = tilemap.GetComponentInChildren <BoardGenerator>();
        }