public MainCharacter() { Inventory = new Inventory(); Speed = new SpeedTracker(this); Targeting = new Targeting(() => this.Bounds, t => t is Zombie); Added.SubscribeForLifetime(() => { Scene.Add(Targeting); }, this.LifetimeManager); Removed.SubscribeForLifetime(() => { Scene.Remove(Targeting); }, this.LifetimeManager); Targeting.TargetChanged.SubscribeForLifetime((target) => { if (this.Target != null && this.Target.IsExpired == false) { Scene.Update(this.Target); } this.Target = target; if (this.Target != null && this.Target.IsExpired == false) { Scene.Update(this.Target); } }, this.LifetimeManager); Speed.Bounciness = 0; this.HealthPoints = 100; Speed.HitDetectionTypes.Add(typeof(Wall)); Added.SubscribeForLifetime(OnAdded, this.LifetimeManager); Removed.SubscribeForLifetime(OnRemoved, this.LifetimeManager); }
public override void FireInternal() { SoundEffects.Instance.PlaySound("thump"); var rpg = new TimedMine(TimeSpan.FromSeconds(2), MainCharacter.Current.Bounds.Clone(), 5, 4) { HealthPointsPerShrapnel = 5 }; var rpgSpeed = new SpeedTracker(rpg); rpgSpeed.HitDetectionTypes.Add(typeof(Wall)); rpgSpeed.HitDetectionTypes.Add(typeof(Zombie)); rpgSpeed.ImpactOccurred.SubscribeForLifetime((impact) => { if (impact.ThingHit is IDestructible) { var destructible = impact.ThingHit as IDestructible; destructible.TakeDamage(5 * rpg.HealthPointsPerShrapnel); } rpg.Explode(); }, rpg.LifetimeManager); var angle = MainCharacter.Current.Target != null? MainCharacter.Current.Bounds.Location.CalculateAngleTo(MainCharacter.Current.Target.Bounds.Location) : MainCharacter.Current.Speed.Angle; if (MainCharacter.Current.FreeAimCursor != null) { angle = MainCharacter.Current.Bounds.Location.CalculateAngleTo(MainCharacter.Current.FreeAimCursor.Bounds.Location); } new Force(rpgSpeed, 30, angle); new Force(rpgSpeed, 15, SceneHelpers.GetOppositeAngle(angle), TimeSpan.FromSeconds(1)); MainCharacter.Current.Scene.Add(rpg); }
public void TestSeeking() { SpacialElement seeker = null; SpacialElement target = null; var w = 10; var h = 3; ConsoleAppTestHarness.Run(TestContext, (app, panel) => { seeker = SpaceTime.CurrentSpaceTime.Add(new SpacialElement(1, 1, 0, 1)); seeker.Renderer = new SpacialElementRenderer() { Background = ConsoleColor.Green }; target = SpaceTime.CurrentSpaceTime.Add(new SpacialElement(1, 1, w - 2, 1)); var seekerV = new SpeedTracker(seeker); var seekerFunc = new Seeker(seeker, target, seekerV, 5) { RemoveWhenReached = true }; seekerFunc.Lifetime.LifetimeManager.Manage(() => { panel.SpaceTime.Stop(); }); }, w: w, h: h); Assert.AreEqual(seeker.CenterX, target.CenterX); Assert.AreEqual(seeker.CenterY, target.CenterY); }
private void FireDoubleInternal(float x, float y, float angle) // :) { Sound.Play("thump"); var rpg = new TimedMine(TimeSpan.FromSeconds(2)) { Silent = true }; rpg.MoveTo(x, y); var rpgSpeed = new SpeedTracker(rpg); rpgSpeed.HitDetectionTypes.Add(typeof(Wall)); rpgSpeed.HitDetectionTypes.Add(typeof(Character)); rpgSpeed.HitDetectionExclusions.Add(Holder); rpgSpeed.ImpactOccurred.SubscribeForLifetime((impact) => { if (impact.ElementHit is IDestructible) { var destructible = impact.ElementHit as IDestructible; destructible.TakeDamage(5 * rpg.HealthPointsPerShrapnel); } rpg.Explode(); }, rpg.Lifetime); new Force(rpgSpeed, SpaceExtensions.NormalizeQuantity(25, angle), angle); SpaceTime.CurrentSpaceTime.Add(rpg); }
public Bullet() { Speed = new SpeedTracker(this); Speed.HitDetectionTypes.Add(typeof(Wall)); Speed.HitDetectionTypes.Add(typeof(Zombie)); Speed.HitDetectionTypes.Add(typeof(MainCharacter)); Speed.Governor.Rate = TimeSpan.FromSeconds(0); Speed.ImpactOccurred.SubscribeForLifetime(Speed_ImpactOccurred, this.LifetimeManager); }
public Projectile() { this.ResizeTo(1, 1); Speed = new SpeedTracker(this); Speed.HitDetectionTypes.Add(typeof(Enemy)); Speed.HitDetectionTypes.Add(typeof(Wall)); Speed.Governor.Rate = TimeSpan.FromSeconds(0); Speed.ImpactOccurred.SubscribeForLifetime(Speed_ImpactOccurred, this.Lifetime); }
public Projectile(Weapon w) : base(w) { this.ResizeTo(StandardWidth, StandardHeight); this.Tags.Add(Weapon.WeaponTag); Speed = new SpeedTracker(this); Speed.Governor.Rate = TimeSpan.FromSeconds(0); Speed.ImpactOccurred.SubscribeForLifetime(Speed_ImpactOccurred, this.Lifetime); this.Speed.HitDetectionExclusionTypes.Add(typeof(Projectile)); if (w?.Holder != null) { this.Speed.HitDetectionExclusions.Add(w.Holder); } }
private void FireDoubleInternal(float x, float y, float angle) // :) { var rpg = new TimedMine(this, TimeSpan.FromSeconds(2)) { Silent = true, ProjectilePen = ProjectilePen }; rpg.MoveTo(x, y, Holder.ZIndex); var rpgSpeed = new SpeedTracker(rpg); rpgSpeed.HitDetectionExclusions.Add(Holder); Holder.Speed.HitDetectionExclusions.Add(rpg); rpgSpeed.ImpactOccurred.SubscribeForLifetime((impact) => { DamageBroker.Instance.ReportImpact(impact); rpg.Explode(); }, rpg.Lifetime); new Force(rpgSpeed, 45.NormalizeQuantity(angle), angle); SpaceTime.CurrentSpaceTime.Add(rpg); }
public NetMatter() { Speed = new SpeedTracker(this); this.initialBonds = this.CopyBounds(); this.initialTime = Time.CurrentTime.Now; }
public NetMatter() { Speed = new SpeedTracker(this); }
public Friction(SpeedTracker tracker) : base(tracker.Element) { this.tracker = tracker; tracker.Lifetime.OnDisposed(this.Lifetime.Dispose); }