Exemplo n.º 1
0
        private void __moving(object sender, EventArgs e)
        {
            this.timer.Stop();

            PlayerPosition target = this.nextWaypoint.position;

            if (this.useSinglePosition)
            {
                target = this.singleTargetPosition;
            }

            PlayerPosition currentPosition = this.memory.position();

            Double angle    = currentPosition.angleBetweenPosition(target);
            Double distance = currentPosition.distanceBetweenPosition(target);

            this.movingToWaypoint(this.currentIndex, distance);

            // final radian to target
            double targetRadian = currentPosition.r - angle;

            targetRadian = MathEx.normalizeAngle(targetRadian);

            Int32 waypointsLeft = this.waypointCount - this.currentIndex;


            // core movement logic
            // move to waypoint if distance lower then minDistanceToMove
            if (distance > SettingsSingleton.Instance.timings.minMovementDistanceToNextWaypoint && !this.isCaneling && (!this.isPaused || this.singleMovement))
            {
                // adjust view direction to target
                this.__adjustToTarget(angle, targetRadian);

                // walk only if angle < (-+) min limit
                if (MathEx.isInRange(angle, SettingsSingleton.Instance.timings.minRadianDifferanceToMove, -SettingsSingleton.Instance.timings.minRadianDifferanceToMove))
                {
                    // avoid running idiot circle bug
                    if (distance < 5 && !MathEx.isInRange(angle, 0.2, -0.2))
                    {
                        this.keyboard.releaseForwardKey();
                    }
                    else
                    {
                        this.keyboard.holdForwardKey();
                    }
                    // move forward
                }
                else
                {
                    this.keyboard.releaseForwardKey();
                }
            }
            else
            {
                // release all keys and dispose current waypoint moving
                // release forward moving not On waypoint walking  ... smoother look
                if (waypointsLeft < 2 || this.singleMovement)
                {
                    this.keyboard.releaseForwardKey();
                }
                this.keyboard.releaseRotateRightKey();
                this.keyboard.releaseRotateLeftKey();
                this.finishWaypointMovement();
                return;
            }
            this.timer.Start();
        }
Exemplo n.º 2
0
 public Double distanceBetweenPosition(PlayerPosition p)
 {
     return(Math.Sqrt((p.x - this.x) * (p.x - this.x) + (p.y - this.y) * (p.y - this.y)));
 }