示例#1
0
		protected override void LoadContent()
		{
			// Create a new SpriteBatch, which can be used to draw textures.
			spriteBatch = new SpriteBatch(GraphicsDevice);

			// Create and load the level.
			level = new Level(this.Content);

			// Load level.
			level.LoadLevel();
		   
			// Create the Shoes.
			shoes = new Shoes(Content.Load<Texture2D>("Sprites/Shoes32x48"), Character.State.Idle, 0, 32, 48, 0, spriteBatch, graphics.PreferredBackBufferHeight, graphics.PreferredBackBufferWidth, Keys.W, Keys.A, Keys.S, Keys.D, this.Content);

			// Set the initial position of the player.
			shoes.Position = level.getPlayerStartingPosition();

			// Create the Guy.
			guy = new Guy(Content.Load<Texture2D>("Sprites/Guy32x48"), spriteBatch, 0, 0, 32, 48, graphics.PreferredBackBufferHeight, graphics.PreferredBackBufferWidth);

			// Load the debug font. We use this for debugging purposes.
			debugFont = Content.Load<SpriteFont>("debugFont"); 
		}
示例#2
0
		/// <summary>
		/// Update method for the Guy that's called once a frame.
		/// </summary>
		/// <param name="gameTime">Snapshot of the game timing state.</param>
		/// <param name="shoes">A reference to the Shoes.</param>
		/// <param name="level">A reference to the current Level.</param>
		public void Update(GameTime gameTime, ref Shoes shoes, ref Level level)
		{
			currentLevel = level;
			handleAnimation(gameTime);
			handleMovement(gameTime, ref shoes);
		}
示例#3
0
		/// <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)
			{
				shoes.Position = new Vector2(Position.X, Position.Y + 40);
				velocity = new Vector2(0f, 0f);
				delayCollisionWithShoesAndGuy = true;
				isGuyBeingShot = false;
				areGuyAndShoesCurrentlyLinked = true;
				shoes.swapTexture(areGuyAndShoesCurrentlyLinked);
			}
		}
示例#4
0
		/// <summary>
		/// Reset the Guy to the Shoes' position if the player has clicked the right mouse button.
		/// </summary>
		/// <param name="shoes">A reference to the Shoes.</param>
		private void resetGuyToShoesCurrentPositionIfPossible(Shoes shoes)
		{
			if (!(currentMouseState.RightButton == ButtonState.Pressed) && previousMouseState.RightButton == ButtonState.Pressed && !areGuyAndShoesCurrentlyLinked)
			{
				velocity = new Vector2(0f, 0f);
				isGuyBeingShot = false;
				areGuyAndShoesCurrentlyLinked = true;
				shoes.swapTexture(areGuyAndShoesCurrentlyLinked);
				Position = new Vector2(shoes.Position.X, shoes.Position.Y);
				usingLauncher = false;
				delayLaunchAfterLauncherCollisionTimer.stopTimer();
				delayBetweenLaunchesTimer.stopTimer();
			}
		}
示例#5
0
		/// <summary>
		/// Shoot the Guy if the player clicks the left mouse button.
		/// </summary>
		/// <param name="shoes">A reference to the Shoes.</param>
		private void shootGuyIfPossible(Shoes shoes)
		{
			if (currentMouseState.LeftButton == ButtonState.Pressed && !isGuyBeingShot)
			{
				if (!delayCollisionWithGuyAndShoesTimer.TimerStarted)
				{
					delayCollisionWithGuyAndShoesTimer.startTimer();
				}

				isGuyBeingShot = true;
				useGravity = true;
				delayCollisionWithShoesAndGuy = true;
				velocity = Utilities.Vector2FromAngle(MathHelper.ToRadians(angleBetweenGuyAndMouseCursor)) * powerOfLauncherBeingUsed;
				velocity *= -1;
				areGuyAndShoesCurrentlyLinked = false;
				shoes.swapTexture(areGuyAndShoesCurrentlyLinked); // Changes the texture/size of the shoes because the Guy is being shot.
			}
		}
示例#6
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.Position);

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

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

			// Update timers.
			updateTimers(gameTime);
		}
示例#7
0
		/// <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)
			{
				currentLevel.LoadLevel();
				shoes.Position = currentLevel.getPlayerStartingPosition();
			}
		}