示例#1
0
        public void Update(GameTime gameTime, SpeedAction speedAction, TurningAction turningAction)
        {
            CurrentLapTime += gameTime.ElapsedGameTime;

            UpdateDirection(turningAction);
            UpdatePosition(speedAction);
        }
        public (SpeedAction speedAction, TurningAction turningAction) GetDrivingActions(Car car, TrackManager trackManager)
        {
            var kb = Keyboard.GetState();

            SpeedAction   speedAction;
            TurningAction turningAction;

            if (kb.IsKeyDown(Keys.W))
            {
                speedAction = SpeedAction.Accelerate;
            }
            else if (kb.IsKeyDown(Keys.S))
            {
                speedAction = SpeedAction.Reverse;
            }
            else
            {
                speedAction = SpeedAction.Coast;
            }

            if (kb.IsKeyDown(Keys.A))
            {
                turningAction = TurningAction.TurnLeft;
            }
            else if (kb.IsKeyDown(Keys.D))
            {
                turningAction = TurningAction.TurnRight;
            }
            else
            {
                turningAction = TurningAction.None;
            }

            return(speedAction, turningAction);
        }
示例#3
0
 private SdkWrapper()
 {
     CreateClient();
     FlipActions     = new FlipActions(_udpClient);
     FlyActions      = new FlyActions(_udpClient);
     RotationActions = new RotationActions(_udpClient);
     BaseActions     = new BaseActions(_udpClient);
     SpeedAction     = new SpeedAction(_udpClient);
 }
示例#4
0
        private void UpdatePosition(SpeedAction speedAction)
        {
            IsBraking = false;

            switch (speedAction)
            {
            case SpeedAction.Accelerate:
            {
                if (CurrentSpeed < 0)
                {
                    IsBraking     = true;
                    CurrentSpeed += BrakingForce;
                }
                else if (CurrentSpeed < MaxSpeed)
                {
                    CurrentSpeed += Acceleration;
                }
                break;
            }

            case SpeedAction.Reverse:
            {
                if (CurrentSpeed > 0)
                {
                    IsBraking     = true;
                    CurrentSpeed -= BrakingForce;
                }
                else if (CurrentSpeed > -MaxSpeed)
                {
                    CurrentSpeed -= Acceleration;
                }
                break;
            }

            case SpeedAction.Coast:
            {
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(speedAction), speedAction, null);
            }

            CurrentSpeed += -DragFactor *CurrentSpeed *MathF.Abs(CurrentSpeed);

            Position += DirectionVector * CurrentSpeed;
        }
示例#5
0
 private void OnDestroy()
 {
     speedAdjustAction = null;
 }