Ejemplo n.º 1
0
        private double CalculateDistanceToBullet(BulletWave ew)
        {
            var traveledDistance = ew.GetTraveledDistance(Time);
            var curDistance      = Helper.GetDistance(ew.StartX, ew.StartY, X, Y);

            return(curDistance - traveledDistance);
        }
Ejemplo n.º 2
0
        // CREDIT: mini sized predictor from Apollon, by rozu
        // http://robowiki.net?Apollon
        private PointF PredictPosition(BulletWave surfWave, int direction)
        {
            PointF predictedPosition = new PointF((float)X, (float)Y);
            double predictedVelocity = Velocity;
            double predictedHeading = HeadingRadians;
            double maxTurning, moveAngle, moveDir;

            int  counter     = 0; // number of ticks in the future
            bool intercepted = false;

            do
            {    // the rest of these code comments are rozu's
                var angleInRadian = Helper.GetAbsBearingInRadian(surfWave.StartX, surfWave.StartY, predictedPosition.X, predictedPosition.Y) + (direction * (Math.PI / 2));
                moveAngle = WallSmoothing(predictedPosition.X, predictedPosition.Y, angleInRadian, direction) - predictedHeading;
                moveDir   = 1;

                if (Math.Cos(moveAngle) < 0)
                {
                    moveAngle += Math.PI;
                    moveDir    = -1;
                }

                moveAngle = Utils.NormalRelativeAngle(moveAngle);

                // maxTurning is built in like this, you can't turn more then this in one tick
                maxTurning       = Math.PI / 720d * (40d - 3d * Math.Abs(predictedVelocity));
                predictedHeading = Utils.NormalRelativeAngle(predictedHeading + Helper.Limit(-maxTurning, moveAngle, maxTurning));

                // this one is nice ;). if predictedVelocity and moveDir have
                // different signs you want to breack down
                // otherwise you want to accelerate (look at the factor "2")
                predictedVelocity += (predictedVelocity * moveDir < 0 ? 2 * moveDir : moveDir);
                predictedVelocity  = Helper.Limit(-8, predictedVelocity, 8);

                // calculate the new predicted position
                predictedPosition = Helper.GetProjection(predictedPosition.X, predictedPosition.Y, predictedHeading, predictedVelocity);

                counter++;

                //todo: check if we can add _radius
                if (Helper.GetDistance(predictedPosition.X, predictedPosition.Y, surfWave.StartX, surfWave.StartY) + _radius <
                    surfWave.GetTraveledDistance(Time) + (counter + 1) * surfWave.Velocity)
                {
                    intercepted = true;
                }
            } while (!intercepted && counter < 500);

            return(predictedPosition);
        }