コード例 #1
0
        public override void updateScreen(GameTime gameTime)
        {
            //checks to move state
            checkToActivateEndOfLevel(playerOne);

            ///--------------------------------------------------
            /// sets previous state to current, then grabs the now current state
            ///--------------------------------------------------

            if (playerOne.controllerBeingUsed == 0)
            {
                previousKeyboardState = currentKeyboardState;
                currentKeyboardState  = Keyboard.GetState();
                playerOne.checkForPlayerKeyboardInput(previousKeyboardState, currentKeyboardState);
            }

            if (playerOne.controllerBeingUsed == 1)
            {
                playerPreviousGamePadState = playerCurrentGamePadState;
                playerCurrentGamePadState  = GamePad.GetState(PlayerIndex.One);
                playerOne.checkForPlayerGamePadInput(playerPreviousGamePadState, playerCurrentGamePadState);
            }

            ///--------------------------------------------------
            ///update based of key press phase
            ///--------------------------------------------------
            //playerOneCamera.acceptKeyboardInput(previousKeyboardState, currentKeyboardState);
            //playerTwoCamera.acceptKeyboardInput(previousKeyboardState, currentKeyboardState);
            if (playerOne.controllerBeingUsed == 1)
            {
                //System.Diagnostics.Debug.WriteLine("GamePad1 being used");
                //System.Diagnostics.Debug.WriteLine("Gamepad DPad Left Pressed: " + playerCurrentGamePadState.IsButtonDown(Buttons.DPadLeft));
                //System.Diagnostics.Debug.WriteLine("Gamepad DPad Right Pressed: " + playerCurrentGamePadState.IsButtonDown(Buttons.DPadRight));
                //System.Diagnostics.Debug.WriteLine("Player Moving Left: " + playerOne.movingLeft);
                //System.Diagnostics.Debug.WriteLine("Player Moving Right: " + playerOne.movingRight);
            }
            //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 calculateplayerNewPosition 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);
            }

            // Start of rail grinds collision checking
            foreach (GrindRail gr in grindRails)
            {
                if (playerOneCamera.getWorldBoundingBox.Intersects(gr.platformSlope.getBoundingRectangle))
                {
                    gr.update(gameTime);
                    playerOneNewPosition = gr.checkAndFixGrindRailCollision(playerOneNewPosition, playerOne);
                }
            }
            // End of rail grinds collision checking

            //TIGHT ROPE COLLISION
            foreach (TightRope tr in tightRopes)
            {
                tr.update(gameTime);
                playerOneNewPosition = tr.checkAndFixTightRopeCollision(playerOneNewPosition, playerOne);
                //check for collision
            }
            //------------- END TIGHT ROPE COLLISION CHECK ---------------

            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
            ///--------------------------------------------------
            foreach (Spring sp in springs)
            {
                if (playerOneCamera.getWorldBoundingBox.Intersects(sp.getBoundingBox))
                {
                    sp.update(gameTime, playerOneCamera);
                    sp.checkToActivateSpring(playerOne);
                }
            }

            //LADDERS
            foreach (Ladder ld in ladders)
            {
                ld.update(gameTime, playerOneCamera);
                ld.checkToActivateActionState(playerOne);
            }

            //HURDLES
            foreach (Hurdle hl in hurdles)
            {
                if (playerOneCamera.getWorldBoundingBox.Intersects(hl.getBoundingBox))
                {
                    hl.update(gameTime, playerOneCamera);
                    hl.checkForAndTriggerPlayerActionState(playerOne);
                }
            }

            //BEAR TRAPS
            foreach (BearTrap tr in bearTraps)
            {
                if (playerOneCamera.getWorldBoundingBox.Intersects(tr.getBoundingBox))
                {
                    tr.update(gameTime);
                    tr.checkToActivate(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();

            ///--------------------------------------------------
            /// 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);

            //if the player was killed
            if (playerOne.wasKilled)
            {
                //this is where the animation would occur, after the animation and the timer for it finishes the position gets set and the player has their killed status set to false
                if (deathWatchTimer < deathWatchTimerTimerLimit)
                {
                    if (deathWatchTimer == 0)
                    {
                        //handles the players death animation
                        playerOne.playerImageSheet.setFrameConfiguration(75, 74, 77);
                        playerOne.playerImageSheet.isAnimating = false;
                        playerOne.playerImageSheet.animateOnce = true;
                        //System.Diagnostics.Debug.WriteLine("Killed");
                    }
                    //do nothing but increment
                    deathWatchTimer++;
                }
                else
                {
                    //handles the players position reset to the death checkpoint
                    playerOne.currentWorldPosition = new Vector2(0, 640 - playerOne.height);
                    //resets the camera position
                    playerOneCamera.currentWorldPosition = new Vector2(0, 0);
                    //resets the player's state
                    playerOne.playerImageSheet.setFrameConfiguration(0, 0, 4);
                    playerOne.facingLeft                   = false;
                    playerOne.facingRight                  = true;
                    playerOne.movingLeft                   = false;
                    playerOne.movingRight                  = false;
                    playerOne.wasKilled                    = false;
                    playerOne.isJumping                    = false;
                    playerOne.isDashing                    = false;
                    playerOne.exhaustedDash                = false;
                    playerOne.isFalling                    = false;
                    playerOne.isFallingFromGravity         = false;
                    playerOne.actionButtonBeingPressed     = false;
                    playerOne.actionStateIsActive          = false;
                    playerOne.playerImageSheet.isAnimating = true;
                    playerOne.playerImageSheet.animateOnce = false;
                    deathWatchTimer = 0;
                }
            }
        }
コード例 #2
0
        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);
            }

            // Start of rail grinds collision checking
            Rectangle checkRect = new Rectangle((int)playerOneNewPosition.X, (int)playerOneNewPosition.Y, playerOne.width, playerOne.height);

            foreach (GrindRail gr in grindRails)
            {
                if (playerOneCamera.getWorldBoundingBox.Intersects(gr.platformSlope.getBoundingRectangle))
                {
                    playerOneNewPosition = gr.checkAndFixGrindRailCollision(playerOneNewPosition, playerOne);
                    //System.Diagnostics.Debug.WriteLine("Rail Start X: " + gr.platformSlope.getBoundingRectangle.X);
                    //System.Diagnostics.Debug.WriteLine("Rail Start Y: " + gr.platformSlope.getBoundingRectangle.Y);
                    //System.Diagnostics.Debug.WriteLine("Rail Slope: " + gr.platformSlope.getSlope());
                    //System.Diagnostics.Debug.WriteLine("Player Start X: " + playerOne.currentWorldPosition.X);
                    //System.Diagnostics.Debug.WriteLine("Player End X: " + (playerOne.currentWorldPosition.X+playerOne.width));
                    //System.Diagnostics.Debug.WriteLine("Player Start Y: " + playerOne.currentWorldPosition.Y);
                    //System.Diagnostics.Debug.WriteLine("Player End Y: " + (playerOne.currentWorldPosition.Y + playerOne.height));
                    gr.update(gameTime);
                }
            }
            if (playerOneNewPosition.X != checkRect.X ||
                playerOneNewPosition.Y != checkRect.Y)
            {
                // a collision occurred from at least one of the rails
            }
            else
            {
                //a collision for grinding did not occur, reset grind state
                playerOne.grindRailReference = null;
            }
            // End of rail grinds collision checking

            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
            ///--------------------------------------------------
            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();

            ///--------------------------------------------------
            /// 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);
        }