/// <summary> /// The Update game loop. It is essentially just an Update(gameTime) call that's inside of a while(true) loop. This is where the game physics and non-rendering things that happen over time should be. /// </summary> /// <param name="gameTime"></param> protected override void Update(GameTime gameTime) { //this came premade in the project, but it works, though I hardly ever use it. if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } //I don't really like the XNA GameTime stuff so instead I made a Time class that functions similarly to the Time class in Unity. //This just adds the time since the last update in milliseconds to the Time.gameTime clock. Time.gameTime += gameTime.ElapsedGameTime.Milliseconds; //Call the worlds update method with the camera reference and the gametime parameters. The reference for the cam is necessary because //I don't want to make the camera a publicly available thing, but do want to control it inside of the update loops. world.Update(gameTime); base.Update(gameTime); }
/// <summary> /// Go through all the ships and let them update. /// </summary> public void Update(GameTime gameTime) { Mouse.GetState(); //Keyboard.GetState(); //Zoom logic if (Keyboard.WasKeyTyped(Keys.Z)) { if (Keyboard.IsKeyPressed(Keys.LeftShift)) { Vector2 oldSize = GameCamera.GetCameraBounds() - GameCamera.Position; GameCamera.Zoom *= 1.5f; Vector2 newSize = GameCamera.GetCameraBounds() - GameCamera.Position; GameCamera.Position += (oldSize - newSize) / 2; } else { if (GameCamera.Zoom > GameCamera.MaxZoom) { Vector2 oldSize = GameCamera.GetCameraBounds() - GameCamera.Position; GameCamera.Zoom /= 1.5f; Vector2 newSize = GameCamera.GetCameraBounds() - GameCamera.Position; //Debug.Log(oldSize - newSize); GameCamera.Position += (oldSize - newSize) / 2; } } Debug.Log("Camera zoom: " + GameCamera.Zoom); } //Camera drag movement. if (Mouse.MouseButtonDown(Mouse.MouseButton.Left)) { mouseRightFlag = true; mouseRightClickedPosition = GameCamera.Position + Mouse.GetState().Position.ToVector2() / GameCamera.Zoom; Debug.Log("Mouse Clicked Position: " + mouseRightClickedPosition); } if (Mouse.IsButtonPressed(Mouse.MouseButton.Left)) { if (mouseRightFlag) { GameCamera.Position = (mouseRightClickedPosition - Mouse.GetState().Position.ToVector2() / GameCamera.Zoom); } } if (Mouse.MouseButtonUp(Mouse.MouseButton.Left)) { //Debug.Log("Mouse Released Position: " + Mouse.GetState().Position.ToVector2()); mouseRightFlag = false; GameCamera.Position = (mouseRightClickedPosition - Mouse.GetState().Position.ToVector2() / GameCamera.Zoom); } foreach (Ship ship in ships) { ship.Update(gameTime); } //Debug.Log(cam.Position); }