void MoveCarToOtherPortal() { previousPuzzlePiece = currentPuzzlePiece; currentPuzzlePiece = GameScript().GetOtherPortalPiece (currentPuzzlePiece); currentPuzzlePieceConnections = PuzzlePieceScript.PuzzlePieceConnections.GetPuzzlePieceConnections (currentPuzzlePiece); int startSide = PuzzlePieceScript.GetSideOfPortal (currentPuzzlePiece); currentConnection = currentPuzzlePieceConnections.getConnectionForSide (startSide); currentDirection = currentConnection.OtherSide (startSide); currentCoordinateIndex = currentConnection.getFirstCoordinateIndexFor (currentDirection); currentCoordinateIndex = currentConnection.getNextCoordinateIndex (currentCoordinateIndex, currentDirection); currentCoordinate = currentConnection.coordinates [currentCoordinateIndex]; Vector3 newPosition = new Vector3(currentPuzzlePiece.transform.position.x, transform.position.y, currentPuzzlePiece.transform.position.z); Vector3 newEulerAngles = transform.eulerAngles; if (currentDirection == PuzzlePieceScript.Coordinate.NORTH) newEulerAngles.y = 0f; else if (currentDirection == PuzzlePieceScript.Coordinate.EAST) newEulerAngles.y = 90f; else if (currentDirection == PuzzlePieceScript.Coordinate.SOUTH) newEulerAngles.y = 180f; else if (currentDirection == PuzzlePieceScript.Coordinate.WEST) newEulerAngles.y = -90f; if (ExplorerLevel ()) mainCamera.position = new Vector3 (mainCamera.position.x + (newPosition.x - transform.position.x), mainCamera.position.y, mainCamera.position.z + (newPosition.z - transform.position.z)); transform.position = newPosition; transform.eulerAngles = newEulerAngles; enteredPortalPiece = false; MenuScript.PlayPortalOutSound (); }
void UpdateCarPosition() { float r_x = currentCoordinate.x; float r_z = currentCoordinate.z; PuzzlePieceScript.Coordinate targetCoord = PuzzlePieceScript.Coordinate.GetCoordinateFor (r_x, r_z, currentPuzzlePiece, levelConfiguration.PieceSize); float x = targetCoord.x; float z = targetCoord.z; MoveTowardsTarget (x, z); float currentX = PointOfCar ().x; float currentZ = PointOfCar ().z; Boolean enteredShopPiece = false; Boolean enteredSavePiece = false; int explorerModeTriggerPiece = -1; if (Math.Abs (currentX - x) < 0.01f && Math.Abs (currentZ - z) < 0.01f) { // Get the next coordinate currentCoordinateIndex = currentConnection.getNextCoordinateIndex (currentCoordinateIndex, currentDirection); GameObject puzzleBoxObtained = null; if (currentCoordinateIndex == currentConnection.coordinates.Length || currentCoordinateIndex == -1) { timeSinceOnLastPuzzlePiece = 0f; clickedButtonWhileOnCurrentPuzzlePiece = false; // Check if the end piece is nearby if (AtEndPiece ()) return; if (enteredPortalPiece) { MoveCarToOtherPortal(); return; } // Get the next puzzle piece previousPuzzlePiece = currentPuzzlePiece; Debug.Log (previousPuzzlePiece); currentPuzzlePiece = ClosestPuzzlePiece (previousPuzzlePiece); Debug.Log (currentPuzzlePiece); if (currentPuzzlePiece == null) { falling = true; return; } distanceMovedSinceStartPuzzlePiece = new Vector3(); if (ExplorerLevel()) { if (currentPuzzlePiece.tag == "UnmovablePuzzlePiece") enteredSavePiece = true; if (gameScript.ShopTriggerPiece(currentPuzzlePiece.name)) enteredShopPiece = true; if (currentPuzzlePiece.name == "puzzlePiece_straight_WE (7)") explorerModeTriggerPiece = 2; if (currentPuzzlePiece.name == "puzzlePiece_straight_WE (20)") explorerModeTriggerPiece = 3; puzzleBoxObtained = gameScript.GetPuzzleBoxForPuzzlePiece(currentPuzzlePiece.name); } if (!PuzzlePieceScript.PuzzlePieceConnections.HasPuzzlePieceConnections (currentPuzzlePiece) || OnOpenBridgePiece(currentPuzzlePiece)) { crashing = true; StopEngineSound(); PlayCrashSound(); return; } enteredPortalPiece = currentPuzzlePiece.name.Contains("portal") && !EnteredPortalPieceFromWrongSide(); currentPuzzlePieceConnections = PuzzlePieceScript.PuzzlePieceConnections.GetPuzzlePieceConnections (currentPuzzlePiece); int startSide = currentCoordinate.InverseSide (currentDirection); currentConnection = currentPuzzlePieceConnections.getConnectionForSide (startSide); if (currentConnection == null) { crashing = true; StopEngineSound(); PlayCrashSound (); return; } currentDirection = currentConnection.OtherSide (startSide); currentCoordinateIndex = currentConnection.getFirstCoordinateIndexFor (currentDirection); // Get the next one, because the first one of the new piece is the same as the last of the previous piece. currentCoordinateIndex = currentConnection.getNextCoordinateIndex (currentCoordinateIndex, currentDirection); } currentCoordinate = currentConnection.coordinates [currentCoordinateIndex]; RotateTowardsTarget (); if (enteredShopPiece) { gameScript.Halt(); carStarted = false; gameScript.ShowShop(); } if (puzzleBoxObtained != null) { int index = 1; if (puzzleBoxObtained.name == "puzzleBoxWorld3") index = 2; gameScript.ShowFirstItemObtainedMessageIfIsFirstItem (); MenuScript.data.animationQueue.Enqueue(new Pair(puzzleBoxObtained.name, index)); GameObject.Destroy (puzzleBoxObtained); MenuScript.Save (); } if (enteredSavePiece) gameScript.RecordCurrentState(); if (explorerModeTriggerPiece != -1) gameScript.ShowExplorerModeMessage (explorerModeTriggerPiece); } CheckForNearbyButton(); }
public void StartTheGame(LevelConfiguration levelConfiguration) { this.levelConfiguration = levelConfiguration; currentPuzzlePiece = ClosestPuzzlePiece (null); if (ExplorerLevel ()) currentPuzzlePiece = ClosestPuzzlePiece (currentPuzzlePiece); currentPuzzlePieceConnections = PuzzlePieceScript.PuzzlePieceConnections.GetPuzzlePieceConnections (currentPuzzlePiece); currentConnection = currentPuzzlePieceConnections.getConnectionForSide (PuzzlePieceScript.Coordinate.WEST); currentDirection = currentConnection.OtherSide (PuzzlePieceScript.Coordinate.WEST); currentCoordinateIndex = currentConnection.getFirstCoordinateIndexFor (currentDirection); currentCoordinate = currentConnection.coordinates [currentCoordinateIndex]; buttons = GameObject.FindGameObjectsWithTag ("Button"); carStarted = true; PlayEngineSound (); }