/// <summary> /// Main update running the game /// /// Manages all animations /// </summary> public void Update() { //Quits Application if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } //If we have an animation in the list, call its update, if it returns true, it's finished and wants to be dequeued and remove from the currently updating list if (m_Animations.Count > 0) { if (m_Animations.Peek().RunUpdate() == true) { m_Animations.Dequeue(); if (m_Animations.Count > 0) { //If there's another animation, prep it to run m_Animations.Peek().RunStart(); } } } else //If we dont have anymore animations, attempt to move to the next player { //Keep a reference of the next player Player m_CurrentPlayer = m_Players[NextPlayer()]; //If he doesn't have any jail-time, load up the dice roll animation for him if (m_CurrentPlayer.m_DaysLeftInJail <= 0) { AddToAnimationQueue(new RollManager(m_CurrentPlayer)); m_Animations.Peek().RunStart(); } else //If he does have jail time, post a message displaying the jail time and deincrement his jailtime by a day { CustomAnimation m_TempCustomAnimation = new StatusScreen("Spent the Day in Jail - Wait " + m_CurrentPlayer.m_DaysLeftInJail + " Days For Release", 2.0f); m_TempCustomAnimation.RunStart(); AddToAnimationQueue(m_TempCustomAnimation); WriteToLog("Player: " + m_CurrentPlayer.name + " Spent the day in Jail"); m_CurrentPlayer.m_DaysLeftInJail--; //If the player has moved out of jail, move him to visiting if (m_CurrentPlayer.m_DaysLeftInJail <= 0) { m_TempCustomAnimation = new PlayerMovementToNode(m_CurrentPlayer, transform.FindChild("Just Visiting").GetComponent <Node>(), 1.0f); m_TempCustomAnimation.RunStart(); AddToAnimationQueue(m_TempCustomAnimation); } } } }
/// <summary> /// Creates the animation, the animation requires the Player it's going to move and how many steps to jump /// </summary> /// <param name="a_Player">The player to be moved</param> /// <param name="a_JumpGoal">The ammount of steps to jump</param> public PlayerMovement(Player a_Player, int a_JumpGoal) { //Subscribe updates to the events on the animation OnStart += OnStartFunction; OnUpdate += OnUpdateFunction; OnFinish += OnFinishFunction; //Keep reference of the inputed data m_JumpGoal = a_JumpGoal; m_Player = a_Player; //Create a sub animation that attempts to move to the next node m_MovementToNode = new PlayerMovementToNode(m_Player, m_Player.m_CurrentNode.m_NextNode, c_ANIMATION_SPEED); }
/// <summary> /// Update function used to check if the animation that's currently being run has finished, if it has, check if enough spots have moved, if so quit the animation. /// Otherwise, repeat /// </summary> /// <returns>Returns true if finished</returns> public bool OnUpdateFunction() { //Checks the sub-animation thats moving to the next node has finished if (m_MovementToNode.RunUpdate() == true) { //If it has finished, increase the jumps m_CurrentJumps++; //Check if the jumps is greater then the goal, if it is, break out of the animation if (m_CurrentJumps >= m_JumpGoal) { return(true); } //If we didn't break previous that means we need to do another lap, recreate the subanimation m_MovementToNode = new PlayerMovementToNode(m_Player, m_Player.m_CurrentNode.m_NextNode, c_ANIMATION_SPEED); m_MovementToNode.RunStart(); } //Didn't finish, return false return(false); }