public void Update(GameTime gameTime) { Animation.Update(gameTime); foreach (BaseWeapon wpn in Weapons) { wpn.UpdateForTower(gameTime, this); } #region Spawn foreach (BaseDefender defender in Defenders) { defender.Update(gameTime); } #endregion if (IncomeTickDelayTimer != null && Level.Instance.State == Level.eState.Playing) // The last check prevents the incoem towers from generating income during the PreSpawn state. { IncomeTickDelayTimer.Update(gameTime); if (IncomeTickDelayTimer.IsDone) { IncomeTickDelayTimer.Reset(); Level.Instance.Player.Gold += IncomePerTick; Level.Instance.AddHut(CenterLoc, IncomePerTick, false); } } }
public void Update(GameTime gameTime) { Animation.Update(gameTime); if (Animation.IsDisposed) { IsDisposed = true; } }
public void Update(GameTime gameTime) { Animation.Update(gameTime); }
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; }
public void Update(GameTime gameTime) { if (IsSpawned) { if (IsAlive) { // Update animation Animation.Update(gameTime); if (State == eState.Fighting) { #region Attempt to attack another unoccupied target when the current target has > 1 defender if (((BaseRunner)Target).TargettedByDefenders.Count > 1) { BaseRunner newTarget = GetNewTarget(true); if (newTarget != null) { Target = newTarget; State = eState.Running; // If the new target would be in range then the next cycle will set this state to fighting but if we don't set it to fighting the defender might not walk to the new enemy. } } #endregion #region Update weapons foreach (BaseWeapon wpn in Weapons) { wpn.Update(gameTime); } #endregion } else { // Get new target if needed if (Target == null) { Target = GetNewTarget(false); } if (Target != null) { float distanceToTarget = Vector2.Distance(FeetLoc, Target.FeetLoc); if (distanceToTarget <= MeleeSightRange) { if (distanceToTarget > ShortestWeaponRange) { #region Run to target SwitchAnimation(RunAni); Vector2 moveDir = Maths.GetMoveDir(FeetLoc, Target.FeetLoc); Animation.Location += moveDir * Velocity; Animation.SetDirectionByDir(moveDir); #endregion } else { #region Start fighting State = eState.Fighting; SwitchAnimation(AtkAni); ((BaseRunner)Target).IsFightingWithDefenders.Add(this); #endregion } } else // Runner walked out of sightrange. So release the target and walk back to the rallypoint if needed. (looking for a new target in range will occur next cycle). { WalkBackToNearRallyPoint(); } } else { WalkBackToNearRallyPoint(); } } m_AABB.X = RelativeAABB.X + Animation.Location.Xi(); m_AABB.Y = RelativeAABB.Y + Animation.Location.Yi(); } else { if (State == eState.Dying) { Animation.Update(gameTime); if (DieAni.IsDisposed) { State = eState.Dead; DieAni.Reset(); } } else { #region Not alive but spawned so respawn code goes here RespawnTimer.Update(gameTime); if (RespawnTimer.IsDone) { RespawnTimer.Reset(); Resurrect(); } #endregion } } } }
public override void Update(GameTime gameTime) { #region Movement Vector2 newLoc = Location; Vector2 md = Vector2.Zero; if (SettingsMgr.Instance.ControlType1 == eControlType.Keyboard) { if (InputMgr.Instance.IsDown(ControllerIdx, Keys.Up, Buttons.DPadUp, Buttons.LeftThumbstickUp, Buttons.RightThumbstickUp)) { md += new Vector2(0, -1); } if (InputMgr.Instance.IsDown(ControllerIdx, Keys.Right, Buttons.DPadRight, Buttons.LeftThumbstickRight, Buttons.RightThumbstickRight)) { md += new Vector2(1, 0); } if (InputMgr.Instance.IsDown(ControllerIdx, Keys.Down, Buttons.DPadDown, Buttons.LeftThumbstickDown, Buttons.RightThumbstickDown)) { md += new Vector2(0, 1); } if (InputMgr.Instance.IsDown(ControllerIdx, Keys.Left, Buttons.DPadLeft, Buttons.LeftThumbstickLeft, Buttons.RightThumbstickLeft)) { md += new Vector2(-1, 0); } } else { if (Vector2.Distance(CenterLoc, InputMgr.Instance.Mouse.Location) > Velocity) { md = Maths.GetMoveDir(CenterLoc, InputMgr.Instance.Mouse.Location); } } newLoc += md * Velocity; // Clamp if (newLoc.X < 0) { newLoc.X = 0; } if (newLoc.X + AABB.Width > Engine.Instance.Width) { newLoc.X = Engine.Instance.Width - AABB.Width; } if (newLoc.Y < 0) { newLoc.Y = 0; } if (newLoc.Y + AABB.Height > Engine.Instance.Height) { newLoc.Y = Engine.Instance.Height - AABB.Height; } Location = newLoc; BroadPhase.Instance.AddEntity(this, AABB); #endregion // Reset weapons if (InputMgr.Instance.Keyboard.IsPressed(Keys.X)) { for (int i = 0; i < Guns.Count; i++) { Guns[i].ResetDelay(); } } // Shoot for (int i = 0; i < Guns.Count; i++) { Guns[i].Update(gameTime, Location); } // Shield ShieldRegenTimer.Update(gameTime); if (ShieldRegenTimer.IsDone) { ShieldRegenTimer.Reset(); Shield.CurrentHP += ShieldRegen; Owner.ShieldBar.Percentage = Shield.LifeLeftPercentage; } // HP regen if (HPRegen.CurrentValue > 0) { HPRegenTimer.Update(gameTime); if (HPRegenTimer.IsDone) { HP.CurrentHP += HPRegen.CurrentValue; Owner.HPBar.Percentage = HP.LifeLeftPercentage; } } // Bomb if (NuclearCnt > 0) { if ((SettingsMgr.Instance.ControlType1 == eControlType.Keyboard && InputMgr.Instance.IsPressed(null, Keys.Space, Buttons.A)) || ((SettingsMgr.Instance.ControlType1 == eControlType.Mouse && InputMgr.Instance.Mouse.RightButtonIsPressed)) ) { NuclearCnt--; Level.Instance.LaunchNuclearBomb(this); } } // Update shield sprite if (Shield.CurrentHP >= MIN_SHIELD_HP_FOR_SPRITE) { ShieldSprite.Update(gameTime); ShieldSprite.Location = Location; } }