Ejemplo n.º 1
0
        public void CreateDoors(RoomInstance room)
        {
            Vector2 spawnPosition = new Vector2(room.gridPos.x + room.roomSizeInTiles.x, room.gridPos.y + room.roomSizeInTiles.y * 2);

            PlaceDoor(spawnPosition, room.doorU, room.roomTop, Orientation.North, room);
            spawnPosition = new Vector2(room.gridPos.x + room.roomSizeInTiles.x, room.gridPos.y - 1);
            PlaceDoor(spawnPosition, room.doorD, room.roomBot, Orientation.South, room);
            spawnPosition = new Vector2(room.gridPos.x + room.roomSizeInTiles.x * 2, room.gridPos.y + room.roomSizeInTiles.y);
            PlaceDoor(spawnPosition, room.dooR, room.roomRight, Orientation.East, room);
            spawnPosition = new Vector2(room.gridPos.x - 1, room.gridPos.y + room.roomSizeInTiles.y);
            PlaceDoor(spawnPosition, room.doorL, room.roomLeft, Orientation.West, room);
        }
Ejemplo n.º 2
0
        void PlaceDoor(Vector2 spawnPosition, GameObject door, RoomInstance linkedRoom, Orientation orientation, RoomInstance OwnerRoom)
        {
            if (linkedRoom != null)
            {
                Vector3Int currentCell = GameObject.FindGameObjectWithTag("Interactive").GetComponent <Tilemap>().WorldToCell(spawnPosition);
                GameObject.FindGameObjectWithTag("Interactive").GetComponent <Tilemap>().SetTile(new Vector3Int(currentCell.x, currentCell.y, currentCell.z), DoorTile);
                Vector3 spawnPos = new Vector3(0, 0, 0);
                switch (orientation)
                {
                case Orientation.North:
                    spawnPos = new Vector3(spawnPosition.x, spawnPosition.y, 0);
                    break;

                case Orientation.South:
                    spawnPos = new Vector3(spawnPosition.x, spawnPosition.y - 1f, 0);
                    break;

                case Orientation.East:
                    spawnPos = new Vector3(spawnPosition.x + 1f, spawnPosition.y - 1f, 0);
                    break;

                case Orientation.West:
                    spawnPos = new Vector3(spawnPosition.x, spawnPosition.y - 1f, 0);
                    break;
                }
                door = (GameObject)Instantiate(Resources.Load("Prefabs/Interactive/Activable/Door"), spawnPos, Quaternion.identity);
                door.transform.parent = GameObject.Find("Room " + OwnerRoom.gridPos.x / 100 + ", " + OwnerRoom.gridPos.y / 100 + " - " + OwnerRoom.RoomType).transform;
                Door doorScript = door.GetComponent(typeof(Door)) as Door;
                doorScript.LinkRoom    = linkedRoom;
                doorScript.Orientation = orientation;
                doorScript.OwnerRoom   = OwnerRoom;
                door.name = "Door " + OwnerRoom.gridPos.x / 100 + ", " + OwnerRoom.gridPos.y / 100 + "- " + orientation;
                switch (orientation)
                {
                case Orientation.North:
                    OwnerRoom.doorU = door;
                    break;

                case Orientation.South:
                    OwnerRoom.doorD = door;
                    break;

                case Orientation.East:
                    OwnerRoom.dooR = door;
                    break;

                case Orientation.West:
                    OwnerRoom.doorL = door;
                    break;
                }

                switch (linkedRoom.RoomType)
                {
                case RoomType.SecretRoom:
                    doorScript.DoorType = DoorType.secretDoor;
                    break;

                case RoomType.BossRoom:
                    doorScript.DoorType = DoorType.bossDoor;
                    break;

                default:
                    doorScript.DoorType = DoorType.normalDoor;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        void CreateRoomsInstances()
        {
            // Convert all room to roomInstance
            foreach (var room in roomList)
            {
                // Create gameobject RoomInstance
                GameObject roomObject = new GameObject();
                roomObject.name             = "Room " + room.gridPos.x + ", " + room.gridPos.y + " - " + room.RoomType;
                roomObject.transform.parent = GameObject.Find("Rooms").transform;
                RoomInstance roomSriptInstance = roomObject.AddComponent(typeof(RoomInstance)) as RoomInstance;
                roomSriptInstance.gridPos  = room.gridPos * 100;
                roomSriptInstance.RoomType = room.RoomType;
                roomSriptInstance.DoorTile = DoorTile;
                roomSriptInstance.Mapper   = room.Mapper;

                switch (room.RoomType)
                {
                case RoomType.NormalRoom:
                    roomSriptInstance.WallTile  = NormalWallTile;
                    roomSriptInstance.FloorTile = NormalFloorTile;
                    break;

                case RoomType.BossRoom:
                    roomSriptInstance.WallTile  = BossWallTile;
                    roomSriptInstance.FloorTile = BossFloorTile;
                    break;

                case RoomType.TreasureRoom:
                    roomSriptInstance.WallTile  = TreasureWallTile;
                    roomSriptInstance.FloorTile = TreasureFloorTile;
                    break;

                case RoomType.SecretRoom:
                    roomSriptInstance.WallTile  = TreasureWallTile;
                    roomSriptInstance.FloorTile = TreasureFloorTile;
                    break;

                case RoomType.SpawnRoom:
                    roomSriptInstance.WallTile  = NormalWallTile;
                    roomSriptInstance.FloorTile = NormalFloorTile;
                    break;

                default:
                    roomSriptInstance.WallTile  = NormalWallTile;
                    roomSriptInstance.FloorTile = NormalFloorTile;
                    break;
                }
                roomSriptInstance.Invoke("GenerateRoomTiles", 0);
                roomInstanceList.Add(roomObject.GetComponent(typeof(RoomInstance)) as RoomInstance);
            }

            // Adding connected room to each room
            for (int i = 0; i < roomList.Count; i++)
            {
                var roomInstance = roomInstanceList[i];
                if (roomList[i].roomBot != null)
                {
                    roomInstance.roomBot = roomInstanceList[roomList.IndexOf(roomList[i].roomBot)];
                }
                if (roomList[i].roomTop != null)
                {
                    roomInstance.roomTop = roomInstanceList[roomList.IndexOf(roomList[i].roomTop)];
                }
                if (roomList[i].roomLeft != null)
                {
                    roomInstance.roomLeft = roomInstanceList[roomList.IndexOf(roomList[i].roomLeft)];
                }
                if (roomList[i].roomRight != null)
                {
                    roomInstance.roomRight = roomInstanceList[roomList.IndexOf(roomList[i].roomRight)];
                }
            }
            // Create doors
            foreach (var room in roomInstanceList)
            {
                CreateDoors(room);
                room.Mapper.transform.parent = GameObject.Find("Room " + room.gridPos.x / 100 + ", " + room.gridPos.y / 100 + " - " + room.RoomType).transform;
            }

            roomInstanceList[0].isRoomVisited = true;
        }
Ejemplo n.º 4
0
 public void SetRoomLeft(RoomInstance _RoomLeft)
 {
     roomLeft = _RoomLeft;
 }