Пример #1
0
        // ******************
        // * START MOVEMENT *
        // ******************

        /// <summary>
        /// Handles all of the movement for the Guy.
        /// </summary>
        /// <param name="gameTime">Snapshot of the game timing state.</param>
        /// <param name="shoes">A reference to the Shoes.</param>
        private void handleMovement(GameTime gameTime, ref Shoes shoes)
        {
            // Updates a variety of variables used for knowing information about the current frame.
            updateCurrentFrameVariables(gameTime, shoes.Position);

            // Handles delaying the collision between the guy and shoes so that they don't link back together too quickly.
            stopDelayingCollisionWithGuyAndShoesIfPossible();

            // Set the position to the player's position so it follows him around.
            setPositionOfGuyToPositionOfShoesIfPossible(shoes);

            // Shoot the Guy if the player clicks the left mouse button.
            shootGuyIfPossible(shoes);

            // Reset the Guy to the Shoes' position if the player clicks the right mouse button.
            // This should be disabled in game.
            //resetGuyToShoesCurrentPositionIfPossible(shoes);

            if (isGuyBeingShot)
            {
                // Takes care of movement for the Guy while he's being shot.
                handleGuyMovementWhenBeingShot();

                // Set the Shoes' position to the Guys' upon collision.
                setShoesPositionToGuyUponCollisionIfPossible(shoes);

                // Checks to see if the Guy is using a Launcher. If so, then launch the Guy if possible.
                checkIfGuyCanLaunch(gameTime);

                // Stops delaying collisions with the Guy and other Launchers once he's been launched.
                stopDelayingCollisionWithGuyAndLaunchersIfPossible();
            }
            else
            {
                // Load the next level if the player has reached the end of the level and the Guy and Shoes are linked.
                loadNextLevelIfPossible(shoes);
            }

            // Change power of shooting the Guy and of Launchers if the player scrolls the mouse wheel.
            changePowerOfShootingAndLaunching();

            // If the interface is not linked, allows the player to modify the value of gravity.
            changeGravity();

            // If the Guy has turned on a particular set of Air Cannons and has now left that switch, turn the corresponding Air Cannons off.
            Air.turnOffAirCannonsIfPossible(CurrentCollidingTile, PreviousCollidingTile, this, null);

            // Reset the Guy and Shoes to the beginning of the level if they fall off.
            resetShoesAndGuyToLevelStartingPositionIfNecessary(ref shoes, false);

            // Updates the variables that are used for storing the previous values of the current values.
            updatePreviousFrameVariables();

            // Update timers.
            updateTimers(gameTime);

            Sprite.Position = Position;
        }
Пример #2
0
 /// <summary>
 /// Turns on all C Cannons.
 /// </summary>
 /// <param name="content">Run-time component which loads managed objects from the binary files produced by the design time content pipeline.</param>
 /// <param name="spriteBatch">Enables a group of sprites to be drawn using the same settings.</param>
 public static void turnOnAllCCannons(ContentManager content, SpriteBatch spriteBatch)
 {
     foreach (Tile cannon in allCCannons)
     {
         cannon.IsAirCannonSwitchOn = true;
         Air newAir = new Air(content.Load <Texture2D>("Sprites/AnimatedAir64x48_2"), 0, 32, 48, 1, spriteBatch, new Vector2(cannon.Position.X + 6, cannon.Position.Y - 2), cannon.Rotation, 'C');
         Air.allAirs.Add(newAir);
     }
 }
