返回首页

我想平方米缩小或长大后,这么多的点击,所以我创建常数变量的最小和最大尺寸和一个布尔值来确定的方是否应该缩小或生长。如果报表最有意义我吧,我想不出更好的方法。请帮帮忙!

protected override void Update(GameTime gameTime)

		{

			// Allows the game to exit

			if (GamePad.GetState(PlanyerIndex.One).Buttons.Back == ButtonState.Pressed)

				this.Exit();

 

			// TODO: Add your update logic here

			if (timeRemaining == 0.0f)

			{

				currentSquare = new Rectangle(

					rand.Next(0, this.Window.ClientBounds.Width - 32),

					rand.Next(0, this.Window.ClientBounds.Height - 32),

					64, 64);  //The size of the square is here



				timeRemaining = TimePerSquare;

			}

 

			MouseState mouse = Mouse.GetState();

 

			if (mouse.LeftButton == ButtonState.Pressed &&

			  (currentSquare.Contains(mouse.X, mouse.Y)))

			{

				//Check to see if square is at its maximum size and set bool to false

				//This will start shrinking the square

				if (currentSquare.Width == MaxWidth && currentSquare.Height == MaxHeight)

				{

					SwitchGrowthDirection = false;

				}

 

				//Check to see if square is at its minimum size and set bool to true

				//This will start growing the square

				if (currentSquare.Width == MinWidth && currentSquare.Height == MinHeight)

				{

					SwitchGrowthDirection = true;

				}

 

				//Grow Square

				if (SwitchGrowthDirection == true)

				{

					currentSquare.Height += 16;

					currentSquare.Width += 16;

				}

 

				//Shrink square

				if (SwitchGrowthDirection == false)

				{

					currentSquare.Height -= 16;

					currentSquare.Width -= 16;

				}

				playerScore++;

				timeRemaining = 0.0f;

			}

			timeRemaining = MathHelper.Max(0, timeRemaining -

				(float)gameTime.ElapsedGameTime.TotalSeconds);

 

			this.Window.Title = "Score : " + playerScore.ToString();

 

			base.Update(gameTime);

		}

回答

评论会员: 时间:2
O