protected override void Update(GameTime gameTime) { currKeyboard = Keyboard.GetState(); if (currKeyboard.IsKeyDown(Keys.Escape) && currKeyboard.IsKeyDown(Keys.LeftShift)) { this.Exit(); } if (!console.Opened) { camera.HandleInput(); // View options if (keyPressed(Keys.F11)) { toggleFullscreen(); } if (keyPressed(Keys.F12)) { backgroundLight = !backgroundLight; } if (keyPressed(Keys.C)) { drawCar = !drawCar; } if (keyPressed(Keys.R)) { rotateCar = !rotateCar; } if (keyPressed(Keys.G)) { drawGrid = !drawGrid; } if (keyPressed(Keys.V)) { drawVoro = !drawVoro; } if (keyPressed(Keys.B)) { if (currKeyboard.IsKeyDown(Keys.LeftShift) || currKeyboard.IsKeyDown(Keys.RightShift)) { watchSearch = !watchSearch; } else { drawSearch = !drawSearch; } } if (keyPressed(Keys.P)) { drawPath = !drawPath; } if (keyPressed(Keys.L)) { drawSmoothedPath = !drawSmoothedPath; drawController = false; } if (keyPressed(Keys.O)) { drawController = !drawController; drawSmoothedPath = false; } if (keyPressed(Keys.F)) { drawFrontPath = !drawFrontPath; } if (keyPressed(Keys.Home)) { drawStart = !drawStart; } if (keyPressed(Keys.End)) { drawGoal = !drawGoal; } if (keyPressed(Keys.Scroll)) { drawCurrent = !drawCurrent; } // Zoom if (currKeyboard.IsKeyDown(Keys.OemPlus)) { scale *= 1.02f; } if (currKeyboard.IsKeyDown(Keys.OemMinus)) { scale *= 0.98f; } // Translate if (currKeyboard.IsKeyDown(Keys.Up)) { yOffset += 5f / scale; } if (currKeyboard.IsKeyDown(Keys.Down)) { yOffset -= 5f / scale; } if (currKeyboard.IsKeyDown(Keys.Right)) { xOffset += 5f / scale; } if (currKeyboard.IsKeyDown(Keys.Left)) { xOffset -= 5f / scale; } if (currKeyboard.IsKeyDown(Keys.W)) { gas = 1; } else if (currKeyboard.IsKeyDown(Keys.S)) { gas = -1; } else { gas = 0; } if (currKeyboard.IsKeyDown(Keys.D)) { steer = -1; } else if (currKeyboard.IsKeyDown(Keys.A)) { steer = 1; } else { steer = 0; } if (currKeyboard.IsKeyDown(Keys.Space)) { brake = 1; } else { brake = 0; } if (gas != 0 || brake != 0 || steer != 0) { autoDrive = false; } if (currKeyboard.IsKeyDown(Keys.Enter) && pathSmoothDone) { run = true; } // Camera views if (keyPressed(Keys.D1)) { cameraView = 1; } if (keyPressed(Keys.D2)) { cameraView = 2; } if (keyPressed(Keys.D3)) { cameraView = 3; } if (keyPressed(Keys.D4)) { cameraView = 4; } if (keyPressed(Keys.D5)) { cameraView = 5; } if (keyPressed(Keys.D0)) { ClearWorld(); InitSim(false); } } prevKeyboard = currKeyboard; if (autoDrive) { if (run) { currentControls = controller.Update(car.Pose, car.WheelAngle, car.SpeedMetersPerSecond, gameTime); car.Update(currentControls); } } else { currentControls = new CarControls(gas, brake, steer); car.Update(new CarControls(gas, brake, steer)); } if (run && controller.State == StanleyFSMController.ControllerState.MissionComplete && MissionCompleted != null) { MissionCompleted(this, controller.Info); } world.Step((float)gameTime.ElapsedGameTime.TotalSeconds); dashboard.Update(car.WheelAngle, currentControls.Gas, currentControls.Brake, car.SpeedMPH); if (isCollided && Collided != null) { Collided(this, null); } base.Update(gameTime); }