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); }
private SdkWrapper() { CreateClient(); FlipActions = new FlipActions(_udpClient); FlyActions = new FlyActions(_udpClient); RotationActions = new RotationActions(_udpClient); BaseActions = new BaseActions(_udpClient); SpeedAction = new SpeedAction(_udpClient); }
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; }
private void OnDestroy() { speedAdjustAction = null; }