コード例 #1
0
        private void ShootAtAttacker(TDAttacker Attacker)
        {
            // create a TDAmmo object at this current location, and set it's speed toward target.
            TDAmmo newAmmo = new TDAmmo(this, Attacker);

            TDSession.thisSession.CurrentLevel.Ammo.Add(newAmmo);
        }
コード例 #2
0
ファイル: TDAmmo.cs プロジェクト: HansonScott/TowerDefense
        private void HitTarget(TDEntity entity)
        {
            #region splash
            if (this.SplashRadius > 0)
            {
                DamageRadius(target.Location, this.SplashRadius);

                // spawn a new explosion
                TDSession.thisSession.CurrentLevel.Explosions.Add(new TDExplosion(entity.Location, this.SplashRadius));
            }
            #endregion
            else // not splash
            {
                entity.HPCurrent -= this.damage;

                // apply any effects
                if (this.Effects != null &&
                    this.Effects.Count > 0)
                {
                    foreach (TDEffect e in this.Effects)
                    {
                        entity.Effects.Add(new TDEffect(e.Effect, e.Power, e.Duration, true));
                    }
                }
            }

            #region Chaining
            if (this.ChainCount > 0)
            {
                // find the next closest attacker, not the source
                List <TDEntity> newTargets = GetTowersInRange(entity.Location, this.ChainDist, false, true);

                // don't hit this source.
                if (newTargets.Contains(this.source))
                {
                    newTargets.Remove(this.source);
                }

                // and don't hit this new target itself
                if (newTargets.Contains(entity))
                {
                    newTargets.Remove(entity);
                }

                if (newTargets.Count > 0)
                {
                    // get a random target within this range
                    TDEntity newTarget = newTargets[TDMath.D(newTargets.Count) - 1];

                    // make a new ammo from this one,
                    TDAmmo newAmmo = new TDAmmo(entity, newTarget); // start from this target hit

                    // reduce the chain count
                    newAmmo.ChainDist  = this.ChainDist;
                    newAmmo.ChainCount = this.ChainCount - 1;
                    newAmmo.damage     = Math.Max(1, this.damage - 1); // override the damage with the chain decline
                    TDSession.thisSession.CurrentLevel.Ammo.Add(newAmmo);
                }
            }
            #endregion

            // since ammo dies automatically
            this.DeleteMe = true;
        }