public virtual void Update() { ChangeEnergy((ShipStats.EnergyRegenRate * StatBonuses[StatBonusTypes.EnergyRegen] / (1 + Debuffs[DebuffTypes.EnergyRegen] * DebuffHandlerModel.EffectValues[DebuffTypes.EnergyRegen])) * (TimeKeeper.MsSinceInitialization - lastTimeStamp)); //Energy rate given in energy/millisecond foreach (var w in _weapons) { w.Update(); } if (DoCombatUpdates) { Debuffs.Update(TimeKeeper.MsSinceInitialization); Shields.Update(TimeKeeper.MsSinceInitialization); if (combatUpdateTimeout + TimeOfLastCollision < TimeKeeper.MsSinceInitialization) { DoCombatUpdates = false; } } lastTimeStamp = TimeKeeper.MsSinceInitialization; }
public virtual void Update(IGameTimeService gameTime) { Pilot.Update(gameTime); BodyBehaviors.ForEach(b => b.Update(gameTime)); // Time dependent updates (e.g. shields) var energyRegexRate = ShipStats.EnergyRegenRate * StatBonuses[StatBonusTypes.EnergyRegen] / (1 + Debuffs[DebuffTypes.EnergyRegen]); var amount = (int)(gameTime.ElapsedMilliseconds * energyRegexRate); ChangeEnergy(amount); //WARNING: Might have to fix on fast computers, if update is too fast, int might be rounded down Shields.Update(gameTime.TotalMilliseconds); Debuffs.Update(gameTime.TotalMilliseconds); // Turning // Divided because units are radians/second var elapsedTime = ShipStats.TurnRate * StatBonuses[StatBonusTypes.TurnRate]; if (IsTurningCounterClockwise) { AngularVelocity = -elapsedTime; } else if (IsTurningClockwise) { AngularVelocity = elapsedTime; } else { AngularVelocity = 0; } // Increase Drag if ship is going faster than top speed float limitVal = (ShipStats.TopSpeed + StatBonuses[StatBonusTypes.TopSpeed]) / (1 + Debuffs[DebuffTypes.TopSpeed]); if (Thrusting) { limitVal *= ShipStats.BoostBonus; } LinearDamping = LinearVelocity.Length() >= limitVal ? _speedDampValue : 0.0001f; // Check if Outside System //// Check if you're outside of the wall // Broken :( //if (Vector2.Distance(Vector2.Zero, ConvertUnits.ToDisplayUnits(Position)) > _borderManager.sizeOfSystem // && GameStateManager.getState() == GameStates.space) //{ // Console.WriteLine("Outside of System"); // Vector2 pos; // //pos.X = (float) (Math.Cos(MathHelper.ToRadians(Position.X))*(BorderManager.sizeOfSystem + 700)); // //pos.Y = (float) (Math.Sin(MathHelper.ToRadians(Position.Y))*(BorderManager.sizeOfSystem + 700)); // //Position = ConvertUnits.ToSimUnits(pos); // Position = new Vector2(1,1); // LinearVelocity *= -1; //} foreach (Weapon w in _weapons) { w.Update(gameTime); } if (!SendPositionUpdates && gameTime.TotalMilliseconds - PositionUpdateDisableTimestamp > PositionUpdateDisableDuration) { SendPositionUpdates = true; } lastTimeStamp = gameTime.ElapsedMilliseconds; }