コード例 #1
0
ファイル: Driver.cs プロジェクト: CompleteBrains/Escape
        //------------------------------------------------------------------
        protected Driver(Car car)
            : base(car)
        {
            Loop = new Loop();
            Sequence = new Sequence();
            AddInLoop (Sequence);

            Car = car;

            Velocity = Car.Lane.Velocity;
            ChangeLaneSpeed = 1;
            SafeZone = new SafeZone (this, 1);
            Primary = Direction.Left;
        }
コード例 #2
0
ファイル: Driver.cs プロジェクト: CompleteBrains/Escape
        //------------------------------------------------------------------
        private bool IsAnimationDisabled(Sequence action)
        {
            if (!Settings.NoChangeLaneAnimation) return false;

            // Move Car instead of the Animation
            action.Add (new Generic (() => Car.DockToLane()));

            return true;
        }
コード例 #3
0
ファイル: Driver.cs プロジェクト: CompleteBrains/Escape
 //------------------------------------------------------------------
 public bool IsInLoop(Sequence newAction)
 {
     return Loop.Actions.Any (action => action.GetType() == newAction.GetType());
 }
コード例 #4
0
ファイル: Driver.cs プロジェクト: CompleteBrains/Escape
        //------------------------------------------------------------------
        public bool TryChangeLane(Sequence action, Lane lane, float duration)
        {
            // Prevent changing on incorrect Lanes
            if (lane == null) return false;
            if (lane != Car.Lane.Left && lane != Car.Lane.Right) return false;

            // Check free space on Lane
            if (!CheckLane (lane)) return false;

            // Change Lane
            ChangeLane (action, lane, duration);

            return true;
        }
コード例 #5
0
ファイル: Driver.cs プロジェクト: CompleteBrains/Escape
        //------------------------------------------------------------------
        public void ChangeLane(Sequence action, Lane lane, float duration)
        {
            if (lane == null) return;

            // No Lane changing when car doesn't move
            if (Car.Velocity < 10) return;

            // Add to the new Lane
            action.Add (new Generic (() => lane.Add (Car)));

            if (IsAnimationDisabled (action)) return;

            // Rotate
            Action <float> rotate = share => Car.Drawable.Rotation += share;
            float finalAngle = MathHelper.ToRadians ((lane.Position.X < Car.Position.X) ? -10 : 10);
            action.Add (new Controller (rotate, finalAngle, duration * 0.3f));

            // Moving
            Action <Vector2> move = shift => Car.LocalPosition += shift;
            var diapason = new Vector2 (lane.Position.X - Car.Position.X, 0);
            action.Add (new Controller (move, diapason, duration * 0.4f));

            // Inverse rotating
            var inverseRotating = new Controller (rotate, -finalAngle, duration * 0.3f);
            action.Add (inverseRotating);

            // Fix accuracy error in Car's Position
            action.Add (new Generic (() => Car.DockToLane()));
        }