Example #1
0
        private int GetClosestIndex(List<D3DXVECTOR2> PList, D3DXVECTOR2 curPos)
        {
            var n = 0;

            PList.ForEach(p => n = Distance(curPos, p) < Distance(curPos, PList[n]) ? PList.IndexOf(p) : n);

            return n;
        }
Example #2
0
        /// <summary>
        /// Rotates the character's model, to face the given destination point.
        /// </summary>
        /// <param name="pointB">The destination point</param>
        protected void ModelRotation(D3DXVECTOR2 pointB)
        {
            // Get new heading angle, for the given point.
            var newHeading = HeadingToRad(AllEntities.Get2DPos(), pointB);

            // Get new 3D matrix Y axis vector, rotated to the given angle.
            var newVector = GetNewVector(newHeading);

            // Set new heading
            Funcs.SetHeading(EntityType.PCMob, 0, newHeading);

            // Set new rotation vector.
            Funcs.Set3DVector(EntityType.PCMob, Axis.X, 0, newVector.x);
            Funcs.Set3DVector(EntityType.PCMob, Axis.Y, 0, newVector.y);
        }
Example #3
0
 protected float Distance(D3DXVECTOR2 p1, D3DXVECTOR2 p2)
 {
     return Distance(p1.y, p1.x, p2.y, p2.x);
 }
Example #4
0
 protected float HeadingToRad(D3DXVECTOR2 from, D3DXVECTOR2 to)
 {
     return (float)Math.Atan2((to.x - from.x), (to.y - from.y));
 }
Example #5
0
        public void Walk(float x, float y, bool KeepWalking)
        {
            if (Moving)
                return;
            Moving = true;

            HaltFlag = false;
            float heading;
            float tobeHeading;
            var waypoint = new D3DXVECTOR2(x, y);
            if (CorDelay)
                Funcs.SetMoveStatus(WalkingStatus.Standing);

            ModelRotation(waypoint);

            if (CamReset)
                SendKeyPress(KeyStates.Toggled, Key.End);

            if (CorDelay)
                Thread.Sleep(HeadToll);

            var decX = (Funcs.GetPOS(EntityType.PCMob, Axis.X, 0) > x);

            Funcs.SetMoveStatus(WalkingStatus.Autorun | WalkingStatus.Running);

            if (decX)
            {
                while (Funcs.GetPOS(EntityType.PCMob, Axis.X, 0) > x)
                {
                    if (HaltFlag)
                    {
                        Funcs.SetMoveStatus(WalkingStatus.Standing);
                        Moving = false;
                        return;
                    }
                    if (AICorrection)
                    {
                        heading = Funcs.GetHeading(EntityType.PCMob, 0);

                        tobeHeading = HeadingToRad(AllEntities.Get2DPos(), waypoint);

                        // Check if our heading is within our tolerance.
                        if (tobeHeading - heading < 0 ? tobeHeading - heading < -0.1f : tobeHeading - heading > 0.1f)
                            ModelRotation(waypoint);
                    }
                    Thread.Sleep(10);
                }
            }
            else
            {
                while (Funcs.GetPOS(EntityType.PCMob, Axis.X, 0) < x)
                {
                    if (HaltFlag)
                    {
                        Funcs.SetMoveStatus(WalkingStatus.Standing);
                        Moving = false;
                        return;
                    }
                    if (AICorrection)
                    {
                        heading = Funcs.GetHeading(EntityType.PCMob, 0);
                        tobeHeading = HeadingToRad(AllEntities.Get2DPos(), waypoint);

                        // Check if our heading is within our tolerance.
                        if (tobeHeading - heading < 0 ? tobeHeading - heading < -0.1f : tobeHeading - heading > 0.1f)
                            ModelRotation(waypoint);
                    }
                    Thread.Sleep(10);
                }
            }
            if (!KeepWalking)
                Funcs.SetMoveStatus(WalkingStatus.Standing);
            Moving = false;
        }