protected override void FrameMove() { int fps = (int)framePerSecond; debugText = "FPS: " + fps.ToString() + "\r\n"; debugText += "ShipLocation:\r\n" + playerShip.Location.ToString(); debugText += "CameraMode: " + cameraMode.ToString() + "\r\n"; debugText += "Use the mouse to rotate your ship, and W or the \r\n" + "up arrow to thrust forward. The C key changes the camera views. F5-F10 for sounds \r\n\r\n"; ProcessInput(); MouseControlValues v = mouseInput.Values; if (v.FireButtonPushed) { playerShip.Shoot(); } float yawAmount = mouseLoc.X - screenCenter.X; float pitchAmount = mouseLoc.Y - screenCenter.Y; playerShip.YawPitchRoll(yawAmount, pitchAmount, elapsedTime); playerShip.SetThrust(v.ThrustButtonPushed | kbThrust, elapsedTime); playerShip.UpdatePosition(elapsedTime); /*Here we set up the view matrix and space dome location. The space dome moves but not rotates with the player * and is alway drawn first, so it looks like it is infinitely distant. * * In chase mode, the chaseMatrix determines the offset from the ship. If you want to move our viewpoint * back from the ship more, increase the negative z value. * * The fixed mode camera sits at the origin and always tracks the player ship. Very hard to control from * this viewpoint, but cool to watch. */ Vector3 spaceSphereLocation = new Vector3(0, 0, 0); switch (cameraMode) { case CameraMode.ChaseMode: { Matrix chaseMatrix = Matrix.Translation(0, 6, -14); chaseMatrix *= playerShip.Position.WorldMatrix; viewMatrix = Matrix.Invert(chaseMatrix); spaceSphereLocation = playerShip.Position.Location; break; } case CameraMode.CockpitMode: { viewMatrix = Matrix.Invert(playerShip.Position.WorldMatrix); spaceSphereLocation = playerShip.Position.Location; break; } case CameraMode.Fixed: { camera.Point(0, 0, 0, playerShip.Position.XPos, playerShip.Position.YPos, playerShip.Position.ZPos); viewMatrix = camera.ViewMatrix; spaceSphereLocation = new Vector3(0, 0, 0); break; } } device.Transform.View = viewMatrix; spaceSphere.Position.Location = spaceSphereLocation; //rotate space very slowly for that nice twinkly star effect spaceSphere.Position.RotateRel(-.001f * elapsedTime, -0.0001f * elapsedTime, 0); //Play the sounds soundHandler.Play(playerShip.Sounds); playerShip.Sounds = (Sounds)0; }
protected override void FrameMove() { statusMessageTimer += elapsedTime; int fps = (int)framePerSecond; debugText = "FPS: " + fps.ToString() + "\r\n"; ProcessInput(); MouseControlValues v = mouseInput.Values; if (v.FireButtonPushed) { playerShip.Shoot(); } float yawAmount = mouseLoc.X - screenCenter.X; float pitchAmount = mouseLoc.Y - screenCenter.Y; playerShip.YawPitchRoll(yawAmount, pitchAmount, elapsedTime); playerShip.SetThrust(v.ThrustButtonPushed | kbThrust, elapsedTime); playerShip.UpdatePosition(elapsedTime); playerShip.UpdateState(elapsedTime); playerShip.TestShip(opponentShip); //Send our ship update to the remote player SendMyPlayerUpdate(); // If there is no remote player, fly the o ther ship around in a circle for target practice. // Ideally, we would derive an AI controlled ship from the ship class and use it instead. if (!remotePlayerActive) { opponentShip.SetThrust(true, elapsedTime); opponentShip.YawPitchRoll(250, 0, elapsedTime); opponentShip.TestShip(playerShip); } opponentShip.UpdatePosition(elapsedTime); opponentShip.UpdateState(elapsedTime); /*Here we set up the view matrix and space dome location. The space dome moves but not rotates with the player * and is alway drawn first, so it looks like it is infinitely distant. * * In chase mode, the chaseMatrix determines the offset from the ship. If you want to move our viewpoint * back from the ship more, increase the negative z value. * * The fixed mode camera sits at the origin and always tracks the player ship. Very hard to control from * this viewpoint, but cool to watch. */ Vector3 spaceSphereLocation = new Vector3(0, 0, 0); switch (cameraMode) { case CameraMode.ChaseMode: { Matrix chaseMatrix = Matrix.Translation(0, 6, -14); chaseMatrix *= playerShip.Position.WorldMatrix; viewMatrix = Matrix.Invert(chaseMatrix); spaceSphereLocation = playerShip.Position.Location; break; } case CameraMode.CockpitMode: { viewMatrix = Matrix.Invert(playerShip.Position.WorldMatrix); spaceSphereLocation = playerShip.Position.Location; break; } case CameraMode.Fixed: { camera.Point(0, 0, 0, playerShip.Position.XPos, playerShip.Position.YPos, playerShip.Position.ZPos); viewMatrix = camera.ViewMatrix; spaceSphereLocation = new Vector3(0, 0, 0); break; } } device.Transform.View = viewMatrix; spaceSphere.Position.Location = spaceSphereLocation; //rotate space very slowly for that nice twinkly star effect spaceSphere.Position.RotateRel(-.001f * elapsedTime, -0.0001f * elapsedTime, 0); //Calculate range and direction to target range = (int)Vector3.Length( playerShip.Position.Location - opponentShip.Position.Location); bgPointer.Point(playerShip.Position, opponentShip.Position); //Play the sounds soundHandler.Play(opponentShip.Sounds | playerShip.Sounds); opponentShip.Sounds = (Sounds)0; playerShip.Sounds = (Sounds)0; }