Пример #1
0
        public sDirections GetDirectionForNext(sVect curVec, sPoint curLoc)
        {
            sDirections result = sDirections.Null;

            if (curVec.Length < (this.size * 3) && curVec.Length > 0)
            {
                int offset = Convert.ToInt32(Math.Floor((this.size * 3) / curVec.Length));

                curVec.MultiplyBy(offset); // make longer to ensure it will intersect side
            }

            Line north = this.Side[(int)sDirections.North];
            Line west = this.Side[(int)sDirections.West];
            Line south = this.Side[(int)sDirections.South];
            Line east = this.Side[(int)sDirections.East];

            Line test = curVec.toLine(curLoc);

            if (this.DoLinesIntersect(north, test))
            {
                sPoint intersect = this.GetLinesIntersect(north, test);

                if (intersect == north.Start)
                {
                    result = sDirections.NorthWest;
                }
                else if (intersect == north.End)
                {
                    result = sDirections.NorthEast;
                }
                else
                {
                    result = sDirections.North;
                }
            }
            else if (this.DoLinesIntersect(west, test))
            {
                sPoint intersect = this.GetLinesIntersect(west, test);

                if (intersect == west.Start)
                {
                    result = sDirections.NorthWest;
                }
                else if (intersect == west.End)
                {
                    result = sDirections.SouthWest;
                }
                else
                {
                    result = sDirections.West;
                }
            }
            else if (this.DoLinesIntersect(south, test))
            {
                sPoint intersect = this.GetLinesIntersect(west, test);

                if (intersect == south.Start)
                {
                    result = sDirections.SouthWest;
                }
                else if (intersect == south.End)
                {
                    result = sDirections.SouthEast;
                }
                else
                {
                    result = sDirections.South;
                }
            }
            else if (this.DoLinesIntersect(east, test))
            {
                sPoint intersect = this.GetLinesIntersect(west, test);

                if (intersect == east.Start)
                {
                    result = sDirections.NorthEast;
                }
                else if (intersect == east.End)
                {
                    result = sDirections.SouthEast;
                }
                else
                {
                    result = sDirections.East;
                }
            }

            return result;
        }
Пример #2
0
 public void AddVector(sVect v)
 {
     this.X = this.X + v.X;
     this.Y = this.Y + v.Y;
 }