// Entire Wallmaster movement, destroys self at the end of game // NOTICE: linkLocation is the localPosition of the trap public IEnumerator GrabLink(Vector3 linkLocation) { Debug.Log("Grab Link function begun"); Vector3 startLocation = Vector3.zero; if (linkLocation.y == 2) { // Bottom edge of the room startLocation.y = 33; startLocation.x = linkLocation.x + 64 + distanceFrom[Random.Range(0, distanceFrom.Length)]; firstDirection = Vector3.up; secondDirection = Vector3.left; flippedX = true; flippedY = false; } else if (linkLocation.y == 8) { // Top edge of the room startLocation.y = 43; startLocation.x = linkLocation.x + 64 + distanceFrom[Random.Range(0, distanceFrom.Length)]; firstDirection = Vector3.down; secondDirection = Vector3.left; flippedY = true; flippedX = true; } else if (linkLocation.x == 2) { // Left edge of the room startLocation.x = 64; startLocation.y = linkLocation.y + 33 - distanceFrom[Random.Range(0, distanceFrom.Length)]; firstDirection = Vector3.right; secondDirection = Vector3.up; flippedX = false; flippedY = false; } else if (linkLocation.x == 13) { // Right edge of the room startLocation.x = 79; startLocation.y = linkLocation.y + 33 - distanceFrom[Random.Range(0, distanceFrom.Length)]; firstDirection = Vector3.left; secondDirection = Vector3.up; flippedX = true; flippedY = false; } else { Debug.Log("ERROR::INVALID_POSITION_WALLMASTER_TRAP"); yield break; } // Place wallmaster in correct start position & begin moving transform.localPosition = startLocation; anim = StartCoroutine(WallmasterAnimation()); // Wallmaster move animation for (float firstDistMoved = 0; firstDistMoved < 2; firstDistMoved += wallmasterSpeed * Time.deltaTime) { while (!canMove) { yield return(null); } rb.velocity = firstDirection * wallmasterSpeed; yield return(null); } for (float secondDistMoved = 0; secondDistMoved < 3; secondDistMoved += wallmasterSpeed * Time.deltaTime) { while (!canMove) { yield return(null); } rb.velocity = secondDirection * wallmasterSpeed; yield return(null); } for (float firstDistMoved = 0; firstDistMoved < 2.5; firstDistMoved += wallmasterSpeed * Time.deltaTime) { while (!canMove) { yield return(null); } rb.velocity = -firstDirection * wallmasterSpeed; yield return(null); } rb.velocity = Vector3.zero; isBusy = false; StopCoroutine(anim); if (hasCaptured) { // TODO: Set respawnRequirement to true // TODO: Animation change to beginning of room cam.transform.position = cam.GetComponent <CameraController>().initPosition; playerAttacked.is_captured = false; player.transform.position = cam.GetComponent <CameraController>().initPlayerPosition; utility.WallmasterReset(); // Indicator that the room has been left by link } // TODO: Anything else to do at the end of movement? }