public override void Update(float elapsedTime) { activeRunTime += elapsedTime; currentTime += elapsedTime; if (currentCurve < bezierCurves.Count) { float t = activeRunTime / runTimes[currentCurve]; if (t <= 1.0) { var nextPos = ChaosDriveMath.CalculateBezierCurveLocation(bezierCurves[currentCurve], t); velocity = nextPos - position; position = nextPos; } else { activeRunTime -= runTimes[currentCurve]; currentCurve++; if (currentCurve < bezierCurves.Count) { t = activeRunTime / runTimes[currentCurve]; var nextPos = ChaosDriveMath.CalculateBezierCurveLocation(bezierCurves[currentCurve], t); velocity = nextPos - position; position = nextPos; } } } else { position += velocity; } if (bullets.Count > 0) { if (bullets.Any(b => b.LaunchTime < currentTime)) { OnShotsFired(); } } UpdateHitEffect(elapsedTime); ActiveSprite.Update(elapsedTime); ActiveSprite.Position = position; if (health <= 0) { shouldRemove = true; } if (currentCurve >= bezierCurves.Count && activeRunTime >= runTimes.Last() && !ActiveSprite.Bounds.Intersects(bounds)) { shouldRemove = true; } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { foreach (var controller in controllers) { controller.Update(); } ActiveSprite?.Update(); base.Update(gameTime); }
public void Update(float elapsedTime) { ActiveSprite.Update(elapsedTime); #region Move the player according to the state Move(elapsedTime); #endregion if (incomingDamage > 0) { var toRemove = 25.0f / (elapsedTime); toRemove = Math.Min(incomingDamage, toRemove); health -= toRemove; incomingDamage -= toRemove; } if (health < 1) { health = 0; } if (invulnerableTime > 0) { invulnerableTime = Math.Max(0f, invulnerableTime - elapsedTime); invulnerable = invulnerableTime > 0; } if (gunReloadTime > 0) { gunReloadTime -= elapsedTime; } if (driveReloadTime > 0) { driveReloadTime -= elapsedTime; } if (chaosDriveFuel < 100 && timeAdjustment == 1.0f) { chaosDriveFuel = Math.Min((chaosDriveFuel + (10.0f * elapsedTime / 1000.0f)), 100); } if (timeAdjustment != 1.0f) { chaosDriveFuel = Math.Max(chaosDriveFuel - (10.0f * elapsedTime / 1000.0f / timeAdjustment), 0.0f); if (chaosDriveFuel == 0.0f) { driveReloadTime = 4000.0f; } } }
public virtual void Update(float elapsedTime) { if (!isDisposed && ActiveSprite != null) { UpdateHitEffect(elapsedTime); } if (!isDisposed && ActiveSprite != null) { ActiveSprite.Update(elapsedTime); } if (!isDisposed && ActiveSprite != null) { ActiveSprite.Position = position; } if (health <= 0 || !ActiveSprite.Bounds.Intersects(bounds)) { shouldRemove = true; } }