public virtual void Draw(Camera2D camera) { Color c = drawColor; if (IsSelected) { c = Color.Green; } _spriteBatch.Draw(currentDrawTex, ConvertUnits.ToDisplayUnits(Position), new Rectangle(0, 0, currentDrawTex.Width, currentDrawTex.Height), c, Rotation, new Vector2(currentDrawTex.Width / 2, currentDrawTex.Height / 2), 1, SpriteEffects.None, 0.2f); BodyBehaviors.ForEach(b => b.Draw(camera)); #region Damage Based Particle Effects if (CurrentHealth <= (.2) * (MaxHealth) && CurrentHealth > 0) { if (Thrusting) //Smoke trail { _particleManager.TriggerEffect(engineSpot, ParticleEffectType.SmokeTrailEffect, 1); } plasmaEffectPosition.X = _rand.Next(-3, 3) / 10f; plasmaEffectPosition.Y = _rand.Next(-3, 3) / 10f; if (TimeKeeper.MsSinceInitialization >= (lastFlameTriggerTime + timeToNextPlasmaTrigger)) { _particleManager.TriggerEffect(ConvertUnits.ToDisplayUnits(Position + plasmaEffectPosition), ParticleEffectType.SmallFlameExplosionEffect, .4f); lastFlameTriggerTime = (float)TimeKeeper.MsSinceInitialization; if (CurrentHealth > 200) { timeToNextPlasmaTrigger = _rand.Next(200, CurrentHealth); } else { timeToNextPlasmaTrigger = 200; } } } #endregion engineSpot.X = (float)Math.Cos(Rotation + MathHelper.PiOver2) * engineOffset + ConvertUnits.ToDisplayUnits(Position.X); engineSpot.Y = (float)Math.Sin(Rotation + MathHelper.PiOver2) * engineOffset + ConvertUnits.ToDisplayUnits(Position.Y); if (Thrusting) { _particleManager.TriggerEffect(engineSpot, ParticleEffectType.EngineEffect, 1); //if (pilot == _clientShipManager.PlayerPilot || localSim) // thrusting = false; } }
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; }