Esempio n. 1
0
        private void Awake()
        {
            roomInfo = GetComponent <RoomInformation>();

            // The extents are actaully halfExtents
            float x = roomInfo.extents.x;
            float z = roomInfo.extents.z;

            int numberOfXTiles = Mathf.CeilToInt(x / tileSize);
            int numberOfZTiles = Mathf.CeilToInt(z / tileSize);

            grid = new GridPoint[numberOfXTiles, numberOfZTiles];
            Quaternion rot      = this.transform.rotation;
            Vector3    transPos = this.transform.position;

            for (int i = 0; i < grid.GetLength(0); i++)
            {
                for (int j = 0; j < grid.GetLength(1); j++)
                {
                    grid[i, j]      = new GridPoint();
                    grid[i, j].room = this;
                    Vector3 pos = transPos + rot * new Vector3((i * tileSize) + tileSize / 2, 0, (j * tileSize) + tileSize / 2);
                    grid[i, j].center           = pos;
                    grid[i, j].adjacentPointsXY = GetAdjacentXY(i, j, grid.GetLength(0), grid.GetLength(1));
                }
            }
            entrancePoints = new Vector2Int[roomInfo.GetEntrances.Length];
            entranceIds    = new int[roomInfo.GetEntrances.Length];
            for (int i = 0; i < roomInfo.GetEntrances.Length; i++)
            {
                Vector3 entrancePos = (roomInfo.GetEntrance(i).entranceMidPoint.transform.localPosition) / tileSize;
                int     xPos        = Mathf.FloorToInt(entrancePos.x);
                if (xPos >= grid.GetLength(0))
                {
                    xPos = grid.GetLength(0) - 1;
                }
                else if (xPos < 0)
                {
                    xPos = 0;
                }

                int zPos = Mathf.FloorToInt(entrancePos.z);
                if (zPos >= grid.GetLength(1))
                {
                    zPos = grid.GetLength(1) - 1;
                }
                else if (zPos < 0)
                {
                    zPos = 0;
                }

                grid[xPos, zPos].entrance   = roomInfo.GetEntrance(i);
                grid[xPos, zPos].isEntrance = true;
                entrancePoints[i]           = new Vector2Int(xPos, zPos);
                entranceIds[i] = roomInfo.GetEntrance(i).ID;
            }
        }
Esempio n. 2
0
    private void Update()
    {
        if (afterBurnTimer > 0)
        {
            afterBurnTimer -= Time.deltaTime;
        }

        if (!isOnFire)
        {
            return;
        }
        if (fireLifeTimer > 0)
        {
            fireLifeTimer -= Time.deltaTime;
            StepFireForwards();
        }
        else if (burningTris.Count > 0)
        {
            for (int i = 0; i < 3; i++)
            {
                tris[removedTriangles * 3 + i] = 0;
            }
            removedTriangles++;
            availableDoorTriangles.Remove(burningTris[0]);
            burningTris.RemoveAt(0);
            if (burningTris.Count == 0)
            {
                particleSystem.Stop();
                smokeParticleSystem.Stop();
                mesh.triangles = tris;
                var sh = particleSystem.shape;
                sh.shapeType = ParticleSystemShapeType.Sphere;
                sh           = smokeParticleSystem.shape;
                sh.shapeType = ParticleSystemShapeType.Sphere;
                burningTris.Clear();
                removedTriangles = 0;
                isOnFire         = false;
                afterBurnTimer   = afterBurnTime;
            }
            else
            {
                mesh.triangles = tris;
                var sh = particleSystem.shape;
                sh.mesh = mesh;
                sh      = smokeParticleSystem.shape;
                sh.mesh = mesh;
            }
        }
        if (availableDoorTriangles.Count > 0)
        {
            for (int i = 0; i < availableDoorTriangles.Count; i++)
            {
                for (int j = 0; j < availableDoorTriangles[i].connectedEntranceIDs.Length; j++)
                {
                    NavMeshEntrance selectedEntrance = room.GetEntrance(availableDoorTriangles[i].connectedEntranceIDs[j]);
                    if (selectedEntrance.connectedEntrance != null && selectedEntrance.IsPassable)
                    {
                        RoomInformation nextRoom = room.GetConnectedRoomFromEntranceWithID(selectedEntrance.ID);
                        if (nextRoom)
                        {
                            nextRoom.StartFire(selectedEntrance.connectedEntrance.connectedTriangle.ID);
                        }
                    }
                }
            }
        }
    }
