public override void update() { ships.ForEach(ship => { if (!ship.isDocked) { ship.move(); } }); if (input.wasKeyPressedAndReleased(Keys.C)) { shipLookingForDestination = null; } if (input.wasLeftButtonClicked()) { //TODO: How do we handle displays for multiple ships? //Additional popup asking them to choose which ship? List <Ship> selectedShips = ships.FindAll(ship => input.rectangle.Intersects(ship.getCollisionRectangle())); selectedShips.ForEach(ship => { ShipInfo info = new ShipInfo(ship, () => { shipLookingForDestination = ship; }, () => { buyFuel(ship); }); ModalUtil.addModal(info); }); //Player clicked the 'Select Destination' button on ShipInfo if (shipLookingForDestination != null) { //Make sure the Player clicked a planet to set the destination Planet selectedPlanet = PlanetUtil.getPlanets().Find(planet => planet.getCollisionRectangle().Intersects(input.rectangle)); if (selectedPlanet != null) { if (PlanetUtil.isPlanetInRange(selectedPlanet, shipLookingForDestination)) { shipLookingForDestination.setNewDestination(selectedPlanet); } else { //TODO: Alert that planet is out of range } } //Cancel looking for a destination whether a planet is clicked or not shipLookingForDestination = null; } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } inputHandler.update(); Globals.camera.update(); //TODO: This stupid thing still isn't working 100% right if (inputHandler.wasKeyPressedAndReleased(Keys.F)) { //isFullScreen = !isFullScreen; graphics.ToggleFullScreen(); if (!graphics.IsFullScreen) { this.graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; this.graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; } else { graphics.PreferredBackBufferWidth = 640; graphics.PreferredBackBufferHeight = 480; } graphics.ApplyChanges(); Globals.screenHeight = GraphicsDevice.Viewport.Height; Globals.screenWidth = GraphicsDevice.Viewport.Width; } //TODO: I guess make some states if (isPaused) { if (inputHandler.wasKeyPressedAndReleased(Keys.Space)) { isPaused = false; } } else { if (inputHandler.wasKeyPressedAndReleased(Keys.Space)) { isPaused = true; } //AI Ship //if (inputHandler.wasLeftButtonClicked()) { // foreach (Planet planet in planets) { // if (planet.rectangle.Intersects(inputHandler.rectangle)) { // Point planetCenter = planet.rectangle.Center; // Ship ship = new Ship("AI " + ai.ships.Count, whiteSquare, planetCenter.X, planetCenter.Y, 3, 5, 2, 1000, Color.White); // //Well this is weird. Have to set init planet as the one we clicked so that our // //new destination isn't set to the same planet. // //TODO: Make this better // ship.dest = planet; // ship.dest = PlanetUtil.getDestination(ship); // ship.updateAngle(); //TODO: I don't like how this is stuck out here instead of being a private method // ai.ships.Add(ship); // } // } //} //Human ship if (inputHandler.wasRightButtonClicked()) { foreach (Planet planet in planets) { if (planet.getCollisionRectangle().Intersects(inputHandler.rectangle)) { Ship ship = new Ship("Human " + human.ships.Count, whiteSquare, planet, 7, 15, 2, 1000, Color.Black); human.ships.Add(ship); } } } if (inputHandler.wasKeyPressedAndReleased(Keys.Down)) { ai.ships.ForEach(ship => ship.speed--); human.ships.ForEach(ship => ship.speed--); } else if (inputHandler.wasKeyPressedAndReleased(Keys.Up)) { ai.ships.ForEach(ship => ship.speed++); human.ships.ForEach(ship => ship.speed++); } ai.update(); human.update(); ModalUtil.updateModals(); } base.Update(gameTime); }