Ejemplo n.º 1
0
    /// <summary>
    /// Triggers the end level.
    /// </summary>
    /// <param name="triggerName">Trigger name.</param>
    public void triggerEndLevel(string triggerName)
    {
        string nextLevel = "";

        if (triggerName.Contains("Air"))
        {
            airLevelComplete = true;
            // Track the end air time
            totalStats.endAirTime = Time.time;
            nextLevel             = "FireRoom";
        }
        else if (triggerName.Contains("Fire"))
        {
            fireLevelComplete = true;
            // Track the end fire time
            totalStats.endFireTime = Time.time;
            nextLevel = "WaterRoom";
        }
        else if (triggerName.Contains("Water"))
        {
            waterLevelComplete = true;
            // Track the end water time
            totalStats.endWaterTime = Time.time;
            nextLevel = "ComboRoom";
        }
        else if (triggerName.Contains("Combo"))
        {
            comboLevelComplete = true;
            // Track the end combo time
            totalStats.endComboTime = Time.time;
            // Track the end time
            totalStats.endTime = Time.time;
            nextLevel          = "NinjaMorph";
        }
        // Disable control for the time being
        setControllable(false);
        // Enable the Stats UI
        statsUI.SetActive(true);
        // Set the next level
        statsUI.GetComponentInChildren <StatsMenuHandler> ().nextLevel = nextLevel;
        // Transfer relevant stats to the total stats
        totalStats.transferLevelSpecificStats(ninjaController.currentStats);
        // Set the stats
        statsUI.GetComponentInChildren <ShowStats> ().setStats(nextLevel, ninjaController.currentStats, totalStats);
        // Reset the ninja controller stats
        ninjaController.currentStats = new StatsInfo();
        // Enable the Stats UI
        showStats = true;
        // Disable the ability to pause
        pauseScript.allowed = false;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Checks for the game over.
    /// </summary>
    void CheckGameOver()
    {
        // Check for ninja zen being less than 0
        if (ninjaController.getZen() <= 0.0f)
        {
            gameActive = false;
            // Set the stats data
            currentStats.endTime = Time.time;
            currentStats.transferLevelSpecificStats(ninjaController.currentStats);
            ninjaController.currentStats = new StatsInfo();
            StartCoroutine(GameOver());
        }
        // Still alive
        else
        {
            // Check for level completion
            if (!airLevelComplete)
            {
                if (totalStats.startAirTime < 0.0f)
                {
                    totalStats.startAirTime = Time.time;
                }

                if (airLevelComplete)
                {
                    ninjaController.createMessage("Air Room complete!");
                }
            }
            else if (!fireLevelComplete)
            {
                if (totalStats.startFireTime < 0.0f)
                {
                    totalStats.startFireTime = Time.time;
                }

                if (Application.loadedLevelName == "FireRoom")
                {
                    if (firePuzzle == null)
                    {
                        return;
                    }
                    InteractiveObject[] objects = firePuzzle.GetComponentsInChildren <InteractiveObject>();
                    int numberLit = 0;
                    foreach (InteractiveObject io in objects)
                    {
                        if (io.getObjectType() == ObjectType.Fire)
                        {
                            numberLit++;
                            if (!torchOrder.Contains(io.gameObject.name))
                            {
                                torchOrder.Add(io.gameObject.name);
                            }
                        }
                    }
                    if (numberLit == objects.Length)
                    {
                        fireLevelComplete = true;
                        for (int i = 0; i < torchOrder.Count; i++)
                        {
                            string name = (string)torchOrder[i];
                            if (!name.Contains(i.ToString()))
                            {
                                ninjaController.createMessage("Incorrect order!");
                                fireLevelComplete = false;
                                break;
                            }
                        }
                        if (fireLevelComplete)
                        {
                            // Find all of the crates and allow them to be moved.
                            Rigidbody[] crates = GameObject.FindGameObjectWithTag("Crates").GetComponentsInChildren <Rigidbody>();
                            foreach (Rigidbody crate in crates)
                            {
                                crate.isKinematic = false;
                            }

                            // Make the cannon ball fire
                            Bullet cannonBall = GameObject.FindGameObjectWithTag("Cannon Ball").GetComponent <Bullet>();
                            cannonBall.speed = 0.3f;

                            ninjaController.createMessage("Fire Room complete!");
                        }
                        else
                        {
                            // Clear fire from torches
                            foreach (InteractiveObject io in objects)
                            {
                                io.removeFire();
                            }
                            // Clear the order
                            torchOrder.Clear();
                            // Increment the failure count
                            totalStats.failedFirePuzzles++;
                        }
                    }
                }
            }
            else if (!waterLevelComplete)
            {
                if (totalStats.startWaterTime < 0.0f)
                {
                    totalStats.startWaterTime = Time.time;
                }

                if (Application.loadedLevelName == "WaterRoom")
                {
                    int       numberFilled = 0;
                    ArrayList bucketWaters = new ArrayList(4);
                    ArrayList triggers     = new ArrayList(4);

                    if (waterPuzzle == null)
                    {
                        return;
                    }
                    WaterPuzzleTimer wptimer = waterPuzzle.GetComponent <WaterPuzzleTimer>();

                    //fill up arrays with waters and fill triggers, and keep track of which buckets are filled
                    for (int i = 0; i < bucketWaters.Capacity; i++)
                    {
                        bucketWaters.Add(GameObject.Find("Fillable Bucket " + i).transform.FindChild("bucket_water").GetComponent <InteractiveObject>());
                        triggers.Add(((InteractiveObject)bucketWaters[i]).transform.parent.Find("bottom_trigger" + i).GetComponent <FillableObject>());
                        if (((FillableObject)triggers[i]).filled)
                        {
                            numberFilled++;
                        }
                    }

                    if (!firstWaterMessage && wptimer.getStarted())
                    {
                        ninjaController.createMessage("Fill the buckets before time runs out! You have 30 seconds left!");
                        firstWaterMessage = true;
                    }

                    if (wptimer.getTimer() >= 30.0f)
                    {
                        //clear the buckets
                        foreach (FillableObject fo in triggers)
                        {
                            fo.clearBucket();
                            fo.filled = false;
                        }
                        //restart timer
                        wptimer.setTimer(0.0f);
                        wptimer.setStarted(false);
                        firstWaterMessage = false;
                        timerThreshhold   = 5;
                        //tell user he/she ran out of time
                        ninjaController.createMessage("You ran out of time!");
                        totalStats.failedWaterPuzzles++;
                    }
                    else if (wptimer.getStarted() && wptimer.getTimer() > timerThreshhold)
                    {
                        ninjaController.createMessage("You have " + (30 - timerThreshhold) + " seconds left!");
                        timerThreshhold += 5;
                    }
                    else if (numberFilled == bucketWaters.Capacity)
                    {
                        //tell them they've completed the room
                        ninjaController.createMessage("Water Room complete!");
                        waterLevelComplete = true;
                        GameObject.Destroy(GameObject.Find("Exit Door"));
                    }
                }
            }
            else if (!comboLevelComplete)
            {
                if (totalStats.startComboTime < 0.0f)
                {
                    totalStats.startComboTime = Time.time;
                }

                if (Application.loadedLevelName == "ComboRoom")
                {
                    if (comboPuzzle == null)
                    {
                        return;
                    }

                    // Check the buckets if not complete already
                    if (!bucketsComplete)
                    {
                        int filledBuckets = 0;
                        // Find all fillable objects
                        FillableObject[] objects = comboPuzzle.GetComponentsInChildren <FillableObject>();
                        foreach (FillableObject fo in objects)
                        {
                            if (fo.filled)
                            {
                                filledBuckets++;
                            }
                        }
                        // Buckets complete
                        if (filledBuckets == 2)
                        {
                            bucketsComplete = true;
                            // Find crane
                            GameObject crane = null;
                            foreach (Transform tran in comboPuzzle.GetComponentsInChildren <Transform>())
                            {
                                if (tran.gameObject.name == "Crane")
                                {
                                    crane = tran.gameObject;
                                    break;
                                }
                            }
                            // Transition the crane into position
                            iTween.RotateTo(crane, new Vector3(270.0f, 160.0f, 0.0f), 5.0f);
                        }
                    }

                    // Check the torches if not complete already
                    if (!torchesComplete)
                    {
                        // Find elevator
                        GameObject elevator = null;
                        foreach (Transform tran in comboPuzzle.GetComponentsInChildren <Transform>())
                        {
                            if (tran.gameObject.name == "Elevator")
                            {
                                elevator = tran.gameObject;
                                break;
                            }
                        }
                        // Find all interactive objects
                        InteractiveObject[] objects = comboPuzzle.GetComponentsInChildren <InteractiveObject>();
                        int numberLit = 0;
                        foreach (InteractiveObject io in objects)
                        {
                            if (io.getObjectType() == ObjectType.Fire)
                            {
                                numberLit++;
                            }
                        }
                        // Torches complete
                        if (numberLit == 2)
                        {
                            torchesComplete = true;
                            // Transition the elevator into position (from -33,60,-22 to -33,35,-22)
                            StartCoroutine(MoveElevator(elevator, new Vector3(-33.0f, 35.0f, -22.0f), 5.0f));
                        }
                    }
                }
            }
            else
            {
                // Create a message
                ninjaController.createMessage("Level Complete!");
                triggerEndLevel("Combo");
                // Reset the puzzles
                waterLevelComplete = false;
                airLevelComplete   = false;
                fireLevelComplete  = false;
                comboLevelComplete = false;
            }
        }
    }