void HandleLevelFinished(Message message)
    {
        LevelFinishedMessage mess = message as LevelFinishedMessage;

        endLevel = true;

        if (mess.Type == (int)LevelFinishedType.Win)
        {
            win = true;
            if (_score + displayScore > highscores[9])              // last score not added, needs displayScore
            {
                MessageCenter.Instance.Broadcast(new ScoreAddingMessage(true));
            }
        }
    }
    protected void HandleLevelFinishedMessage(Message message)
    {
        menu.GetComponent <MenuController>().enabled = true;
        for (int i = 0; i < menu.GetComponent <MenuController>().buttons.Length; i++)
        {
            menu.GetComponent <MenuController>().buttons[i].GetComponent <GUIButton>().enabled = true;
        }

        menu.GetComponent <MenuController>().buttons[1].GetComponent <GUIButton>().scene = GlobalGameStateManager.CurrentScene;

        LevelFinishedMessage mess = message as LevelFinishedMessage;

        if (mess.Type == LevelFinishedType.Loss)
        {
            switch (mess.Reason)
            {
            case LevelFinishedReason.MaxNPCsPanicked:
                this.enabled = true;
                this.message = "You have failed\n\nThe NPC noticed you and got scared";
                MessageCenter.Instance.Broadcast(new PauseChangedMessage(true));
                break;

            case LevelFinishedReason.PlayerDied:
                this.enabled = true;
                this.message = "You have failed\n\nYour tree was chopped down and made into evil little toothpicks";
                MessageCenter.Instance.Broadcast(new PauseChangedMessage(true));
                break;

            case LevelFinishedReason.TimerOut:
                this.enabled = true;
                this.message = "You have failed\n\nYou ran out of time";
                MessageCenter.Instance.Broadcast(new PauseChangedMessage(true));
                break;

            default:
                break;
            }
        }
        else if (mess.Type == LevelFinishedType.Win)
        {
            switch (mess.Reason)
            {
            case LevelFinishedReason.TargetNPCEaten:
                this.enabled = true;
                this.message = "You have won\n\nYour target has been consumed";
                MessageCenter.Instance.Broadcast(new PauseChangedMessage(true));
                break;

            case LevelFinishedReason.NumNPCsEaten:
                this.enabled = true;
                this.message = "You have won\n\nYour tree has feasted upon many souls";
                MessageCenter.Instance.Broadcast(new PauseChangedMessage(true));
                break;

            case LevelFinishedReason.TimerOut:
                this.enabled = true;
                this.message = "You have won\n\nYou survived the day";
                MessageCenter.Instance.Broadcast(new PauseChangedMessage(true));
                break;

            default:
                break;
            }
        }
    }
    public override void Update()
    {
        // Tutorial stuff
        if(TutorialManager.Instance.Phase == 1 || TutorialManager.Instance.Phase == 7 || TutorialManager.Instance.Phase == 13)
        {
            if (GlobalGameStateManager.SoulConsumedTimer <= 0f)
            {
                GlobalGameStateManager.PosessionState = PosessionState.EXORCISABLE;

                TutorialManager.Instance.AdvancePhase();
            }
        }

        if(TutorialManager.Instance.Phase == 17)
        {
            if (GlobalGameStateManager.SoulConsumedTimer <= 0f)
            {
                LevelFinishedMessage message = new LevelFinishedMessage(LevelFinishedType.Win, LevelFinishedReason.NumNPCsEaten);

                MessageCenter.Instance.Broadcast(message);
                TutorialManager.Instance.AdvancePhase();

                return;
            }
        }

        float bonusSpeed = (Tree.BonusSpeedTimer > 0f) ? 1.2f : 1f;

        // Update velocity
        Vector2 velocity = Vector2.zero;

        if (TutorialManager.Instance.Phase == 16)
        {
            velocity = new Vector2(Input.GetAxis("LSX"), Input.GetAxis("LSY")) * Tree.Speed * bonusSpeed * Time.deltaTime;

            // Handle keyboard
            if (Input.anyKey)
            {
                velocity = Vector2.zero;

                if (Input.GetKey(KeyCode.LeftArrow)) velocity.x = -1f;
                if (Input.GetKey(KeyCode.RightArrow)) velocity.x = 1f;
                if (Input.GetKey(KeyCode.UpArrow)) velocity.y = 1f;
                if (Input.GetKey(KeyCode.DownArrow)) velocity.y = -1f;

                velocity *= Tree.Speed * bonusSpeed * Time.deltaTime;
            }

            if (velocity != Vector2.zero)
            {
                // Get which frame the leg animation is on
                AnimatorStateInfo stateInfo = Tree.BodyParts.Legs.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0);
                float animationPercent = (stateInfo.normalizedTime % 1.0f);
                int currentLegFrame = Mathf.FloorToInt(animationPercent * 3f) + 1;

                //Debug.Log ("THERE IS ALSO SOMETHING BROKEN HERE!!!!!!!!!\nPLEASE FIX THIS!!!!\nI CAN\'T PLAY THE GAME WITH THIS LINE UNCOMMENTED\nMAKE SURE TO RUN YOUR CODE BEFORE PUSHING!!!!!\nNO CODE SHOULD BE PUSHED THAT REQUIRES UNCOMMENTING!!!!!\nTHIS IS IN FILE TreeStateActive.cs");

                if (!Tree.BodyParts.Trunk.audio.isPlaying && currentLegFrame != lastLegFrame)
                {
                    lastLegFrame = currentLegFrame;
                    walkAudio++;

                    Tree.BodyParts.Trunk.audio.clip = Tree.Sounds.Walk[walkAudio % Tree.Sounds.Walk.Length];

                    Tree.BodyParts.Trunk.audio.Play();
                }

            }
            else
            {
                Tree.audio.Stop();

				/*SoundManager soundManager = GameObject.FindObjectOfType<SoundManager>();
				soundManager.ResumeMusic();*/

                walkAudio = 1;
                lastLegFrame = -1;
            }
        }

        Tree.rigidbody2D.velocity = velocity;
        
        Vector3 grabOffset = Tree.transform.position + new Vector3(0f, 0.25f);

        // Update all NPC's that are within grabbing range
        foreach(GameObject npc in GameObject.FindGameObjectsWithTag("NPC"))
        {
            int listIndex = npcsInRange.IndexOf(npc);
            bool inRange = Vector3.Distance(Tree.transform.position, npc.transform.position) <= 1.5f;

            if(inRange && (listIndex == -1)) npcsInRange.Add(npc);
            else if (!inRange && (listIndex != -1))
            {
                npcsInRange.RemoveAt(listIndex);

                // Untag NPC if necessary
                npc.GetComponent<AIController>().IsTaggedByTree = false;
            }
        }

        // Show LT icons if NPCs are in range
        GameObject[] closestNPCs = GetTwoClosestNPCs();

        if (closestNPCs.Length == 1)
        {
            lt1.GetComponent<LTScript>().Initialize(closestNPCs[0]);
            lt2.GetComponent<LTScript>().Initialize(null);
        }
        else
        {
            lt1.GetComponent<LTScript>().Initialize(null);
            lt2.GetComponent<LTScript>().Initialize(null);
        }

        // Update LS arrow for tree B
        if (TutorialManager.Instance.Phase == 16)
        {
            Transform LS = TutorialManager.Instance.TutorialItems[11].transform;

            LS.position = Tree.transform.position + new Vector3(0f, -0.63f);

            if (velocity == Vector2.zero)
            {
                // Only show the arrow if we're not in range of an NPC
                if (npcsInRange.Count == 0)
                {
                    LS.gameObject.SetActive(true);

                    // Update arrow
                    Vector3 lsDifference = TutorialManager.Instance.TutorialItems[12].transform.position - LS.position;
                    float lsAngle = Mathf.Atan2(lsDifference.y, lsDifference.x) * Mathf.Rad2Deg;
                    LS.GetChild(0).transform.eulerAngles = new Vector3(0f, 0f, lsAngle);
                }
                else LS.gameObject.SetActive(false);
            }
            else LS.gameObject.SetActive(false);
        }

        // See if we are going to grab
        if(Input.GetAxis("LT") > 0.5f && closestNPCs.Length > 0)
        {
            // Send messages for grabbed NPCs
            MessageCenter.Instance.Broadcast(new PlayerGrabbedNPCsMessage(new List<GameObject>() { closestNPCs[0] }));

            closestNPCs[0].SetActive(false);

            TreeStateEatingMinigameWrangleTutorial.Data data = new TreeStateEatingMinigameWrangleTutorial.Data(closestNPCs, true);

            Tree.ChangeState("EatingMinigameWrangle", data);

            return;
        }

        ChangeSpritesToDirection(velocity);
    }