void StartReturnToRally() { State = eState.ReturnToRally; SwitchAnimation(RunAni); ReturnDest = GetRandomRallyLoc(); Vector2 moveDir = Maths.GetMoveDir(FeetLoc, ReturnDest); MoveIncrement = Velocity * moveDir; Animation.SetDirectionByDir(moveDir); }
public void Update(GameTime gameTime) { Animation.Update(gameTime); #region Move if (!IsFighting) { if (Target == null) { #region MoveToWP SetLocation(Animation.Location + MoveIncrement); if (Vector2.Distance(FeetLoc, NextWP.Location + WPSpread) <= Velocity) { CurrentWP = NextWP; if (CurrentWP.IsFinish) { ClearIncommings(); // Call before setting a new location to this runner. Level.Instance.Player.Lives -= FinishDmg; if (Recycles) SetLocation(StartWP); } else { NextWP = CurrentWP.GetNextWP(); InitMoveToNextWP(); } } #endregion } else { #region MoveToTargetIfNeeded { if (Vector2.Distance(FeetLoc, Target.FeetLoc) > 50) { Vector2 moveDir = Maths.GetMoveDir(FeetLoc, Target.FeetLoc); Animation.Location += Velocity * moveDir; Animation.SetDirectionByDir(moveDir); } } #endregion } m_AABB.X = RelativeAABB.X + Animation.Location.Xi(); m_AABB.Y = RelativeAABB.Y + Animation.Location.Yi(); #endregion #region Attack #region if no target then attempt to set ranged target if (Target == null && HasRangedWeapon) { Target = (ITargetable)BroadPhase.Instance.GetFirstEntityInRange(this, RangedWpnRange, e => e.EntityType == eEntityType.Defender); if (Target != null) IsFightingRanged = true; } #endregion if (Target != null) Animation.SetDirection(FeetLoc, Target.FeetLoc); } else { if (Target == null) Target = IsFightingWithDefenders[0]; foreach (BaseWeapon wpn in Weapons) wpn.Update(gameTime); } #endregion // Get the percentage from start-->finish based on the first startpoint from the global list. DistanceToFinish = Vector2.Distance(FeetLoc, NextWP.Location) + NextWP.ShortestRouteToFinishLength; DistanceTraveled = WayPoint.StartPoints[0].ShortestRouteToFinishLength - DistanceToFinish; PercentageToFinish = (DistanceTraveled / WayPoint.StartPoints[0].ShortestRouteToFinishLength) * 100; // Set this as the runner nearest to the finish if applicable if (RunnerNearestToFinish == null || RunnerNearestToFinish.PercentageToFinish < PercentageToFinish) RunnerNearestToFinish = this; }