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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 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);
 }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 public NetMatter()
 {
     Speed             = new SpeedTracker(this);
     this.initialBonds = this.CopyBounds();
     this.initialTime  = Time.CurrentTime.Now;
 }
Esempio n. 10
0
 public NetMatter()
 {
     Speed = new SpeedTracker(this);
 }
Esempio n. 11
0
 public Friction(SpeedTracker tracker) : base(tracker.Element)
 {
     this.tracker = tracker;
     tracker.Lifetime.OnDisposed(this.Lifetime.Dispose);
 }