Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        public void UpdateGame()
        {
            #region Step 1a.
            mLargeFlower.Position += InputWrapper.ThumbSticks.Left;
            mSmallTarget.Position += InputWrapper.ThumbSticks.Right;
            #endregion

            #region Step 1b.
            mPrimitiveCollide = mLargeFlower.PrimitivesTouches(mSmallTarget);
            if (mPrimitiveCollide)
            {
                Vector2 p;

                // This is Large image colliding with small image
                // VERY expensive!!
                // mPixelCollide = mLargeFlower.PixelTouches(mSmallTarget, out p);

                // this is small image colliding with large image
                // much more efficient!
                mPixelCollide = mSmallTarget.PixelTouches(mLargeFlower, out p);

                mCollidePosition.Position = p;
            }
            else
            {
                mPixelCollide = false;
            }
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the game state
        /// </summary>
        public void UpdateGame()
        {
            #region Step 4a. Update Rocket control
            mRocket.RotateAngleInRadian +=
                MathHelper.ToRadians(InputWrapper.ThumbSticks.Right.X);
            mRocket.Position += InputWrapper.ThumbSticks.Left;
            #endregion

            #region Step 4b. Update net in flight
            /// Set net to flight
            if (InputWrapper.Buttons.A == ButtonState.Pressed)
            {
                mNetInFlight             = true;
                mNet.RotateAngleInRadian = mRocket.RotateAngleInRadian;
                mNet.Position            = mRocket.Position;
                mNetVelocity             = ShowVector.RotateVectorByAngle(
                    mRocketInitDirection, mNet.RotateAngleInRadian) * mNetSpeed;
            }
            #endregion

            #region Step 4c. Update bee respawn
            if (!mInsectPreset)
            {
                float x = 15f + ((float)Game1.sRan.NextDouble() * 30f);
                float y = 15f + ((float)Game1.sRan.NextDouble() * 30f);
                mInsect.Position = new Vector2(x, y);
                mInsectPreset    = true;
            }
            #endregion

            #region Step 5. Inter-object interaction: Net in flight and collision with insect
            if (mNetInFlight)
            {
                mNet.Position += mNetVelocity;

                if (mNet.PrimitivesTouches(mInsect))
                {
                    mInsectPreset = false;
                    mNetInFlight  = false;
                    mNumInsectShot++;
                }
                if ((Camera.CollidedWithCameraWindow(mNet) !=
                     Camera.CameraWindowCollisionStatus.InsideWindow))
                {
                    mNetInFlight = false;
                    mNumMissed++;
                }
            }
            #endregion
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        public void UpdateGame()
        {
            #region Step 1a.
            mLargeFlower.Position += InputWrapper.ThumbSticks.Left;
            mSmallTarget.Position += InputWrapper.ThumbSticks.Right;

            if (InputWrapper.Buttons.A == ButtonState.Pressed)
            {
                mLargeFlower.RotateAngleInRadian += MathHelper.ToRadians(1f);
            }
            if (InputWrapper.Buttons.B == ButtonState.Pressed)
            {
                mLargeFlower.RotateAngleInRadian -= MathHelper.ToRadians(1f);
            }
            if (InputWrapper.Buttons.X == ButtonState.Pressed)
            {
                mSmallTarget.RotateAngleInRadian += MathHelper.ToRadians(1f);
            }
            if (InputWrapper.Buttons.Y == ButtonState.Pressed)
            {
                mSmallTarget.RotateAngleInRadian -= MathHelper.ToRadians(1f);
            }
            #endregion

            #region Step 1b.
            mPrimitiveCollide = mLargeFlower.PrimitivesTouches(mSmallTarget);
            if (mPrimitiveCollide)
            {
                Vector2 p;

                // This is Large image colliding with small image
                // VERY expensive!!
                // mPixelCollide = mLargeFlower.PixelTouches(mSmallTarget, out p);

                // this is small image colliding with large image
                // much more efficient!
                mPixelCollide = mSmallTarget.PixelTouches(mLargeFlower, out p);

                mCollidePosition.Position = p;
            }
            else
            {
                mPixelCollide = false;
            }
            #endregion
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update game sate:
        ///     1. Tell all Gameobjects to update themselves
        ///     2. Cause (call) all intractable objects to interact
        /// </summary>
        /// <param name="gameTime"></param>
        public void UpdateGame(GameTime gameTime)
        {
            #region Step a.
            if (null != mFinal) // done!!
            {
                return;
            }
            #endregion

            #region Step b. go through all game object and tell each to update themselves
            // hero movement: right thumb stick
            mHero.Update(InputWrapper.ThumbSticks.Right);

            // Basketball ...
            for (int b = mBBallList.Count - 1; b >= 0; b--)
            {
                if (mBBallList[b].UpdateAndExplode())
                {
                    mBBallList.RemoveAt(b);
                    mBBallMissed++;
                    mScore += kBballMissedScore;
                }
            }
            #endregion

            #region Step c. Call GameObject interaction functions to cause interaction between game objects
            /// Notice we could have integrated the following loop into the above for-loop.
            /// In this implementation we separated out the following loop to highlight the
            /// fact that, Hero->Ball interaction is inter-gameObject interaction and
            /// this happened separately from individual updates of game objects.
            for (int b = mBBallList.Count - 1; b >= 0; b--)
            {
                if (mHero.PrimitivesTouches(mBBallList[b]))
                {
                    mBBallList.RemoveAt(b);
                    mBBallHit++;
                    mScore += kBballTouchScore;
                }
            }
            #endregion

            #region Step d. final checking of game winning
            // Check for new basketball condition
            TimeSpan timePassed = gameTime.TotalGameTime;
            timePassed = timePassed.Subtract(mCreationTimeStamp);
            if (timePassed.TotalMilliseconds > kBballMSecInterval)
            {
                mCreationTimeStamp = gameTime.TotalGameTime;
                BasketBall b = new BasketBall();
                mTotalBBallCreated++;
                mBBallList.Add(b);
            }
            #endregion

            #region Step e.
            // Check for winning condition ...
            if (mScore > kWinScore)
            {
                mFinal = new TexturedPrimitive("Winner", new Vector2(75, 50), new Vector2(30, 20));
            }
            else if (mScore < kLossScore)
            {
                mFinal = new TexturedPrimitive("Loser", new Vector2(75, 50), new Vector2(30, 20));
            }
            #endregion
        }