public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); switch (version) { case 0: { m_Active = reader.ReadBool(); m_Creatures = reader.ReadBool(); m_CombatCheck = reader.ReadBool(); m_CloseDelay = reader.ReadInt(); m_Doors = (DoorSet)reader.ReadInt(); m_FaceValue = reader.ReadInt(); m_Keyword = reader.ReadInt(); m_Range = reader.ReadInt(); m_Substring = reader.ReadString(); m_QuickClose = reader.ReadBool(); m_Timer = new InternalTimer(this, m_CloseDelay); if (this.Open) { m_Timer.Start(); } break; } } }
// Builds a 1x1 room. void BuildRoom1(int x, int y, int [,] map) { Tile[,] room = Border(tileA, new Tile[RWIDTH, RHEIGHT]); DoorSet ds = Doors(x, y, map); if (ds.left) { room[0, 1] = null; room[0, 2] = null; } if (ds.right) { room[7, 1] = null; room[7, 2] = null; } if (ds.bottom) { room[3, 0] = null; room[4, 0] = null; } if (ds.top) { room[3, 5] = null; room[4, 5] = null; } PlaceRoom((x - map.GetLength(0) / 2) * RWIDTH, (y - map.GetLength(1) / 2) * RHEIGHT, room); }
public static void StartDoor(DoorSet[] Doors) { for (int i = 0; i < Doors.Length; i++) { DoorSet door = Doors[i]; BoxCollider2D[] doorObjectColliders = door.DoorObject.GetComponents <BoxCollider2D>(); if (doorObjectColliders.Length != 2) { Debug.Log("HEY! " + door.name + " requires 2 (two) Boxcolliders, not " + doorObjectColliders.Length + "."); continue; } door.Doorway1 = doorObjectColliders[0]; door.Doorway2 = doorObjectColliders[1]; door.Doorway1.isTrigger = true; door.Doorway2.isTrigger = true; if (door.animator != null) { door.animator.speed = 0; } } }
void Update() { Vector2 playerPosition = player.transform.position; if (hasRecentlyFallen) { hasRecentlyFallen = player.isFalling; } for (int i = 0; i < Doors.Length; i++) { DoorSet door = Doors[i]; if (door.isFloorHole && hasRecentlyFallen) { return; } bool playerWasTeleported = door.EnterDoor(player); if (door.isFloorHole && playerWasTeleported) { hasRecentlyFallen = true; } } }
// Builds a 2x2 room. void BuildRoom4(int x, int y, int [,] map) { Tile[,] room = Border(tileA, new Tile[RWIDTH * 2, RHEIGHT * 2]); DoorSet ds = Doors(x, y, map); if (ds.left) { room[0, 1] = null; room[0, 2] = null; } if (ds.right) { room[15, 1] = null; room[15, 2] = null; } if (ds.bottom) { room[3, 0] = null; room[4, 0] = null; } if (ds.top) { room[3, 11] = null; room[4, 11] = null; } if (ds.uleft) { room[0, 7] = null; room[0, 8] = null; } if (ds.uright) { room[15, 7] = null; room[15, 8] = null; } if (ds.rbottom) { room[11, 0] = null; room[12, 0] = null; } if (ds.rtop) { room[11, 11] = null; room[12, 11] = null; } PlaceRoom((x - map.GetLength(0) / 2) * RWIDTH, (y - map.GetLength(1) / 2) * RHEIGHT, room); }
public static DoorSet GetDoor(DoorSet[] doors, string name, Collider2D coll) { for (int i = 0; i < doors.Length; i++) { DoorSet door = doors[i]; if (door.name == name || (coll != null && (door.Doorway1 == coll || door.Doorway2 == coll))) { return(door); } } return(null); }
// Create a struct to represent the doors in a given room. DoorSet Doors(int x, int y, int [,] map) { DoorSet ds = new DoorSet(); ds.bottom = false; ds.top = false; ds.left = false; ds.right = false; ds.rbottom = false; ds.rtop = false; ds.uleft = false; ds.uright = false; // Check the possible doors for each room type and store them in the struct. // Recall that in the tilemap, y increases upwards and x rightwards. switch (map[x, y]) { case 1: ds.bottom = RoomCheck(x, y - 1, map); ds.top = RoomCheck(x, y + 1, map); ds.left = RoomCheck(x - 1, y, map); ds.right = RoomCheck(x + 1, y, map); break; case 2: ds.bottom = RoomCheck(x, y - 1, map); ds.top = RoomCheck(x, y + 1, map); ds.rbottom = RoomCheck(x + 1, y - 1, map); ds.rtop = RoomCheck(x + 1, y + 1, map); ds.left = RoomCheck(x - 1, y, map); ds.right = RoomCheck(x + 2, y, map); break; case 4: ds.bottom = RoomCheck(x, y - 1, map); ds.top = RoomCheck(x, y + 2, map); ds.rbottom = RoomCheck(x + 1, y - 1, map); ds.rtop = RoomCheck(x + 1, y + 2, map); ds.left = RoomCheck(x - 1, y, map); ds.right = RoomCheck(x + 2, y, map); ds.uleft = RoomCheck(x - 1, y + 1, map); ds.uright = RoomCheck(x + 2, y + 1, map); break; } return(ds); }
void Update() { Debug.Log("GameStatus = " + status); switch (status) { case GameStatus.Playing: Time.timeScale = 1.0f; break; case GameStatus.Pause: Time.timeScale = 0.0f; break; case GameStatus.SwitchScene: int previousDoor = PlayerPrefs.GetInt("EnterDoorNum"); PlayerPrefs.SetInt("EnterDoorNum", -1); int currentDoor = OppositeDoor(previousDoor); //设置角色位置 GetDoorPos(); int currentRoom = RoomPointer.Instance.GetNumber(); MapSet roomMap = GameObject.Find("MapBuilder").GetComponent <MapSet>(); DoorSet doors = roomMap.stages[currentRoom].GetComponentInChildren <DoorSet>(); //获得入门位置 Vector2 targetPos = doors.enterPoses[currentDoor].position; playerTransform.position = targetPos; //设置角色停止 playerCtrl.Stop(); //关闭按键监听 playerCtrl.enabled = false; StartCoroutine(WaitForSwitchDone()); //脱离状态 status = GameStatus.SwitchNotDetect; break; case GameStatus.SwitchNotDetect: break; case GameStatus.SwitchDone: GameObject.FindGameObjectWithTag("ActiveDoor").tag = "NoActiveDoor"; break; default: break; } //Debug.Log("Current Room :" + RoomPointer.Instance.GetNumber()); }
void GetDoorPos() { doorSet = GameObject.Find("Doors").GetComponent <DoorSet>(); }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>(); DoorSet.StartDoor(Doors); }
void OnEnable() { doorset = (DoorSet)target; }