Clear() public method

public Clear ( ) : void
return void
コード例 #1
0
        public override void Loop(MovingObject pShip)
        {
            if (Targets.Count == 0)
            {
                Targets.Add(new Vector3((Methods.Random.NextDouble() - 0.5) * World.Instance.Arena.Width, (Methods.Random.NextDouble() - 0.5) * World.Instance.Arena.Height, 0));
            }

            InputStates.Clear();
            //InputStates.Fire = Methods.Random.Next(128) == 0; // Temporary random fire.

            InputStates.Add(MoveToNextTarget(pShip));
            InputStates.DetectPresses();
        }
コード例 #2
0
        protected InputStates MoveToNextTarget(MovingObject pShip)
        {
            temporaryAdditionInputState.Clear();

            if (Targets.Count <= 0)
            {
                return(temporaryAdditionInputState);
            }

            var nextTarget     = Targets[0];
            var vectorToTarget = Methods.ToVector2(nextTarget - pShip.Position);                                                          // Direction to target.
            var vectorToFacing = Methods.ToVector2(pShip.Velocity + 4 * Methods.AngleToVector(pShip.Angle * Constants.DegreesToRadians)); // Ship's velocity plus a little bit of it's rotation.
            var vectorAlong    = Methods.Projection(vectorToFacing, vectorToTarget);                                                      // The part of the facing vector that is in line with the target (how close we are to pointing to the target).
            var vectorAside    = vectorToTarget - vectorAlong;                                                                            // The part of the facing vector that is looking to the side of the target (how close we are to looking 90 degrees away from the target).

            if (vectorAside.Length < vectorAlong.Length * 2 && vectorToTarget.Dot(vectorToFacing) > 0)                                    // Generally facing target.
            {
                temporaryAdditionInputState.Up = true;
            }
            if (vectorAside.Length * 8 > vectorAlong.Length || vectorToTarget.Dot(vectorToFacing) < 0) // Accurately facing target.
            {
                if (vectorToFacing.Perpendicular.Dot(vectorToTarget) < 0)                              // Target is to the left.
                {
                    temporaryAdditionInputState.Left = true;
                }
                else
                {
                    temporaryAdditionInputState.Right = true;
                }
            }
            if ((nextTarget - pShip.Position).Length < (Targets.Count > 1 ? 32 : 16))             // Are we there yet? More lenient if there are more waypoints to come.
            {
                Targets.RemoveAt(0);
            }

            return(temporaryAdditionInputState);
        }