Exemple #1
0
        public TDTower(TDTower sourceTemplate, Point newLocation)
        {
            base.MainColor = Color.Blue;

            this.BulletDamage  = sourceTemplate.BulletDamage;
            this.BulletSpeed   = sourceTemplate.BulletSpeed;
            this.Cooldown      = sourceTemplate.Cooldown;
            this.HPMax         = sourceTemplate.HPMax;
            this.HPCurrent     = this.HPMax;
            this.Location      = new TDLocation(newLocation.X, newLocation.Y);
            this.Name          = sourceTemplate.Name;
            this.Range         = sourceTemplate.Range;
            this.Size          = sourceTemplate.Size;
            this.SpashRadius   = sourceTemplate.SpashRadius;
            this.SeekingMissle = sourceTemplate.SeekingMissle;
            this.ChainHops     = sourceTemplate.ChainHops;
            this.ChainDist     = sourceTemplate.ChainDist;
            this.Cost          = sourceTemplate.Cost;

            if (sourceTemplate.Effects != null &&
                sourceTemplate.Effects.Count > 0)
            {
                foreach (TDEffect e in sourceTemplate.Effects)
                {
                    this.Effects.Add(new TDEffect(e.Effect, e.Power, e.Duration, false));
                }
            }
        }
Exemple #2
0
        private void CreateNewTower()
        {
            TDTower t = new TDTower();

            t.BulletDamage  = (int)nudDamage.Value;
            t.BulletSpeed   = (int)nudBulletSpeed.Value;
            t.HPMax         = (int)nudHP.Value;
            t.HPCurrent     = t.HPMax;
            t.Name          = textBox1.Text;
            t.Range         = (int)nudRange.Value;
            t.SpashRadius   = (int)nud_SplashRadius.Value;
            t.ChainDist     = (int)nud_ChainDist.Value;
            t.ChainHops     = (int)nud_ChainCount.Value;
            t.SeekingMissle = chk_Seeking.Checked;
            t.Cooldown      = new TimeSpan(0, 0, 0, 0, (int)(500 / nudFireRate.Value));

            if (this.nudSlowPercentage.Value > 0 &&
                this.nudSlowTime.Value > 0)
            {
                t.Effects.Add(new TDEffect(TDEffectTypes.Slow, this.nudSlowPercentage.Value, new TimeSpan(0, 0, 0, (int)this.nudSlowTime.Value), false));
            }

            t.Cost = totalCost / 2; // prototype is full cost, each implementation is only half.

            t.IsHighlighted = true;

            this.Tower = t;

            TDSession.thisSession.gold -= totalCost;
        }
Exemple #3
0
        public bool isTowerOnPath(TDTower t)
        {
            // first check if intersting any corner
            TDPathPoint lastPoint = null;

            foreach (TDPath p in this.Paths)
            {
                foreach (TDPathPoint pp in p.PathPoints)
                {
                    if (TDMath.Intersects(t.Location, t.Size, pp.Location, GridSize))
                    {
                        return(true);
                    }
                    else
                    {
                        // check intersecting any line
                        if (lastPoint != null)
                        {
                            if (TDMath.Intersects(t, pp, lastPoint))
                            {
                                return(true);
                            }
                        }

                        lastPoint = pp;
                    }
                }
            }

            return(false);
        }
Exemple #4
0
        private void ShootAtTower(TDTower tower)
        {
            // create a TDAmmo object at this current location, and set it's speed toward target.
            TDAmmo newAmmo = new TDAmmo(this, tower);

            TDSession.thisSession.CurrentLevel.Ammo.Add(newAmmo);
        }
Exemple #5
0
        private void placeTower(Point point)
        {
            TDTower newTower = new TDTower(GetSelectedTowerType(), point);

            TDSession.thisSession.CurrentLevel.Towers.Add(newTower);
            TDSession.thisSession.gold -= newTower.Cost;
        }
Exemple #6
0
        void pop_FormClosed(object sender, FormClosedEventArgs e)
        {
            TDTower t = (sender as TDTowerCreator).Tower;

            if (t == null)
            {
                return;
            }

            // load thew newly created tower into one of the buttons.
            if (btnTower1.Tower == null)
            {
                btnTower1.Tower = t;
            }
            else if (btnTower2.Tower == null)
            {
                btnTower2.Tower = t;
            }
            else if (btnTower3.Tower == null)
            {
                btnTower3.Tower = t;
            }
            else if (btnTower4.Tower == null)
            {
                btnTower4.Tower = t;
            }
            else
            {
                // no more available tower types?
            }

            ResetPurchaseButtons();

            btnDeleteTowerType.Enabled = true;
        }
