public override void Update(GameTime gameTime) { if (fuseOn) { FuseTime -= gameTime.ElapsedGameTime.Milliseconds / 1000f; if (FuseTime <= 0) { var PE = ((PlayableState)GameEngine.Singleton .FindGameState(x => x is PlayableState)) .PhysicsManager; var BlastRadius = 1.5f * this.Radius; var explosion = ParticleSystemFactory.GetDirtyBomb(this.Position, BlastRadius); PE.AddParticleSystems(explosion); var forcefield = new InstantaneousForceField(this.Position, BlastRadius, DefaultForces.GenerateExplosiveField(50, 3f)); PE.AddInstantaneousForceField(forcefield); var inRange = PE.QTbodies.Query(Region.FromCircle(this.Position, BlastRadius)); foreach (Actor actor in inRange) { if (actor is IHealthable) { var damage = forcefield.GetForce(actor.Position - forcefield.SourcePos).Length(); ((IHealthable)actor).Hurt(damage / 500); } } this.CurrentHealth = 0; this.Destroy(); } } }
public void Detonate() { if (this.Parent == null) return; var PE = ((PlayableState)GameEngine.Singleton .FindGameState(x => x is PlayableState)) .PhysicsManager; var explosion = ParticleSystemFactory.GetDirtyBomb(this.Position, BlastRadius); PE.AddParticleSystems(explosion); var forcefield = new InstantaneousForceField(this.Position, BlastRadius, DefaultForces.GenerateExplosiveField(BlastRadius, BlastStrength)); PE.AddInstantaneousForceField(forcefield); this.Parent.Destroy(); var inRange = PE.QTbodies.Query(Region.FromCircle(this.Position, BlastRadius)); foreach (Actor actor in inRange) { if (actor is IHealthable) { var damage = forcefield.GetForce(actor.Position - forcefield.SourcePos).Length(); ((IHealthable)actor).Hurt(damage / 500); } } }