Exemple #1
0
        public bool CanDetect(Detectable detectable)
        {
            var dist = this.GetDistance(detectable);

            if (dist > __DetectRange ||
                !this.SameQuadrant(this.EndPoint, detectable.Location) ||
                this.GetDistance(detectable.Location, new Point(0, 0)) > this.Length)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        private void Spawn()
        {
            //remove this test
            if (this._Detectables.Count > 0)
            {
                return;
            }

            var p = new Point(100, 100);

            var ufo = new Detectable
            {
                Bounds   = new Rectangle(0, 0, this._View.Size.Width, this._View.Size.Height),
                Location = p
            };

            this._Detectables.Add(ufo);
        }
Exemple #3
0
        private double GetDistance(Detectable detectable)
        {
            var startPoint = this.StartPoint;
            var endPoint   = this.EndPoint;

            var x0 = startPoint.X;
            var y0 = startPoint.Y;
            var x1 = endPoint.X;
            var y1 = endPoint.Y;
            var xp = detectable.Location.X;
            var yp = detectable.Location.Y;

            var lambda = (((x1 - x0) * (xp - x0)) + ((y1 - y0) * (yp - y0)))
                         /
                         (Math.Pow(x1 - x0, 2) + Math.Pow(y1 - y0, 2));

            var dist = Math.Sqrt(Math.Pow(xp - x0 - (lambda * (x1 - x0)), 2)
                                 + Math.Pow(yp - y0 - (lambda * (y1 - y0)), 2));

            return(dist);
        }