Esempio n. 1
0
        public TDAmmo(TDEntity source, TDEntity target)
        {
            this.source          = source;
            this.CurrentLocation = new TDLocation(source.Location.X, source.Location.Y);
            this.target          = target;
            this.speed           = source.BulletSpeed;
            this.damage          = source.BulletDamage;
            this.SplashRadius    = source.SpashRadius;
            this.Seeking         = source.SeekingMissle;
            this.ChainCount      = source.ChainHops;
            this.ChainDist       = source.ChainDist;
            this.size            = 1 + (this.damage / 4);
            CalculateTrajectory();

            // copy any effects (except waveDelay)
            this.Effects = new List <TDEffect>();
            foreach (TDEffect e in source.Effects)
            {
                if (e.Effect == TDEffectTypes.WaveDelay)
                {
                    continue;
                }
                else
                {
                    this.Effects.Add(new TDEffect(e.Effect, e.Power, e.Duration, false));
                }
            }
        }
Esempio n. 2
0
        private void LoadDetailsOfTower(TDEntity tde)
        {
            if (tde != null)
            {
                SetLabelText(this.lblDetailName, tde.Name);
                SetLabelText(this.lblDetailsDamage, tde.BulletDamage.ToString());
                SetLabelText(this.lblDetailRange, tde.Range.ToString());
                SetLabelText(this.lblDetailsHP, "" + Math.Max(0, tde.HPCurrent) + " / " + tde.HPMax);
                SetLabelText(this.lblDetailsFireRate, "" + (int)(500 / tde.Cooldown.TotalMilliseconds));
                SetLabelText(this.lblDetailsSplashRadius, tde.SpashRadius.ToString());

                if (tde is TDTower)
                {
                    SetLabelText(this.lblDetail_AI, Enum.GetName(typeof(TDTower.AISettings), (tde as TDTower).AISetting));
                    SetLabelText(this.lbl_Detail_Speed, tde.BulletSpeed.ToString());
                }
                else // TDAttacker
                {
                    SetLabelText(this.lbl_Detail_Speed, (tde.SpeedCurrent).ToString());
                }
            }
            else
            {
                SetLabelText(this.lblDetailName, String.Empty);
                SetLabelText(this.lblDetailsDamage, String.Empty);
                SetLabelText(this.lblDetailRange, String.Empty);
                SetLabelText(this.lbl_Detail_Speed, String.Empty);
                SetLabelText(this.lblDetailsHP, String.Empty);
                SetLabelText(this.lblDetailsFireRate, String.Empty);
                SetLabelText(this.lblDetailsSplashRadius, String.Empty);
                SetLabelText(this.lblDetail_AI, String.Empty);
            }
        }
Esempio n. 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            // confirm - sell tower
            DialogResult r = MessageBox.Show("Are you sure you want to sell this tower?", "Sell tower?", MessageBoxButtons.YesNo);

            if (r == System.Windows.Forms.DialogResult.Yes)
            {
                TDSession.thisSession.gold += this.CurrentlySelectedEntity.Cost / 2;
                TDSession.thisSession.CurrentLevel.Towers.Remove(this.CurrentlySelectedEntity as TDTower);
                this.CurrentlySelectedEntity = null;
                RefreshDetailsOfSelection();
            }
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        /// <summary>
        /// The main panel's action event handler.
        /// </summary>
        private void panelAction_Click(object sender, EventArgs e)
        {
            MouseEventArgs m            = (e as MouseEventArgs);
            bool           shiftPressed = Control.ModifierKeys.HasFlag(Keys.Shift);

            // placing a tower
            if (this._CursorState == CursorStates.PlaceTower)
            {
                TDTowerButton b = GetSelectedTowerButton();
                if (b == null)
                {
                    return;
                }

                TDTower newTower = b.Tower;
                // if on path - no
                newTower.Location = new TDLocation(m.X, m.Y);

                if (TDSession.thisSession.CurrentLevel.CanPlaceTower(newTower))
                {
                    // actually place the tower
                    placeTower((e as MouseEventArgs).Location);

                    // and after we place the tower, unselect the tower if we did not have shift down (or right clicked)
                    if (m.Button == System.Windows.Forms.MouseButtons.Left &&
                        !shiftPressed)
                    {
                        this.CursorState = CursorStates.Normal;
                        GetSelectedTowerButton().Checked = false;
                    }
                }
            }
            // selecting something
            else
            {
                if (TDSession.thisSession == null)
                {
                    return;
                }

                // attempt to highlight tower selected
                this.CurrentlySelectedEntity = GetTowerAtPoint((e as MouseEventArgs).Location);
                if (CurrentlySelectedEntity != null)
                {
                    UnhighlightAll();
                    CurrentlySelectedEntity.IsHighlighted = true;
                    LoadDetailsOfTower(CurrentlySelectedEntity as TDEntity);
                    if (CurrentlySelectedEntity is TDTower)
                    {
                        btnDelete.Enabled = true;
                        ResetPurchaseButtons();
                        ResetAIButtons();
                    }
                    else
                    {
                        btnDelete.Enabled  = false;
                        btn_Repair.Enabled = false;
                        btnUpgrade.Enabled = false;
                    }
                }
                else // nothing was clicked on
                {
                    UnhighlightAll();
                    ClearDetails();
                    ResetPurchaseButtons();
                    ResetAIButtons();
                }
            }
        }