Пример #3
0
        /// <summary>
        /// Upon collision with a Tile, perform the appropriate action depending on the State of the Guy and what kind of Tile is being collided with.
        /// </summary>
        /// <remarks>Only if there is an actual collision will any of these statements execute.</remarks>
        /// <param name="currentState">The current State of the Guy.</param>
        /// <param name="y">The Y coordinate of the Tile in the level being collided with.</param>
        /// <param name="x">The X coordinate of the Tile in the level being collided with.</param>
        protected override void specializedCollision(State currentState, int y, int x)
        {
            if (!delayBetweenLaunchesTimer.TimerStarted)                // Ensures the Guy doesn't use another Launcher too quickly.
            {
                if (currentState == State.Running_Right)
                {
                    // Allow the Guy to pass through an Air Switch Cannon.
                    if (!Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        position.X = Level.tiles[y, x].Position.X - spriteWidth;
                    }

                    if (Level.tiles[y, x].TileRepresentation == 'S')
                    {
                        prepareMovementDueToSpringCollision(currentState);
                    }
                    else if (Level.tiles[y, x].IsLauncher)
                    {
                        usingLauncher = true;
                        collY         = y;
                        collX         = x;
                    }
                    else if (Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch);
                    }
                    else
                    {
                        velocity.X = 0f;
                        delayCollisionWithShoesAndGuy = false;
                    }
                }
                else if (currentState == State.Running_Left)
                {
                    if (!Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        position.X = Level.tiles[y, x].Position.X + Level.tiles[y, x].Texture.Width + 1;
                    }

                    if (Level.tiles[y, x].TileRepresentation == 'S')
                    {
                        prepareMovementDueToSpringCollision(currentState);
                    }
                    else if (Level.tiles[y, x].IsLauncher)
                    {
                        usingLauncher = true;
                        collX         = x;
                        collY         = y;
                    }
                    else if (Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch);
                    }
                    else
                    {
                        velocity.X = 0f;
                        delayCollisionWithShoesAndGuy = false;
                    }
                }
                else if (currentState == State.Jumping)
                {
                    if (!Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        position.Y = Level.tiles[y, x].Position.Y + Level.tiles[y, x].Texture.Height + 2;
                    }

                    if (Level.tiles[y, x].TileRepresentation == 'S')
                    {
                        prepareMovementDueToSpringCollision(currentState);
                    }
                    else if (Level.tiles[y, x].IsLauncher)
                    {
                        usingLauncher = true;
                        collX         = x;
                        collY         = y;
                    }
                    else if (Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch);
                    }
                    else
                    {
                        velocity.Y = 0f;
                    }
                }
                else if (currentState == State.Decending)
                {
                    if (!Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        position.Y = Level.tiles[y, x].Position.Y - spriteHeight;
                    }

                    if (Level.tiles[y, x].TileRepresentation == 'S' && velocity.Y > 1f)
                    {
                        prepareMovementDueToSpringCollision(currentState);
                    }
                    else if (Level.tiles[y, x].IsLauncher)
                    {
                        usingLauncher = true;
                        collX         = x;
                        collY         = y;
                    }
                    else if (Level.tiles[y, x].IsAirCannonSwitch)
                    {
                        Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch);
                        position = new Vector2(Level.tiles[y, x].Position.X - 16, Level.tiles[y, x].Position.Y - 32);
                        velocity = new Vector2(0f, 0f);

                        if (!idleAnimationLockIsOn)
                        {
                            changeSpriteOfTheGuy("Idle_WithoutShoes_Right");
                            idleAnimationLockIsOn = true;
                        }
                    }
                    else
                    {
                        velocity   = new Vector2(0f, 0f);                       // So the Guy doesn't fall through.
                        useGravity = false;
                        changeSpriteOfTheGuy("Idle_WithoutShoes_Right");
                        SoundEffectHandler.playGuyLandingSoundEffect();
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Turns off a specific set of Air Cannons, depending on which set is on.
        /// </summary>
        /// <param name="tileCharacterCurrentlyCollidingWith">The tile that the Character is currently colliding with.</param>
        /// <param name="tileCharacterPreviouslyCollidedWith">The tile that the Character previously collided with.</param>
        public static void turnOffAirCannonsIfPossible(Tile tileCharacterCurrentlyCollidingWith, Tile tileCharacterPreviouslyCollidedWith, Guy guy, Shoes shoes)
        {
            if ((tileCharacterCurrentlyCollidingWith != null && tileCharacterPreviouslyCollidedWith != null) && !tileCharacterCurrentlyCollidingWith.IsAirCannonSwitch && tileCharacterPreviouslyCollidedWith.IsAirCannonSwitch)
            {
                if (guy != null && shoes == null)
                {
                    guy.airsGuyHasCollidedWith.Clear();
                }
                else if (shoes != null && guy == null)
                {
                    shoes.airsShoesHasCollidedWith.Clear();
                }

                if (Air.areQCannonsOn)
                {
                    Air.areQCannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('Q');
                }

                if (Air.areWCannonsOn)
                {
                    Air.areWCannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('W');
                }

                if (Air.areECannonsOn)
                {
                    Air.areECannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('E');
                }

                if (Air.areACannonsOn)
                {
                    Air.areACannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('A');
                }

                if (Air.areDCannonsOn)
                {
                    Air.areDCannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('D');
                }

                if (Air.areZCannonsOn)
                {
                    Air.areZCannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('Z');
                }

                if (Air.areXCannonsOn)
                {
                    Air.areXCannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('X');
                }

                if (Air.areCCannonsOn)
                {
                    Air.areCCannonsOn = false;
                    Air.turnOffSpecificSetOfCannons('C');
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Activates all Air Cannons for the Switch that the Shoes collided with.
 /// </summary>
 /// <param name="airCannonSwitch">The Air Cannon Switch that the Shoes has collided with.</param>
 /// <param name="tileCharacterCurrentlyCollidingWith">The tile that the Character is currently colliding with.</param>
 /// <param name="content">Run-time component which loads managed objects from the binary files produced by the design time content pipeline.</param>
 /// <param name="spriteBatch">Enables a group of sprites to be drawn using the same settings.</param>
 public static void activateAirCannons(Tile airCannonSwitch, Tile tileCharacterCurrentlyCollidingWith, ContentManager content, SpriteBatch spriteBatch)
 {
     if (airCannonSwitch.TileRepresentation == 'Q')
     {
         if (!Air.areQCannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areQCannonsOn = true;
             Air.turnOnAllQCannons(content, spriteBatch);
         }
     }
     else if (airCannonSwitch.TileRepresentation == 'W')
     {
         if (!Air.areWCannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areWCannonsOn = true;
             Air.turnOnAllWCannons(content, spriteBatch);
         }
     }
     else if (airCannonSwitch.TileRepresentation == 'E')
     {
         if (!Air.areECannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areECannonsOn = true;
             Air.turnOnAllECannons(content, spriteBatch);
         }
     }
     else if (airCannonSwitch.TileRepresentation == 'A')
     {
         if (!Air.areACannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areACannonsOn = true;
             Air.turnOnAllACannons(content, spriteBatch);
         }
     }
     else if (airCannonSwitch.TileRepresentation == 'D')
     {
         if (!Air.areDCannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areDCannonsOn = true;
             Air.turnOnAllDCannons(content, spriteBatch);
         }
     }
     else if (airCannonSwitch.TileRepresentation == 'Z')
     {
         if (!Air.areZCannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areZCannonsOn = true;
             Air.turnOnAllZCannons(content, spriteBatch);
         }
     }
     else if (airCannonSwitch.TileRepresentation == 'X')
     {
         if (!Air.areXCannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areXCannonsOn = true;
             Air.turnOnAllXCannons(content, spriteBatch);
         }
     }
     else if (airCannonSwitch.TileRepresentation == 'C')
     {
         if (!Air.areCCannonsOn && tileCharacterCurrentlyCollidingWith == airCannonSwitch)
         {
             Air.areCCannonsOn = true;
             Air.turnOnAllCCannons(content, spriteBatch);
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Loads the next Level.
        /// </summary>
        public void LoadLevel()
        {
            impassableTileRecs = new List <Rectangle>();
            impassableTilePos  = new List <Vector2>();
            Air.resetAllAirCannons();

            if ((!Level.bonusLevelsSelected && currentLevel + 1 <= 5) || (Level.bonusLevelsSelected && currentLevel + 1 <= totalLevels))
            {
                previousLevel++;
                currentLevel++;
            }
            else
            {
                if (!Level.bonusLevelsSelected)
                {
                    currentLevel  = 0;
                    previousLevel = -1;
                }
                else if (Level.bonusLevelsSelected)
                {
                    currentLevel  = 6;
                    previousLevel = 5;
                }
            }

            MusicHandler.PlayMusic(currentLevel, ref contentManager);

            // This array will store a level. Each element in the array will be
            //  a line of tiles.
            // 0 - ****
            // 1 - ****
            // 2 - ****
            // ...

            // The problem is lines is only getting 45
            // Only goes to 65
            lines = System.IO.File.ReadAllLines("Content/Levels/" + currentLevel.ToString() + ".txt");

            int length = lines.Length;

            // The outer loop goes through the columns.
            for (int column = 0; column < numberOfTileColumns; column++)
            {
                // The inner loop goes through the rows.
                for (int row = 0; row < numberOfTilesInRow; row++)
                {
                    // The first position of the block is (0, 0), followed by (64, 0), (128, 0), etc.
                    // Going up the y axis works the same way. (0, 0), (0, 64), (0, 128), etc.

                    // Create a new tile in each position of the grid. We give Tile() the character in the string 'lines'.
                    tiles[column, row] = new Tile(lines[column][row], ref contentManager);

                    // Set the position of the tile in the Level array.
                    tiles[column, row].PositionInArray = new Vector2(column, row);

                    // Set the position of a new tile.
                    tiles[column, row].Position = new Vector2((row * 16), (column * 16));

                    // Draw a rectangle around the tile. We need this for collision detection.
                    tiles[column, row].SourceRect = new Rectangle((int)tiles[column, row].Position.X, (int)tiles[column, row].Position.Y, 16, 16);

                    // Set the rotation and center for the tile.
                    if (tiles[column, row].IsLauncher || tiles[column, row].IsAirCannon || tiles[column, row].IsAirCannonSwitch)
                    {
                        tiles[column, row].Center   = new Vector2(16 / 2, 16 / 2);
                        tiles[column, row].Rotation = Tile.getRotationInRadians(tiles[column, row]);
                    }
                    else
                    {
                        tiles[column, row].Center = new Vector2(0, 0);
                    }

                    // We are going to store all the impassable tiles rectangles in a list. We will use this for collision detection.
                    if (tiles[column, row].CollProperties == Tile.CollisionProperty.Impassable)
                    {
                        impassableTileRecs.Add(tiles[column, row].SourceRect);
                        impassableTilePos.Add(tiles[column, row].Position);
                    }

                    if (tiles[column, row].TileRepresentation == 'G' || tiles[column, row].TileRepresentation == 'g')
                    {
                        goalRectangle = tiles[column, row].SourceRect;
                    }
                    if (tiles[column, row].TileRepresentation == 'P')
                    {
                        playerStartingPosition = tiles[column, row].Position;
                    }
                }
            }
        }