public override void updateScreen(GameTime gameTime) { ///-------------------------------------------------- /// sets previous state to current, then grabs the now current state ///-------------------------------------------------- previousKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); if (playerOne.controllerBeingUsed == 1) { playerOnePreviousGamePadState = GamePad.GetState(PlayerIndex.One); playerOneCurrentGamePadState = GamePad.GetState(PlayerIndex.One); } ///-------------------------------------------------- ///update based of key press phase ///-------------------------------------------------- //playerOneCamera.acceptKeyboardInput(previousKeyboardState, currentKeyboardState); //playerTwoCamera.acceptKeyboardInput(previousKeyboardState, currentKeyboardState); playerOne.checkForPlayerKeyboardInput(previousKeyboardState, currentKeyboardState); //playerTwo.checkForPlayerInput(previousKeyboardState, currentKeyboardState); ///--------------------------------------------------- /// Update playerOne position phase /// - grab the calculatedPosition from the playerOne, this calculates the next position for the playerOne and returns the vector2 /// - take the playerOneNewPosition that you got from calculateplayerOneNewPosition and put it into the collision checking of the objects you're concerned about (map bounding, camera bounding, collisions etc) /// - update the playerOne's currentWorldPosition to the playerOneNewPosition, /// - call the playerOne's update command ///-------------------------------------------------- Vector2 playerOneNewPosition = playerOne.calculateNewPosition(gravity); playerOne.previousWorldPosition = playerOne.currentWorldPosition; //Vector2 playerTwoNewPosition = playerTwo.calculateNewPosition(gravity); foreach (Platform tp in platforms) { if (playerOneCamera.getWorldBoundingBox.Intersects(tp.boundingRectangle)) { if (!playerOne.ladderActionStateActive) { playerOneNewPosition = tp.checkAndFixPlatformCollision(playerOneNewPosition, playerOne); } } if (tp is DisappearingPlatform) { if (tp.platformSize.X == 0) { platformsToRemove.Add(tp); } } tp.Update(gameTime, gravity); } foreach (Platform tp in platformsToRemove) { platforms.Remove(tp); } platformsToRemove.Clear(); //playerTwoNewPosition = platformOne.checkAndFixTiledPlatformCollision(playerTwoNewPosition, playerTwo); playerOneNewPosition = map.fixPlayerCollisionWithMapBoundings(playerOneNewPosition, playerOne); playerOneNewPosition = map.checkForAndFixCollidableTileCollisionWithPlayer(playerOneNewPosition, playerOne, playerOneCamera); //playerTwoNewPosition = map.fixPlayerCollisionWithMapBoundings(playerTwoNewPosition, playerTwo); //playerOneNewPosition = playerOneCamera.fixPlayerCollisionWithCameraBounds(playerOneNewPosition, playerOne); foreach (SlopedPlatform sp in slopedPlatforms) { playerOneNewPosition = sp.checkAndFixPlatformCollision(playerOneNewPosition, playerOne); } playerOne.currentWorldPosition = playerOneNewPosition; //playerTwo.currentWorldPosition = playerTwoNewPosition; //This is only used to contain the playerOne inside the drawing window, not needed if camera bounds and map bounding are handled //playerOne.checkAndFixWindowCollision(); playerOne.Update(gameTime); //playerTwo.Update(gameTime); ///-------------------------------------------------- /// Update world object positions /// This is the area where the world objects will perform their variations of updating, in some cirucmstances that may involve calculating a new position /// In other circumastances it may just involve updating ///-------------------------------------------------- //Hurdle hurdleOne.update(gameTime, playerOneCamera); hurdleOne.checkForAndTriggerPlayerActionState(playerOne); hurdleTwo.update(gameTime, playerOneCamera); hurdleTwo.checkForAndTriggerPlayerActionState(playerOne); foreach (Spring sp in springs) { if (playerOneCamera.getWorldBoundingBox.Intersects(sp.getBoundingBox)) { sp.update(gameTime, playerOneCamera); sp.checkToActivateSpring(playerOne); } } //------------ treasure checks -------------- Treasure tempTreasure = null; foreach (Treasure treasure in worldTreasure) { if (playerOneCamera.getWorldBoundingBox.Intersects(treasure.getBoundingBox)) { treasure.update(gameTime, playerOneCamera); tempTreasure = treasure.checkToActivate(playerOne); if (tempTreasure != null) { worldTreasureToRemove.Add(tempTreasure); } } } foreach (Treasure t in worldTreasureToRemove) { worldTreasure.Remove(t); } worldTreasureToRemove.Clear(); testRope.acceptPlayerInput(playerOne); testRope.updatePlayerPositionWithGrappleCircle(playerOne); testRope.checkForAndTriggerPlayerActionState(playerOne); testLadder.update(gameTime, playerOneCamera); testLadder.checkToActivateActionState(playerOne); ///-------------------------------------------------- /// Update the camera's logic here last /// - updateWorldPositionBasedOnPlayer updates the camera so it orients around the playerOne passed in /// - fixCameraCollisionWithTileMapBounds makes it so that the camera will never draw over the boundaries of the tile map, if it exceeds the dimensions the map is adjusted accordingly ///-------------------------------------------------- playerOneCamera.updateWorldPositionBasedOnPlayer(playerOne); playerOneCamera.fixCameraCollisionWithTileMapBounds(map); foreach (ParallaxBackground pBackground in parallaxBackgrounds) { pBackground.updateBasedOnCamera(playerOneCamera); } //playerTwoCamera.updateWorldPositionBasedOnPlayer(playerTwo); //playerTwoCamera.fixCameraCollisionWithTileMapBounds(map); ///-------------------------------------------------- /// Update the map accordingly ///-------------------------------------------------- //System.Diagnostics.Debug.WriteLine(map.getWorldToScreenCoord(new Vector2(playerOne.currentWorldPosition.X + playerOne.width / 2, playerOne.boundingRectangle.Top), playerOneCamera)); map.update(gameTime, playerOneCamera); //map.update(gameTime, playerTwoCamera); }
public override void updateScreen(GameTime gameTime) { ///-------------------------------------------------- /// sets previous state to current, then grabs the now current state ///-------------------------------------------------- previousKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); ///-------------------------------------------------- ///update based of key press phase ///-------------------------------------------------- //playerOneCamera.acceptKeyboardInput(previousKeyboardState, currentKeyboardState); //playerTwoCamera.acceptKeyboardInput(previousKeyboardState, currentKeyboardState); playerOne.checkForPlayerInput(previousKeyboardState, currentKeyboardState); //playerTwo.checkForPlayerInput(previousKeyboardState, currentKeyboardState); ///--------------------------------------------------- /// Update player position phase /// - grab the calculatedPosition from the player, this calculates the next position for the player and returns the vector2 /// - take the playerOneNewPosition that you got from calculateplayerOneNewPosition and put it into the collision checking of the objects you're concerned about (map bounding, camera bounding, collisions etc) /// - update the player's currentWorldPosition to the playerOneNewPosition, /// - call the player's update command ///-------------------------------------------------- Vector2 playerOneNewPosition = playerOne.calculateNewPosition(gravity); //Vector2 playerTwoNewPosition = playerTwo.calculateNewPosition(gravity); playerOneNewPosition = platformOne.checkAndFixTiledPlatformCollision(playerOneNewPosition, playerOne); //playerTwoNewPosition = platformOne.checkAndFixTiledPlatformCollision(playerTwoNewPosition, playerTwo); playerOneNewPosition = map.fixPlayerCollisionWithMapBoundings(playerOneNewPosition, playerOne); //playerTwoNewPosition = map.fixPlayerCollisionWithMapBoundings(playerTwoNewPosition, playerTwo); //playerOneNewPosition = playerOneCamera.fixPlayerCollisionWithCameraBounds(playerOneNewPosition, playerOne); playerOne.currentWorldPosition = playerOneNewPosition; //playerTwo.currentWorldPosition = playerTwoNewPosition; //This is only used to contain the player inside the drawing window, not needed if camera bounds and map bounding are handled //playerOne.checkAndFixWindowCollision(); playerOne.Update(gameTime); //playerTwo.Update(gameTime); ///-------------------------------------------------- /// Update world object positions /// This is the area where the world objects will perform their variations of updating, in some cirucmstances that may involve calculating a new position /// In other circumastances it may just involve updating ///-------------------------------------------------- platformOne.Update(gameTime, gravity); //Hurdle hurdleOne.update(gameTime, playerOneCamera); hurdleOne.checkForAndTriggerPlayerActionState(playerOne); hurdleTwo.update(gameTime, playerOneCamera); hurdleTwo.checkForAndTriggerPlayerActionState(playerOne); momentumButtonOne.update(gameTime, playerOneCamera); momentumButtonOne.checkForAndTriggerPlayerState(playerOne); ///-------------------------------------------------- /// Update the camera's logic here last /// - updateWorldPositionBasedOnPlayer updates the camera so it orients around the player passed in /// - fixCameraCollisionWithTileMapBounds makes it so that the camera will never draw over the boundaries of the tile map, if it exceeds the dimensions the map is adjusted accordingly ///-------------------------------------------------- playerOneCamera.updateWorldPositionBasedOnPlayer(playerOne); playerOneCamera.fixCameraCollisionWithTileMapBounds(map); //playerTwoCamera.updateWorldPositionBasedOnPlayer(playerTwo); //playerTwoCamera.fixCameraCollisionWithTileMapBounds(map); ///-------------------------------------------------- /// Update the map accordingly ///-------------------------------------------------- map.update(gameTime, playerOneCamera); //map.update(gameTime, playerTwoCamera); }