Exemple #7
0
        void TDTowerButton_Click(object sender, EventArgs e)
        {
            if (this.Checked)
            {
                // then uncheck all the other towers
                UnCheckOtherPurchaseButtons();

                if (TDForm.ThisForm.CursorState == TDForm.CursorStates.DeleteTower)
                {
                    DialogResult r = MessageBox.Show("Are you sure you want to delete this tower type?", "Delete Tower?", MessageBoxButtons.YesNo);
                    if (r == DialogResult.Yes)
                    {
                        Tower = null;
                        TDForm.ThisForm.CursorState = TDForm.CursorStates.Normal;
                        //this.Checked = false;
                    }
                }
                else if (TDForm.ThisForm.CursorState == TDForm.CursorStates.Normal)
                {
                    TDForm.ThisForm.CursorState = TDForm.CursorStates.PlaceTower;
                    TDForm.placementTower       = this.Tower;
                }
                // we are already placing a tower, but we changed which tower to place
                else if (TDForm.ThisForm.CursorState == TDForm.CursorStates.PlaceTower)
                {
                    TDForm.placementTower = this.Tower;
                }
            }
            else
            {
                TDForm.ThisForm.CursorState = TDForm.CursorStates.Normal;
            }
        }
Exemple #8
0
        /// <summary>
        /// Does the target interect the line between point A and point B.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="pointA"></param>
        /// <param name="pointB"></param>
        /// <returns></returns>
        internal static bool Intersects(TDTower target, TDPathPoint pointA, TDPathPoint pointB)
        {
            bool result = false;

            // adjust PathPoints by GridSize
            double aX = pointA.Location.X;
            double aY = pointA.Location.Y;
            double bX = pointB.Location.X;
            double bY = pointB.Location.Y;

            bool intersectXAxis = false;
            bool intersectYAxis = false;

            if (aX < bX)
            {
                intersectXAxis = target.Location.X <bX + (TDMap.GridSize - 2) && target.Location.X + (TDMap.GridSize - 2)> aX;
            }
            else
            {
                intersectXAxis = target.Location.X <aX + (TDMap.GridSize - 2) && target.Location.X + (TDMap.GridSize - 2)> bX;
            }

            // y between
            if (aY < bY)
            {
                intersectYAxis = target.Location.Y <bY + (TDMap.GridSize - 2) && target.Location.Y + (TDMap.GridSize - 2)> aY;
            }
            else
            {
                intersectYAxis = target.Location.Y <aY + (TDMap.GridSize - 2) && target.Location.Y + (TDMap.GridSize - 2)> bY;
            }

            // if it intersects the rectangle of the two
            result = intersectXAxis && intersectYAxis;

            // if it is within the square box, and is a diagonal line, check it additionally because it might not be on the actual path.
            if (result &&
                aX != bX && aY != bY) // neither a horizontal or vertical line
            {
                // use graphing formulas y=Mx+b to see if the location is on the line (or within range of the line).
                // y = (Mx + b)
                // y = ((^Y / ^X) * x + b)
                // target.y = ((changeY / changeX)* target.x + b)
                // target.y = (((bY-aY) / (bX-aX))* target.x + b))
                double slope = (bY - aY) / (bX - aX);
                // to find b, use b = y - mx, and we put in one of the points
                double b          = aY - (slope * aX);
                double estimatedY = slope * target.Location.X + b;
                // actual Y needs to be 'close' to the estimated Y of the line
                result = (Math.Abs(target.Location.Y - estimatedY) < (TDMap.GridSize - 1));
            }

            return(result);
        }
Exemple #9
0
        internal bool isTowerOnTowers(TDTower target)
        {
            foreach (TDTower t in this.Towers)
            {
                if (TDMath.Intersects(target.Location, target.Size, t.Location, t.Size))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #10
0
        public bool CanPlaceTower(TDTower t)
        {
            if (Map.isTowerOnPath(t))
            {
                return(false);
            }

            // if on other tower - no
            if (isTowerOnTowers(t))
            {
                return(false);
            }

            return(true);
        }
Exemple #11
0
        public TDTowerButton()
            : base()
        {
            this.Tower = null;
            this.Text  = "unknown tower";

            this.Appearance = System.Windows.Forms.Appearance.Button;
            this.Enabled    = false;
            this.TextAlign  = System.Drawing.ContentAlignment.MiddleCenter;
            this.Tower      = null;
            this.UseVisualStyleBackColor = true;

            this.MouseEnter += TDTowerButton_MouseEnter;
            this.MouseLeave += TDTowerButton_MouseLeave;

            this.Click += TDTowerButton_Click;

            this.Padding = new Padding(1);
        }
Exemple #12
0
 private bool TowerWithinRange(TDTower tower)
 {
     return(TDMath.PointInRange(this.Location, tower.Location, this.Range));
 }
Exemple #13
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();
                }
            }
        }