// Use this for initialization void Start() { //Random.Range(1, 1); //wad = new ArrayList(); Debug.Log("speed start"); roomScript = this.GetComponent <RoomScript>(); spawnerScript = this.transform.GetChild(0).GetComponent <SpeedRoomItemSpawner>(); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.LEFT), roomScript.GetHasTriggerBox(DIRECTION.LEFT), DIRECTION.LEFT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.RIGHT), roomScript.GetHasTriggerBox(DIRECTION.RIGHT), DIRECTION.RIGHT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.UP), roomScript.GetHasTriggerBox(DIRECTION.UP), DIRECTION.UP)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.DOWN), roomScript.GetHasTriggerBox(DIRECTION.DOWN), DIRECTION.DOWN)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.LEFT)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.RIGHT)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.UP)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.DOWN)); elapsedTime = 0.0f; isLock = false; puzzleComplete = false; isCompleted = false; //playersList = GameObject.FindGameObjectsWithTag("Player"); //Debug.Log("numPlayer: " + playersList.Length); //for (int i = 0; i < playersList.Length; i++) //{ // if (playersList[i].GetComponent<NetworkIdentity>().isLocalPlayer == true) // { // player = playersList[i]; // break; // } //} player = Global.Instance.player; if (player.GetComponent <NetworkIdentity>().isServer) { Debug.Log("is a server"); } style = new GUIStyle(); style.alignment = TextAnchor.UpperCenter; content = new GUIContent(); itemCollected = 0; }
// Use this for initialization void Start() { roomScript = this.GetComponent <RoomScript>(); //totalNumWave = Random.Range(3, 10); //doorList.Add(roomScript.GetIsLocked(DIRECTION.LEFT)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.RIGHT)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.UP)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.DOWN)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.LEFT), roomScript.GetHasTriggerBox(DIRECTION.LEFT), DIRECTION.LEFT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.RIGHT), roomScript.GetHasTriggerBox(DIRECTION.RIGHT), DIRECTION.RIGHT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.UP), roomScript.GetHasTriggerBox(DIRECTION.UP), DIRECTION.UP)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.DOWN), roomScript.GetHasTriggerBox(DIRECTION.DOWN), DIRECTION.DOWN)); //Spawner = transform.GetChild(0).gameObject; //playersList = GameObject.FindGameObjectsWithTag("Player"); //for (int i = 0; i < playersList.Length; i++) //{ // if (playersList[i].GetComponent<NetworkIdentity>().isLocalPlayer == true) // { // player = playersList[i]; // break; // } //} player = Global.Instance.player; elapsedTime = 0.0f; completedWaves = false; style = new GUIStyle(); style.alignment = TextAnchor.UpperCenter; content = new GUIContent(); text = "Survive the wave of enemies"; content.text = text; isLock = false; isCompleted = false; }
//void ConnectNeighbour(int x, int y, DIRECTION neighbourAt, RoomScript myRoom) //{ // if (!roomMap.ContainsKey(y)) // return; // if (!roomMap[y].ContainsKey(x)) // return; // DIRECTION oppoSide = this.GetOppositeDir(neighbourAt); // GameObject neighbour = roomMap[y][x]; // RoomScript neighbourScript = neighbour.GetComponent<RoomScript>(); // if (!neighbourScript.GetIsLocked(oppoSide)) // { // neighbourScript.OffTriggerBox(oppoSide); // myRoom.UnlockDoor(neighbourAt); // myRoom.OffTriggerBox(neighbourAt); // numOfOpenedDoors -= 2; // } // else // { // //if neighbour facing me is locked, so i also lock lo IF im not locked // if (!myRoom.GetIsLocked(neighbourAt)) // { // myRoom.LockDoor(neighbourAt); // myRoom.OnTriggerBox(neighbourAt); // numOfOpenedDoors -= 1; // } // } //} //returns -1 means must lock, 0 means u can choose, 1 means mmust open RANDACTION IsNeighbourHaveUnlockedDoor(int m_x, int m_y, DIRECTION dir) { int checkX = m_x; int checkY = m_y; switch (dir) { case DIRECTION.LEFT: checkX -= 1; break; case DIRECTION.RIGHT: checkX += 1; break; case DIRECTION.UP: ++checkY; break; case DIRECTION.DOWN: --checkY; break; } if (!roomMap.ContainsKey(checkY)) { return(RANDACTION.CANCHOOSE); } if (!roomMap[checkY].ContainsKey(checkX)) { return(RANDACTION.CANCHOOSE); } RoomScript rs = roomMap[checkY][checkX].GetComponent <RoomScript>(); if (rs.GetIsLocked(GetOppositeDir(dir))) { return(RANDACTION.MUSTLOCK); } else { return(RANDACTION.MUSTOPEN); } return(RANDACTION.CANCHOOSE); }
//init the map public void Init() { biggestX = biggestY = smallestY = smallestX = 0; numOfOpenedDoors = 0; generatedBossRoom = false; roomList = new List <GameObject>(); roomMap = new Dictionary <int, Dictionary <int, GameObject> >(); currID = 0; Global.Instance.bossIsDead = false; //if (!Global.Instance.player.GetComponent<NetworkIdentity>().isServer) //{ // Debug.Log("u not the host"); // return; //} if (!GenerateOnStart) { return; } //Debug.Log("RoomGenerator Start()"); //spawn at 0,0, so generate one at 0,0 GameObject room = Instantiate(defaultRoom, new Vector3(0, 0, zOffset), Quaternion.identity); room.transform.localScale.Set(scaleX, scaleY, 1); RoomScript roomScript = room.GetComponent <RoomScript>(); Dictionary <DIRECTION, bool> boolArray = new Dictionary <DIRECTION, bool>(); float incChance = 0.0f; for (DIRECTION i = DIRECTION.LEFT; i < DIRECTION.LEFT + 4; ++i) { boolArray[i] = false; if (!boolArray[i]) { boolArray[i] = UnityEngine.Random.value < (0.5f + incChance); if (boolArray[i]) { ++numOfOpenedDoors; incChance -= 0.2f; } else { incChance += 0.25f; } } } //Debug.Log("B4_CurrID: " + currID); roomScript.Set(currID, 0, 0, boolArray[DIRECTION.LEFT], boolArray[DIRECTION.RIGHT], boolArray[DIRECTION.UP], boolArray[DIRECTION.DOWN]); StoreRoom(currID, 0, 0, room); //Debug.Log("After_CurrID: " + currID); //Debug.Log("roomID" + room.GetComponent<RoomScript>().GetRoomID()); //NETWORK asdasd //RoomStruct temp = new RoomStruct(); //temp.room = room; //syncListRooomStruct.Add(temp); //NetworkServer.Spawn(room); PopulateRoomListMessage popRoomMsg = new PopulateRoomListMessage(); popRoomMsg.roomID = room.GetComponent <RoomScript>().GetRoomID(); popRoomMsg.gridX = 0; popRoomMsg.gridY = 0; popRoomMsg.roomPos = new Vector3(0, 0, zOffset); popRoomMsg.roomScale = room.transform.localScale; popRoomMsg.roomType = -1; popRoomMsg.isLeft = room.GetComponent <RoomScript>().GetIsLocked(DIRECTION.LEFT); popRoomMsg.isRight = room.GetComponent <RoomScript>().GetIsLocked(DIRECTION.RIGHT); popRoomMsg.isUp = room.GetComponent <RoomScript>().GetIsLocked(DIRECTION.UP); popRoomMsg.isDown = room.GetComponent <RoomScript>().GetIsLocked(DIRECTION.DOWN); popRoomMsg.isActive = true; popRoomMsg.isCompleted = false; roomDataList.Add(popRoomMsg); while (numOfOpenedDoors > 0) { DIRECTION[] dirList = new DIRECTION[4]; //check which door open for (int i = 0; i < roomList.Count; ++i) { GameObject daroom = roomList[i]; RoomScript daroomscript = daroom.GetComponent <RoomScript>(); for (DIRECTION j = DIRECTION.LEFT; j < DIRECTION.LEFT + 4; ++j) { if (daroomscript.GetHasTriggerBox(j) && !daroomscript.GetIsLocked(j)) { //open tat door GenerateRoom(i, j); } } } } Debug.Log("number of rooms: " + roomList.Count); //Increase the number of times entered game PlayerPrefs.SetInt(PREFTYPE.NUM_OF_ENTERGAME.ToString(), PlayerPrefs.GetInt(PREFTYPE.NUM_OF_ENTERGAME.ToString(), 0) + 1); //Debug.Log("LEFT: " + room.GetComponent<RoomScript>().GetIsLocked(DIRECTION.LEFT)); //Debug.Log("UP: " + room.GetComponent<RoomScript>().GetIsLocked(DIRECTION.UP)); //Debug.Log("RIGHT: " + room.GetComponent<RoomScript>().GetIsLocked(DIRECTION.RIGHT)); //Debug.Log("DOWN: " + room.GetComponent<RoomScript>().GetIsLocked(DIRECTION.DOWN)); }
// Use this for initialization //172.21.134.118 void Start() { //Random.Range(1, 1); //wad = new ArrayList(); Debug.Log("PuzzleRoomStart"); roomScript = this.GetComponent <RoomScript>(); //playersList = GameObject.FindGameObjectsWithTag("Player"); //Debug.Log("numPlayer: " + playersList.Length); //for (int i = 0; i < playersList.Length; i++) //{ // if (playersList[i].GetComponent<NetworkIdentity>().isLocalPlayer == true) // { // player = playersList[i]; // break; // } //} player = Global.Instance.player; if (!isPosSet || player.GetComponent <NetworkIdentity>().isServer) { //Debug.Log("IS SETTING AGN"); ObjectivePos.Set(Random.Range((transform.position.x - transform.localScale.x * 0.5f + 2.0f), transform.position.x), Random.Range((transform.position.y - transform.localScale.y * 0.5f + 2.0f), (transform.position.y + transform.localScale.y * 0.5f - 2.0f)), 0); TargetPos.Set(Random.Range((transform.position.x + transform.localScale.x * 0.5f - 2.0f), transform.position.x), Random.Range((transform.position.y - transform.localScale.y * 0.5f + 2.0f), (transform.position.y + transform.localScale.y * 0.5f - 2.0f)), 0); //transform.GetChild(0).position = ObjectivePos; transform.GetChild(0).position = TargetPos; if (player.GetComponent <NetworkIdentity>().isServer) { spawnedObj = genericSpawner.GetComponent <GenericSpawner>().SpawnObject(ObjectivePos, objective); //put the obj as child of room spawnedObj.transform.SetParent(this.gameObject.transform); } } if (player.GetComponent <NetworkIdentity>().isServer) { MessageHandler.Instance.SendPushPuzzle_S2C(1, roomScript.GetRoomID(), ObjectivePos, TargetPos); } //else //{ // Debug.Log("pushRommId: " + roomScript.GetRoomID()); // MessageHandler.Instance.SendPushPuzzle_C2S(roomScript.GetRoomID()); //} //doorList.Add(roomScript.GetIsLocked(DIRECTION.LEFT)) ; //doorList.Add(roomScript.GetIsLocked(DIRECTION.RIGHT)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.UP)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.DOWN)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.LEFT), roomScript.GetHasTriggerBox(DIRECTION.LEFT), DIRECTION.LEFT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.RIGHT), roomScript.GetHasTriggerBox(DIRECTION.RIGHT), DIRECTION.RIGHT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.UP), roomScript.GetHasTriggerBox(DIRECTION.UP), DIRECTION.UP)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.DOWN), roomScript.GetHasTriggerBox(DIRECTION.DOWN), DIRECTION.DOWN)); elapsedTime = 0.0f; timer = 5.0f; style = new GUIStyle(); content = new GUIContent(); puzzleComplete = false; isCompleted = false; isLock = false; Debug.Log("minDist: " + (transform.localScale.x * 0.5f - 2.0f)); }
// Use this for initialization void Start() { //Random.Range(1, 1); //wad = new ArrayList(); player = Global.Instance.player; OriginalGroup = this.transform.GetChild(0); ChangedGroup = this.transform.GetChild(1); int randIndex = 0; Color newColor = new Color(1, 1, 1); if (player.GetComponent <NetworkIdentity>().isServer) { for (int i = 0; i < OriginalGroup.childCount; ++i) { Vector3 newPos = new Vector3(Random.Range(transform.position.x - transform.localScale.x * 0.5f + 2.5f, transform.position.x - 2.5f), Random.Range(transform.position.y - transform.localScale.y * 0.5f + 2.5f, transform.position.y + transform.localScale.y * 0.5f - 2.5f), 1); OriginalGroup.GetChild(i).position = newPos; newPos.x += transform.localScale.x * 0.5f; ChangedGroup.GetChild(i).position = newPos; } randIndex = Random.Range(0, 4); changedObject = ChangedGroup.GetChild(randIndex).gameObject; newColor = changedObject.GetComponent <SpriteRenderer>().color; newColor.r = Random.Range(0.0f, 1.0f); newColor.g = Random.Range(0.0f, 1.0f); newColor.b = Random.Range(0.0f, 1.0f); newColor.a = Random.Range(0.0f, 1.0f); changedObject.GetComponent <SpriteRenderer>().color = newColor; } roomScript = this.GetComponent <RoomScript>(); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.LEFT), roomScript.GetHasTriggerBox(DIRECTION.LEFT), DIRECTION.LEFT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.RIGHT), roomScript.GetHasTriggerBox(DIRECTION.RIGHT), DIRECTION.RIGHT)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.UP), roomScript.GetHasTriggerBox(DIRECTION.UP), DIRECTION.UP)); doorInfoList.Add(new DoorInfo(roomScript.GetIsLocked(DIRECTION.DOWN), roomScript.GetHasTriggerBox(DIRECTION.DOWN), DIRECTION.DOWN)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.LEFT)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.RIGHT)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.UP)); //doorList.Add(roomScript.GetIsLocked(DIRECTION.DOWN)); //if (spotPuzzleMsg != null) // RepositionObjectClient(spotPuzzleMsg); elapsedTime = 0.0f; puzzleComplete = false; isCompleted = false; isLock = false; style = new GUIStyle(); content = new GUIContent(); //if is host/server if (player.GetComponent <NetworkIdentity>().isServer) { //send msg to clients SpotPuzzleRoomMessage message = new SpotPuzzleRoomMessage(); message.roomId = roomScript.GetRoomID(); message.shape01_pos = OriginalGroup.GetChild(0).position; message.shape02_pos = OriginalGroup.GetChild(1).position; message.shape03_pos = OriginalGroup.GetChild(2).position; message.shape04_pos = OriginalGroup.GetChild(3).position; message.changedObjectIndex = randIndex; message.changedObjectColor = newColor; MessageHandler.Instance.SendSpotPuzzle_S2C(message); } }