public override void Update(GameTime gameTime) { KeyboardState keyState = Keyboard.GetState(); if (!Game1.Instance.Camera.isRoverCamera) { if (keyState.IsKeyDown(Keys.B)) { //turn the container for camera laser left roverMovement.RotationCameraLaserYAxis(0.01f); } if (keyState.IsKeyDown(Keys.M)) { //turn the container for camera laser right roverMovement.RotationCameraLaserYAxis(-0.01f); } if (keyState.IsKeyDown(Keys.H)) { // So the camera/laser can only look up a certain amount if (roverMovement.cameraLaserContainerXaxisRotation.Motor.Settings.Servo.Goal >= -maximumTurnAngle) { roverMovement.RotationXAxis(-0.01f, right); } } if (keyState.IsKeyDown(Keys.N)) { // So the camera/laser can only look down a certain amount if (roverMovement.cameraLaserContainerXaxisRotation.Motor.Settings.Servo.Goal <= maximumTurnAngle) { roverMovement.RotationXAxis(0.01f, right); } } } if(keyState.IsKeyDown(Keys.F)) { //the drill cylinder looks up SetDrillOrientation(-0.01f); } if (keyState.IsKeyDown(Keys.V)) { //the drill cylinder looks down SetDrillOrientation(0.01f); } if(keyState.IsKeyDown(Keys.Space)) { //create the laser to shoot & add to game Lazer laser = new Lazer(); laserShot.Play(); laser.pos = cameraLaserContainer.body.Position; laser.look = GetLaserLook(); Game1.Instance.Children.Add(laser); } //code taken from bepu physics demo suspensioncardemo.cs and adapted for this project roverMovement.steeringMotor1.Settings.Servo.BaseCorrectiveSpeed = 3 + 7 * Math.Min(roverMovement.steeringMotor1.ConnectionB.AngularVelocity.Length() / 100, 1); roverMovement.steeringMotor2.Settings.Servo.BaseCorrectiveSpeed = 3 + 7 * Math.Min(roverMovement.steeringMotor2.ConnectionB.AngularVelocity.Length() / 100, 1); if (keyState.IsKeyDown(Keys.Down)) { //move rover backward roverMovement.MoveForwardBackward(-driveSpeed); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(0); } } else if (keyState.IsKeyDown(Keys.Up)) { //move rover forward roverMovement.MoveForwardBackward(driveSpeed); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(0); } } else { //turn driving motor off roverMovement.SetMotorActive(false); } if (keyState.IsKeyDown(Keys.Left)) { //turn rover left roverMovement.TurnLeftRight(maximumTurnAngle); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(0.01f); } } else if (keyState.IsKeyDown(Keys.Right)) { //turn rover right roverMovement.TurnLeftRight(-maximumTurnAngle); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(-0.01f); } } else { //Face forward roverMovement.steeringMotor1.Settings.Servo.Goal = 0; roverMovement.steeringMotor2.Settings.Servo.Goal = 0; } if (keyState.IsKeyDown(Keys.P)) { if (elapsed > (1.0f / fireRate)) { //Change to or out of the rovers camera if (Game1.Instance.Camera.isRoverCamera == false) { //set look vector and position of camera and if it is rover camera, changes controls if it is ChangeCameraBeingUsed(GetCameraRoverPosition(), GetLaserLook(), true); } else { //put camera back to normal ChangeCameraBeingUsed(new Vector3(248, 64, -200), new Vector3(0.0f, 0.0f, -1.0f),false); } elapsed = 0.0f; } } elapsed += (float) gameTime.ElapsedGameTime.TotalSeconds;//used so cant chnge between normal camera and rover camera too quickly if (elapsed >= 25.0f) { elapsed = 25.0f; } if (keyState.IsKeyDown(Keys.E)) { //set the rover to explode if (!exploded) { Explosion createExplosion = new Explosion(Vector3.Zero, 2000, 30, Game1.Instance.Space); createExplosion.Position = roverBase.body.Position; //disable all the joints foreach (RevoluteJoint joint in roverMovement.roverJoints) joint.IsActive = false; foreach (var suspensionString in roverMovement.suspensionSprings) suspensionString.IsActive = false; foreach (var joint in roverMovement.joints) joint.IsActive = false; foreach (var motor in roverMovement.motors) motor.IsActive = false; //start the explosion createExplosion.Explode(); explosionSound.Play(); exploded = true; } } }
public override void Update(GameTime gameTime) { KeyboardState keyState = Keyboard.GetState(); if (!Game1.Instance.Camera.isRoverCamera) { if (keyState.IsKeyDown(Keys.B)) { //turn the container for camera laser left roverMovement.RotationCameraLaserYAxis(0.01f); } if (keyState.IsKeyDown(Keys.M)) { //turn the container for camera laser right roverMovement.RotationCameraLaserYAxis(-0.01f); } if (keyState.IsKeyDown(Keys.H)) { // So the camera/laser can only look up a certain amount if (roverMovement.cameraLaserContainerXaxisRotation.Motor.Settings.Servo.Goal >= -maximumTurnAngle) { roverMovement.RotationXAxis(-0.01f, right); } } if (keyState.IsKeyDown(Keys.N)) { // So the camera/laser can only look down a certain amount if (roverMovement.cameraLaserContainerXaxisRotation.Motor.Settings.Servo.Goal <= maximumTurnAngle) { roverMovement.RotationXAxis(0.01f, right); } } } if (keyState.IsKeyDown(Keys.F)) { //the drill cylinder looks up SetDrillOrientation(-0.01f); } if (keyState.IsKeyDown(Keys.V)) { //the drill cylinder looks down SetDrillOrientation(0.01f); } if (keyState.IsKeyDown(Keys.Space)) { //create the laser to shoot & add to game Lazer laser = new Lazer(); laserShot.Play(); laser.pos = cameraLaserContainer.body.Position; laser.look = GetLaserLook(); Game1.Instance.Children.Add(laser); } //code taken from bepu physics demo suspensioncardemo.cs and adapted for this project roverMovement.steeringMotor1.Settings.Servo.BaseCorrectiveSpeed = 3 + 7 * Math.Min(roverMovement.steeringMotor1.ConnectionB.AngularVelocity.Length() / 100, 1); roverMovement.steeringMotor2.Settings.Servo.BaseCorrectiveSpeed = 3 + 7 * Math.Min(roverMovement.steeringMotor2.ConnectionB.AngularVelocity.Length() / 100, 1); if (keyState.IsKeyDown(Keys.Down)) { //move rover backward roverMovement.MoveForwardBackward(-driveSpeed); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(0); } } else if (keyState.IsKeyDown(Keys.Up)) { //move rover forward roverMovement.MoveForwardBackward(driveSpeed); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(0); } } else { //turn driving motor off roverMovement.SetMotorActive(false); } if (keyState.IsKeyDown(Keys.Left)) { //turn rover left roverMovement.TurnLeftRight(maximumTurnAngle); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(0.01f); } } else if (keyState.IsKeyDown(Keys.Right)) { //turn rover right roverMovement.TurnLeftRight(-maximumTurnAngle); if (Game1.Instance.Camera.isRoverCamera) { SetRoverCamera(-0.01f); } } else { //Face forward roverMovement.steeringMotor1.Settings.Servo.Goal = 0; roverMovement.steeringMotor2.Settings.Servo.Goal = 0; } if (keyState.IsKeyDown(Keys.P)) { if (elapsed > (1.0f / fireRate)) { //Change to or out of the rovers camera if (Game1.Instance.Camera.isRoverCamera == false) { //set look vector and position of camera and if it is rover camera, changes controls if it is ChangeCameraBeingUsed(GetCameraRoverPosition(), GetLaserLook(), true); } else { //put camera back to normal ChangeCameraBeingUsed(new Vector3(248, 64, -200), new Vector3(0.0f, 0.0f, -1.0f), false); } elapsed = 0.0f; } } elapsed += (float)gameTime.ElapsedGameTime.TotalSeconds; //used so cant chnge between normal camera and rover camera too quickly if (elapsed >= 25.0f) { elapsed = 25.0f; } if (keyState.IsKeyDown(Keys.E)) { //set the rover to explode if (!exploded) { Explosion createExplosion = new Explosion(Vector3.Zero, 2000, 30, Game1.Instance.Space); createExplosion.Position = roverBase.body.Position; //disable all the joints foreach (RevoluteJoint joint in roverMovement.roverJoints) { joint.IsActive = false; } foreach (var suspensionString in roverMovement.suspensionSprings) { suspensionString.IsActive = false; } foreach (var joint in roverMovement.joints) { joint.IsActive = false; } foreach (var motor in roverMovement.motors) { motor.IsActive = false; } //start the explosion createExplosion.Explode(); explosionSound.Play(); exploded = true; } } }