// Handles movement of player. void MovePlayer() { // If this orca is above sea, and isAbove is false, this must be the orca's first frame above the water. if ((transform.position.y > seaLevel) && (!isAbove)) { splashController2.SetPos(transform.position.x); splashController2.Active(); playerAnim.speed = 0; playerAnim.Play(0, -1, 0.5f); speedDelta = 0; gravY = transform.right.y * speed; isAbove = true; outside_splash_source.PlayOneShot(outside_splash_source.clip, 1f); underwater_ambience.volume = 0; outside_ambience.volume = 0.85f; exitDegrees = degrees; waveCollision = false; timer = 0; transform.position += new Vector3(transform.right.x * speed * Time.deltaTime, gravY * Time.deltaTime); } // If orca is above sea, and has been for at least 1 frame, constantly reduce y velocity (applying gravity). else if ((transform.position.y > seaLevel)) { gravY -= gravConst; transform.position += new Vector3(transform.right.x * speed * Time.deltaTime, gravY * Time.deltaTime); tempRightVecX = transform.right.x; tempRightVecY = gravY / speed; // Following if statements check the y position of the player, and change music accordingly if (transform.position.y >= 70) { outside_ambience.volume = (110 - transform.position.y) / 50; } if (transform.position.y > 110) { if (!space_ambience.isPlaying) { space_ambience.Play(); } space_ambience.volume = (transform.position.y - 110) / 30; } // Following if statements check if y position of player is above a certain point, then if planet reaching trick associated with that point has been added. // If not, the trick is added. if ((transform.position.y > 150) && !spaceObjects[0]) { trickTrackController.AddElement("Moon Man!", 10000); spaceObjects[0] = true; } if ((transform.position.y > 300) && !spaceObjects[1]) { trickTrackController.AddElement("Musk!", 20000); spaceObjects[1] = true; } if ((transform.position.y > 450) && !spaceObjects[2]) { trickTrackController.AddElement("Red Eye!", 50000); spaceObjects[2] = true; } if ((transform.position.y > 600) && !spaceObjects[3]) { trickTrackController.AddElement("The Ring!", 75000); spaceObjects[3] = true; } if ((transform.position.y > 720) && !spaceObjects[4]) { trickTrackController.AddElement("The Bounty!", 150000); spaceObjects[4] = true; } } // If entrance to water occured this frame. else if ((transform.position.y <= seaLevel) && (isAbove)) { // Indicate orca is below sea level isAbove = false; // Underwater ambience should play below the water, set volumes accordingly outside_ambience.volume = 0; underwater_ambience.volume = 1; degDifference = 360 - degrees; playerAnim.speed = playerAnimSpeed; splashController1.SetPos(transform.position.x); splashController1.Active(); splash_source.PlayOneShot(splash_source.clip, 1f); spaceObjects = new bool[10]; // If incorrect entrance angle, reset speed, cancel current tricks, reset speed, and set timer if ((exitDegrees > (degDifference + entryAngleLenience)) || (exitDegrees < (degDifference - entryAngleLenience)) || ((degrees > 0) && (degrees < 180))) { timer = 75; speed = 10; speedDelta = speed; trickTrackController.ResetListSplash(); waveCollision = true; transform.position += new Vector3(tempRightVecX * speed * Time.deltaTime, tempRightVecY * speed * Time.deltaTime); } // If correct angle, increase speed and enact score increase else { speed += speedInc; trickTrackController.AddElement("Smooth entrance!", 500); scoreResetTimer = 70; if (speed > speedLimit) { speed = speedLimit; } if (speed > 50) { enterTimer = enterTimerSet1; inEnterTimer = enterTimer; } else { enterTimer = enterTimerSet2; inEnterTimer = enterTimer; } transform.position += new Vector3(tempRightVecX * speed * Time.deltaTime, tempRightVecY * speed * Time.deltaTime); } } // If the orca's current position indicates it is in water, between the sea and the sand else if ((sandLevel < transform.position.y) && (transform.position.y <= seaLevel)) { // Ensure orca stops if timer has reach 0 and game is about to end if (stop) { playerAnim.speed = 0; // Add score from current tricks if smooth entrance was made but timer for score addition not yet zero (scoreResetTimer only set in case of smooth entrance) if (scoreResetTimer > 0) { trickTrackController.ResetListSmooth(); } return; } // If timer is above 25, the orca is slowed. if (timer > 25) { speedDelta -= speed / 50; playerAnimSpeed = (float)(maxTimer - timer) / (float)maxTimer; playerAnim.speed = playerAnimSpeed; timer--; if (timer == 25) { speedDelta = 0; } // Increment position with entrance vector components and decreasing speed if incorrect angle entrance (wave collision) has been made if (waveCollision) { transform.position += new Vector3(tempRightVecX * speedDelta * Time.deltaTime, tempRightVecY * speedDelta * Time.deltaTime); } else { transform.position += added * speedDelta * Time.deltaTime; } } // If timer is equal to or below 25, the orca is speed back up. else if (timer > 0) { transform.rotation = Quaternion.Euler(Vector3.forward * degrees); playerAnimSpeed = (float)(maxTimer - timer) / (float)maxTimer; playerAnim.speed = playerAnimSpeed; speed = 10; speedDelta += speed / 26; timer--; transform.position += new Vector3(transform.right.x * speedDelta * Time.deltaTime, transform.right.y * speedDelta * Time.deltaTime); if (timer == 0) { waveCollision = false; } } // If enterTimer is above 0, the orca has recently entered and its movement vector must be changed slowly. else if (enterTimer > 0) { // Rotate as normal. transform.rotation = Quaternion.Euler(Vector3.forward * degrees); // x and y components of to hold incremental change to orca direction based on enterTimer progression. smoothRightVecX = ((tempRightVecX * (float)enterTimer) + (transform.right.x) * ((float)inEnterTimer - (float)enterTimer)) / (float)inEnterTimer; smoothRightVecY = ((tempRightVecY * (float)enterTimer) + (transform.right.y) * ((float)inEnterTimer - (float)enterTimer)) / (float)inEnterTimer; transform.position += new Vector3(smoothRightVecX * speed * Time.deltaTime, smoothRightVecY * speed * Time.deltaTime); // If the orca is in the sand, it should be moved above the sand, then continue as if it had collided with the sand. if (transform.position.y <= sandLevel) { SandCollision(); } // exitDegrees = degrees; enterTimer--; // Timer to reset score should be decreased after newly entering sea - if 0, reset the trick list and add score if (scoreResetTimer > 0) { scoreResetTimer--; } else { // Only reset if trick has been added if (trickTrackController.Exists()) { trickTrackController.ResetListSmooth(); } } } // In water, no current timers, so move normally. else if (enterTimer == 0) { // Ensure rotation changes according to degree change that occurs due to player input. transform.rotation = Quaternion.Euler(Vector3.forward * degrees); transform.position += transform.right * speed * Time.deltaTime; if (transform.position.y <= sandLevel) { SandCollision(); } // Timer to reset score should be decreased - if 0, reset the trick list and add score if (scoreResetTimer > 0) { scoreResetTimer--; } else { // Only reset if trick has been added if (trickTrackController.Exists()) { trickTrackController.ResetListSmooth(); } } } } }