/// <summary> /// Set the Shoes's position to the position of the Guy if the collision delay timer is completed and the Guy and Shoes are not currently linked. /// </summary> /// <param name="shoes">A reference to the Shoes.</param> private void setShoesPositionToGuyUponCollisionIfPossible(Shoes shoes) { if (PositionRect.Intersects(shoes.PositionRect) && !delayCollisionWithShoesAndGuy && !areGuyAndShoesCurrentlyLinked) { velocity = new Vector2(0f, 0f); shoes.velocity = new Vector2(0f, 0f); shoes.Position = new Vector2(Position.X, Position.Y + 40); isGuyBeingShot = false; shoes.stopPlayerInput = true; idleAnimationLockIsOn = false; delayCollisionWithShoesAndGuy = true; areGuyAndShoesCurrentlyLinked = true; shoes.swapTexture(areGuyAndShoesCurrentlyLinked); SoundEffectHandler.stopShoesRunningEffect(); if (shoes.directionShoesAreRunning == State.Running_Left || shoes.directionShoesAreRunning == State.Idle_Left) { shoes.changeSpriteOfTheShoes("Idle_Left", true); changeSpriteOfTheGuy("Empty"); } else if (shoes.directionShoesAreRunning == State.Running_Right || shoes.directionShoesAreRunning == State.Idle_Right) { shoes.changeSpriteOfTheShoes("Idle_Right", true); changeSpriteOfTheGuy("Empty"); } } }
/// <summary> /// Load the next level if the player has reached the end of the level and the Guy and Shoes are linked. /// </summary> /// <param name="shoes">A reference to the Shoes.</param> private void loadNextLevelIfPossible(Shoes shoes) { if (PositionRect.Intersects(currentLevel.goalRectangle) && areGuyAndShoesCurrentlyLinked && (currentMouseState.RightButton != ButtonState.Pressed && previousMouseState.RightButton == ButtonState.Released)) { shoes.stopPlayerInputDueToLevelCompletion = true; } // The victory screen will show here. Prompt player to continue to the next level. if (currentKeyboardState.IsKeyUp(Keys.Enter) && previousKeyboardState.IsKeyDown(Keys.Enter) && shoes.stopPlayerInputDueToLevelCompletion && !fadeHandler.FadingOut && !fadeHandler.HoldingWhileFaded && !fadeHandler.FadingIn) { // If the player hasn't completed all of the Main Game levels or the Bonus Levels, keep loading them. Otherwise, exit to main menu. if ((!Level.bonusLevelsSelected && Level.currentLevel + 1 <= 5) || (Level.bonusLevelsSelected && Level.currentLevel + 1 <= 12)) { // Begin fading out the sceen. fadeHandler.fadeToBlack(); } else { // Exit to main menu. Level.exitGame = true; } } // Once the screen is completely faded out, hold the fade for the specified time. if (fadeHandler.fadeToBlackTimer.TimerCompleted) { fadeHandler.holdFadeOut(); } // Once the amount of time to hold the screen has passed, load the next level. if (fadeHandler.holdWhileFadedTimer.TimerCompleted) { fadeHandler.fadeFromBlack(); currentLevel.LoadLevel(); shoes.Position = currentLevel.getPlayerStartingPosition(); shoes.stopPlayerInputDueToLevelCompletion = false; } // Once the screen is done fading in, reset the FadeHandler. if (fadeHandler.fadeFromBlackTimer.TimerCompleted) { fadeHandler.resetFadeHandler(); } }
/// <summary> /// Sets the current and previous Tile that the Character is colliding with. /// </summary> protected void setCurrentAndPreviousCollisionTiles() { PreviousCollidingTile = CurrentCollidingTile; int leftTile = (int)Math.Floor((float)positionRect.Left / Level.impassableTileRecs[0].Width); int rightTile = (int)Math.Ceiling(((float)positionRect.Right / Level.impassableTileRecs[0].Width)) - 1; int topTile = (int)Math.Floor((float)positionRect.Top / Level.impassableTileRecs[0].Height); int bottomTile = (int)Math.Ceiling(((float)positionRect.Bottom / Level.impassableTileRecs[0].Height)) - 1; for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { if ((x > 0 && x < 79 && y > 0 & y < 44) && PositionRect.Intersects(Level.tiles[y, x].SourceRect)) { currentTileCollidingWith = Level.tiles[y, x]; tileCollRect = Level.tiles[y, x].SourceRect; } } } }