private void cleanGenerator()
 {
     if (_currentGenerator != null)
     {
         Destroy(_currentGenerator);
         _currentGenerator = null;
     }
 }
Exemple #2
0
 private void cleanGenerator()
 {
     if (_currentGenerator != null)
     {
         Destroy(_currentGenerator);
         _currentGenerator = null;
     }
 }
Exemple #3
0
 public override IEnumerator RunTimeTryGenerate(BaseLevelGenerator generator, MonoBehaviour mono)
 {
     notConnectedRooms = new List <BaseRoom>();
     //place rooms
     for (int i = 0; i < loseRoomData.roomCount; i++)
     {
         int x    = Random.Range(0, loseRoomData.roomCount * loseRoomData.averageRoomSize.x);
         int y    = Random.Range(0, loseRoomData.roomCount * loseRoomData.averageRoomSize.y);
         var room = loseRoomData.GetRoom().GetStructure() as BaseRoom;
         room.posX = x;
         room.posY = y;
         notConnectedRooms.Add(room);
     }
     //recalcuate Positions
     for (int i = 0; i < 80; i++)
     {
         MoveStructureAway(notConnectedRooms);
     }
     //remove some rooms
     for (int i = notConnectedRooms.Count - 1; i >= 0; i--)
     {
         var otherStructure = GetRoomInBounds(notConnectedRooms, notConnectedRooms[i]);
         if (otherStructure.Count != 0 && Random.value > .5f)
         {
             //notConnectedRooms.Remove(notConnectedRooms[i]);
         }
     }
     //recalculate position again
     for (int i = 0; i < 40; i++)
     {
         MoveStructureAway(notConnectedRooms);
     }
     for (int i = 0; i < 44; i++)
     {
         MoveTogehter(notConnectedRooms);
     }
     //remove some rooms
     for (int i = notConnectedRooms.Count - 1; i >= 0; i--)
     {
         var otherStructure = GetRoomInBounds(notConnectedRooms, notConnectedRooms[i]);
         if (otherStructure.Count != 0)
         {
             //notConnectedRooms.Remove(notConnectedRooms[i]);
         }
     }
     //connect rooms to start room
     for (int i = 0; i < notConnectedRooms.Count; i++)
     {
         //ConnectRoomWithOther(notConnectedRooms, notConnectedRooms[i]);
     }
     //remove not connected Rooms
     rooms = notConnectedRooms;
     for (int i = 0; i < rooms.Count; i++)
     {
         rooms[i].TryGenerate(generator);
     }
     yield return(null);
 }
Exemple #4
0
    public override void TryGenerate(BaseLevelGenerator generator)
    {
        base.TryGenerate(generator);
        notConnectedRooms = new List <BaseRoom>();
        //place rooms
        for (int i = 0; i < loseRoomData.roomCount; i++)
        {
            int x    = 0;
            int y    = 0;
            var room = loseRoomData.GetRoom().GetStructure() as BaseRoom;
            if (notConnectedRooms.Count != 0)
            {
                int index = Random.Range(0, notConnectedRooms.Count);
                int xDir  = (int)Mathf.Sign(Random.Range(-1, 1));
                int yDir  = (int)Mathf.Sign(Random.Range(-1, 1));
                if (Random.value > .5)
                {
                    xDir = 0;
                }
                else
                {
                    yDir = 0;
                }
                x = notConnectedRooms[index].centerX + (notConnectedRooms[index].sizeX / 2 + room.sizeX / 2 - room.centerX) * xDir;
                y = notConnectedRooms[index].centerY + (notConnectedRooms[index].sizeY / 2 + room.sizeY / 2 - room.centerY) * yDir;
            }

            room.posX = x;
            room.posY = y;
            notConnectedRooms.Add(room);
        }
        //recalcuate Positions
        //for (int i = 0; i < 80; i++) {
        //    MoveStructureAway(notConnectedRooms);
        //}
        //
        ////recalculate position again
        //for (int i = 0; i < 40; i++) {
        //    MoveStructureAway(notConnectedRooms);
        //}
        for (int i = 0; i < 4; i++)
        {
            MoveTogehter(notConnectedRooms);
        }

        rooms = notConnectedRooms;
        for (int i = 0; i < rooms.Count; i++)
        {
            rooms[i].TryGenerate(generator);
        }
    }
	public void TestGenerator(BaseLevelGenerator generator)
	{
		_generating = true;
		_timeSinceLastStep = 0.0f;

		_generatorRemainsWhenDone = true;
		_generator = generator;
		this.Map.FillCompletely(LevelGenMap.TileType.A);
		_generator.SetupGeneration();

        if (_updateDelegates != null)
        {
            for (int i = 0; i < _updateDelegates.Count; ++i)
                _updateDelegates[i]();
        }
    }
