Example #1
0
        private TDEntity GetTowerAtPoint(Point point)
        {
            if (TDSession.thisSession == null ||
                TDSession.thisSession.CurrentLevel == null)
            {
                return(null);
            }

            TDLocation p = new TDLocation(point.X, point.Y);

            foreach (TDAttacker a in TDSession.thisSession.CurrentLevel.Attackers)
            {
                if (TDMath.PointOnPoint(a.Location, p, a.Size))
                {
                    return(a);
                }
            }

            foreach (TDTower t in TDSession.thisSession.CurrentLevel.Towers)
            {
                if (TDMath.PointOnPoint(t.Location, p, t.Size))
                {
                    return(t);
                }
            }

            // if not a tower or attacker, then nothing
            return(null);
        }
Example #2
0
        public void Update()
        {
            // if on target
            if (this.Seeking &&
                TDMath.PointOnPoint(this.CurrentLocation, target.Location, (int)(this.speed * TDSession.SpeedFactor)))
            {
                HitTarget(target as TDEntity);
            }
            else
            {
                // if on any target type
                if (target is TDAttacker)
                {
                    // hit any target
                    for (int i = 0; i < TDSession.thisSession.CurrentLevel.Attackers.Count; i++)
                    {
                        if (TDSession.thisSession.CurrentLevel.Attackers[i] != this.source &&
                            TDMath.PointOnPoint(this.CurrentLocation,
                                                TDSession.thisSession.CurrentLevel.Attackers[i].Location,
                                                TDSession.thisSession.CurrentLevel.Attackers[i].Size))
                        {
                            HitTarget(TDSession.thisSession.CurrentLevel.Attackers[i] as TDEntity);
                            break;
                        }
                    }
                }
                else // if target is TDTower
                {
                    // hit any tower
                    for (int i = 0; i < TDSession.thisSession.CurrentLevel.Towers.Count; i++)
                    {
                        if (TDMath.PointOnPoint(this.CurrentLocation,
                                                TDSession.thisSession.CurrentLevel.Towers[i].Location,
                                                TDSession.thisSession.CurrentLevel.Towers[i].Size))
                        {
                            HitTarget(TDSession.thisSession.CurrentLevel.Towers[i] as TDEntity);
                            break;
                        }
                    }
                }

                // move toward target
                MoveToward(target.Location);
            }
        }
Example #3
0
 private bool OnPoint(TDLocation L1, TDLocation L2)
 {
     return(TDMath.PointOnPoint(L1, L2, (int)Math.Max(1, this.SpeedCurrent * TDSession.SpeedFactor)));
 }