Esempio n. 3
0
    private void Update()
    {
        if (availableEntrances.Count == 0)
        {
            return;
        }
        if (roomCounter < numberOfRooms && stopCounter++ > 0)
        {
            // Pick a random entrance point
            int             randomEntranceIndex = Random.Range(0, availableEntrances.Count);
            NavMeshEntrance randomEntrance      = availableEntrances[randomEntranceIndex];
            // Choose a random generator
            RoomInformation randomRoomPrefab        = GetRandomRoom();
            int             randomRoomEntranceIndex = Random.Range(0, randomRoomPrefab.GetEntrances.Length);

            NavMeshEntrance randomRoomEntrance = randomRoomPrefab.GetEntrance(randomRoomEntranceIndex);

            float angle          = Vector3.SignedAngle(randomEntrance.GetRotatedAwayFromDoorDirection(), randomRoomEntrance.GetRotatedAwayFromDoorDirection(), Vector3.up);
            float amountToRotate = 180 - angle;

            // Init the random generator
            RoomInformation room2 = Instantiate <RoomInformation>(randomRoomPrefab, this.transform);

            List <NavMeshEntrance> newRoomEntrances = new List <NavMeshEntrance>(room2.GetEntrances);
            NavMeshEntrance        room2Entrance    = newRoomEntrances[randomRoomEntranceIndex];

            room2.transform.RotateAround(room2Entrance.entranceMidPoint.transform.position, Vector3.up, amountToRotate);

            Vector3 directionToMove = randomEntrance.entranceMidPoint.transform.position - room2Entrance.entranceMidPoint.transform.position;
            room2.transform.Translate(directionToMove, Space.World);

            room2.GetRotatedCenter(out cen, out ext);
            cen += room2.transform.position;
            if (generationMap.IsRoomSpaceFree(cen, ext))
            {
                generationMap.AddRectangle(cen, ext);

                generatedRooms.Add(room2);

                room2.SetID(roomCounter + 1);
                roomGraph.AddRoom(room2, randomEntrance.generator.containedRoom);
                newRoomEntrances.RemoveAt(randomRoomEntranceIndex);

                AddEntrancesToAvailableEntrances(newRoomEntrances, amountToRotate);

                TraversalEntrance traversalEntranceRoom2 =
                    room2.TraversalGenerator.GetEntrance(room2Entrance.ID);
                TraversalEntrance traversalEntranceRandomRoom =
                    randomEntrance.generator.containedRoom.TraversalGenerator.GetEntrance(randomEntrance.ID);

                if (traversalEntranceRoom2 != null)
                {
                    room2.roomGrid.AddGrid(randomEntrance.generator.containedRoom.roomGrid, traversalEntranceRoom2.ID, traversalEntranceRandomRoom.ID);
                    randomEntrance.generator.containedRoom.roomGrid.AddGrid(room2.GetComponent <Pieter.Grid.RoomGrid>(), traversalEntranceRandomRoom.ID, traversalEntranceRoom2.ID);

                    room2.TraversalGenerator.AddAdjacentNodes(traversalEntranceRoom2.vertex, traversalEntranceRandomRoom.vertex);
                    randomEntrance.generator.containedRoom.TraversalGenerator.AddAdjacentNodes(traversalEntranceRandomRoom.vertex, traversalEntranceRoom2.vertex);

                    room2.AddConnectedRoom(randomEntrance.generator.containedRoom, room2Entrance);
                    randomEntrance.generator.containedRoom.AddConnectedRoom(room2, randomEntrance);

                    room2Entrance.connectedEntrance  = randomEntrance;
                    randomEntrance.connectedEntrance = room2Entrance;
                }
                else
                {
                    print("Could not find the door with ID " + room2Entrance.ID + " on the door " + room2.name);
                }

                traversalGraphHolder.AddTraversalLines(room2.TraversalGenerator);

                availableEntrances.RemoveAt(randomEntranceIndex);
                Physics.SyncTransforms();
                roomCounter++;
            }
            else
            {
                Destroy(room2.gameObject);
            }
        }
        else
        {
            if (!didNotify)
            {
                didNotify = true;
                OnDoneLevelGeneration?.Invoke();
                traversalGraphHolder.Notify();
            }
        }
    }