Exemple #6
0
    public void TestGenerator(BaseLevelGenerator generator)
    {
        _generating        = true;
        _timeSinceLastStep = 0.0f;

        _generatorRemainsWhenDone = true;
        _generator = generator;
        this.Map.FillCompletely(LevelGenMap.TileType.A);
        _generator.SetupGeneration();

        if (_updateDelegates != null)
        {
            for (int i = 0; i < _updateDelegates.Count; ++i)
            {
                _updateDelegates[i]();
            }
        }
    }
Exemple #7
0
    private void Start()
    {
        Enemies [1].SetActive(false);
        Enemies [2].SetActive(false);

        mazeGenerator = new MazeGen(Rows, Columns);
        mazeGenerator.GenerateMaze();
        for (int row = 0; row < Rows; row++)
        {
            for (int column = 0; column < Columns; column++)
            {
                this.x    = column * cellWidth;
                this.z    = row * cellHeight;
                this.cell = mazeGenerator.GetMazeCell(row, column);
                GameObject tmp;
                tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject;
                tmp.transform.parent = transform;
                if (this.cell.WallRight)
                {
                    tmp = Instantiate(Wall, new Vector3(x + cellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;
                    tmp.transform.parent = transform;
                }

                if (this.cell.WallFront)
                {
                    tmp = Instantiate(Wall, new Vector3(x, 0, z + cellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                    tmp.transform.parent = transform;
                }

                if (this.cell.WallLeft)
                {
                    tmp = Instantiate(Wall, new Vector3(x - cellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;
                    tmp.transform.parent = transform;
                }

                if (this.cell.WallBack)
                {
                    tmp = Instantiate(Wall, new Vector3(x, 0, z - cellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;
                    tmp.transform.parent = transform;
                }
            }
        }
    }
Exemple #8
0
 public virtual IEnumerator RunTimeTryGenerate(BaseLevelGenerator generator, MonoBehaviour mono)
 {
     yield return(null);
 }
Exemple #9
0
 public virtual void TryGenerate(BaseLevelGenerator generator)
 {
 }
        public override IEnumerator RunTimeTryGenerate(BaseLevelGenerator generator, MonoBehaviour mono)
        {
            structureList = new List <BaseLevelStructure>();
            int levelSizeX = gData.levelSizeX;
            int levelSizeY = gData.levelSizeY;

            rooms = new BaseFixedRoom[levelSizeX * levelSizeY];
            for (int x = 0; x < levelSizeX; x++)
            {
                for (int y = 0; y < levelSizeY; y++)
                {
                    rooms[x + y * levelSizeX] = BaseFixedRoom.EmptyRoom(x, y);
                }
            }
            freeRooms = new List <BaseFixedRoom>();

            for (int x = 0; x < levelSizeX; x++)
            {
                for (int y = 0; y < levelSizeY; y++)
                {
                    freeRooms.Add(BaseFixedRoom.EmptyRoom(x, y));
                }
            }
            yield return(null);


            //placeExit
            //DebugCheckTimeStart("Place Exit");
            var exit    = GetRandomRoomFromList(gData.roomExitDataList).GetStructure() as FixedRoom_Exit;
            var exitPos = GetRandomRoomPos();

            SetFixedRoom(exit, exitPos.x, exitPos.y);
            if (exitPos == Vector2Int.one * -1 || exit == null)
            {
                //DebugTryFail(exit == null ? "Couldnt find Exit Room" : "Could find Position for exit");
                //return false;
            }
            yield return(null);

            // DebugCheckTimeEnd();

            //ChestRoom
            //DebugCheckTimeStart("Place Chest");

            var chest    = GetRandomRoomFromList(gData.roomChestDataList).GetStructure() as FixedRoom_Chest;
            var chestPos = GetRandomFreeRoomPos((int)new Vector2(levelSizeX, levelSizeY).magnitude / 3, exit);

            if (chestPos == Vector2Int.one * -1 || chest == null)
            {
                //DebugTryFail(chest == null ? "Couldnt find Chest Room" : "Could find Position for chest");
                //return false;
            }
            SetFixedRoom(chest, chestPos.x, chestPos.y);
            yield return(null);

            //DebugCheckTimeEnd();


            //PlaceShop
            //DebugCheckTimeStart("Place Shop");

            var shop    = GetRandomRoomFromList(gData.roomShopDataList).GetStructure() as FixedRoom_Shop;
            var shopPos = GetRandomFreeRoomPos((int)new Vector2(levelSizeX, levelSizeY).magnitude / 3, chest, exit);

            if (shopPos == Vector2Int.one * -1 || shop == null)
            {
                //DebugTryFail(exit == null ? "Couldnt find Shop Room" : "Could find Position for shop");
                //return false;
            }
            SetFixedRoom(shop, shopPos.x, shopPos.y);
            yield return(null);

            //DebugCheckTimeEnd();


            //Connect Rooms
            //DebugCheckTimeStart("Connection");

            if (GenerateConnection(chest, exit) == false)
            {
                //DebugTryFail("Couldnt connect chest and Exit");
                //return false;
            }
            if (GenerateConnection(shop, exit) == false)
            {
                //DebugTryFail("Couldnt connect shop and Exit");
                //return false;
            }
            yield return(null);

            //DebugCheckTimeEnd();


            //FillRest
            //DebugCheckTimeStart("Fill");

            int roomCount = UnityEngine.Random.Range(gData.roomCountRange.x, gData.roomCountRange.y);

            for (int i = 0; i < 50; i++)
            {
                if (CountOfRooms() >= roomCount)
                {
                    break;
                }
                int corridorLength = UnityEngine.Random.Range(gData.additionalCoridorLengthRange.x, gData.additionalCoridorLengthRange.y);
                GenerateCorridor(corridorLength, roomCount);
                yield return(null);
            }
            yield return(null);

            //DebugCheckTimeEnd();


            //Place Entry
            //DebugCheckTimeStart("Place Entry");

            var entry    = GetRandomRoomFromList(gData.roomEntryDataList).GetStructure() as FixedRoom_Entry;
            var entryPos = FindEntryPos(exit, (int)new Vector2(levelSizeX, levelSizeY).magnitude / 3);

            if (entryPos == Vector2Int.one * -1 || entry == null)
            {
                //DebugTryFail(entry == null ? "Couldnt find Entry Room" : "Could find Position for Entry");
                //return false;
            }
            SetFixedRoom(entry, entryPos.x, entryPos.y);
            yield return(null);

            //DebugCheckTimeEnd();

            //GenerateDoor
            for (int x = 0; x < levelSizeX; x++)
            {
                for (int y = 0; y < levelSizeY; y++)
                {
                    if (GetRoom(x, y).IsEmpty())
                    {
                        continue;
                    }
                    ConnectDoorsWithTop(GetRoom(x, y));
                    ConnectDoorsWithBottom(GetRoom(x, y));
                    ConnectDoorsWithLeft(GetRoom(x, y));
                    ConnectDoorsWithRight(GetRoom(x, y));
                    yield return(null);
                }
            }

            for (int x = 0; x < levelSizeX; x++)
            {
                for (int y = 0; y < levelSizeY; y++)
                {
                    if (GetRoom(x, y) != null && GetRoom(x, y).IsEmpty() == false)
                    {
                        structureList.Add(GetRoom(x, y));
                    }
                }
            }


            //return true;
        }