/// <summary>
 /// Go through the list to update each arrow
 /// </summary>
 /// <param name="hero"></param>
 public void UpdateSpinningSet(TexturedPrimitive hero)
 {
     foreach (var arrow in mTheSet)
     {
         arrow.UpdateSpinningArrow(hero);
     }
 }
示例#2
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 select which primitive to work on
            if (InputWrapper.Buttons.A == ButtonState.Pressed)
            {
                mWorkPrim = mBall;
            }
            else if (InputWrapper.Buttons.B == ButtonState.Pressed)
            {
                mWorkPrim = mUWBLogo;
            }
            #endregion select which primitive to work on

            #region update the work primitive
            float rotation = 0;
            if (InputWrapper.Buttons.X == ButtonState.Pressed)
            {
                rotation = MathHelper.ToRadians(1f);            //1 degree pre-press
            }
            if (InputWrapper.Buttons.Y == ButtonState.Pressed)
            {
                rotation = MathHelper.ToRadians(-1f);           //1 degree pre-press
            }
            mWorkPrim.Update(InputWrapper.ThumbSticks.Left, InputWrapper.ThumbSticks.Right, rotation);
            #endregion
        }
        bool mHeroBoundCollision; // If there is a image bound collision for the

        public GameState()
        {
            // Set up the flower ...
            mFlower = new TexturedPrimitive("Flower", new Vector2(50, 35), new Vector2(350, 350));

            // Planes
            mPlane    = new TexturedPrimitive[kNumPlanes];
            mPlane[0] = new TexturedPrimitive("PatrolEnemy", new Vector2(20, -80), new Vector2(10, 20));
            mPlane[1] = new TexturedPrimitive("PatrolEnemy", new Vector2(150, -100), new Vector2(10, 20));
            mPlane[2] = new TexturedPrimitive("PatrolEnemy", new Vector2(150, 120), new Vector2(10, 20));
            mPlane[3] = new TexturedPrimitive("PatrolEnemy", new Vector2(20, 170), new Vector2(10, 20));

            mHeroBoundCollision = false;
            mHeroPixelCollision = false;

            mHero = new SpritePrimitive("SimpleSpriteSheet", new Vector2(10, 0), new Vector2(10, 10),
                                        4,  // Number of rows
                                        2,  // Number of columns
                                        0); // Padding between images


            // Start Hero by walking left and AnotherHero by walking towards right
            mHero.SetSpriteAnimation(0, 0, 0, 3, 10); // Slowly

            // Begin background audio
            AudioSupport.PlayBackgroundAudio("Mind_Meld", 0.4f);
        }
        public bool PrimitivesTouches(TexturedPrimitive otherPrim)
        {
            Vector2 v    = mPosition - otherPrim.Position;
            float   dist = v.Length();

            return(dist < ((mSize.X / 2f) + (otherPrim.mSize.X / 2f)));
        }
示例#5
0
        public GameState()
        {
            // Set up the flower ...
            mFlower = new TexturedPrimitive("Flower", new Vector2(50, 35), new Vector2(350, 350));

            // planes
            mPlane    = new TexturedPrimitive[kNumPlanes];
            mPlane[0] = new TexturedPrimitive("PatrolEnemy", new Vector2(20, -80), new Vector2(20, 40));
            mPlane[1] = new TexturedPrimitive("PatrolEnemy", new Vector2(150, -100), new Vector2(20, 40));
            mPlane[2] = new TexturedPrimitive("PatrolEnemy", new Vector2(150, 120), new Vector2(20, 40));
            mPlane[3] = new TexturedPrimitive("PatrolEnemy", new Vector2(20, 170), new Vector2(20, 40));

            mHeroBoundCollision = false;
            mHeroPixelCollision = false;

            mHero = new SpritePrimitive("SimpleSpriteSheet", new Vector2(10, 0), new Vector2(10, 10),
                                        4,  // number of rows
                                        2,  // number of columns
                                        0); // padding between images


            // Start Hero by walking left and AnotherHero by walking towards right
            mHero.SetSpriteAnimation(0, 0, 0, 3, 10); // slowly

            mParticleSystem = new ParticleSystem();
        }
示例#6
0
        /// <summary>
        /// Check for bound overlaps
        /// </summary>
        /// <param name="otherPrim">Primitive testing for collision</param>
        /// <returns>True: collides</returns>
        public bool PrimitivesTouches(TexturedPrimitive otherPrim)
        {
            if ((Math.Abs(RotateAngleInRadian) < float.Epsilon) &&
                (Math.Abs(otherPrim.RotateAngleInRadian) < float.Epsilon))
            {
                // No rotations involved ...: check for bound overlaps
                Vector2 myMin    = MinBound;
                Vector2 otherMin = otherPrim.MinBound;

                Vector2 myMax    = MaxBound;
                Vector2 otherMax = otherPrim.MaxBound;

                return
                    ((myMin.X < otherMax.X) && (myMax.X > otherMin.X) &&
                     (myMin.Y < otherMax.Y) && (myMax.Y > otherMin.Y));
            }
            else
            {
                // One of both are rotated ... use radius ... be conservative
                // Use the larger of the Width/Height and approx radius
                // Sqrt(1/2)*x Approx = 0.71f * x;
                float r1 = 0.71f * MathHelper.Max(Size.X, Size.Y);
                float r2 = 0.71f * MathHelper.Max(otherPrim.Size.X, otherPrim.Size.Y);
                return((otherPrim.Position - Position).Length() < (r1 + r2));
            }
        }
示例#7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public GameState()
 {
     // Create the primitives
     mLargeFlower     = new TexturedPrimitive("Flower", new Vector2(40, 30), new Vector2(60, 50));
     mSmallTarget     = new TexturedPrimitive("Target", new Vector2(60, 50), new Vector2(3, 7));
     mCollidePosition = new TexturedPrimitive("Soccer", Vector2.Zero, new Vector2(3, 3));
 }
示例#8
0
        bool mHeroBoundCollision;      // If there is a image bound collision for the hero

        public GameState()
        {
            // Set up the flower ...
            mFlower = new TexturedPrimitive("Flower", new Vector2(50, 35), new Vector2(60, 60));

            // Planes
            mPlane    = new TexturedPrimitive[kNumPlanes];
            mPlane[0] = new TexturedPrimitive("PatrolEnemy", new Vector2(10, 15), new Vector2(5, 10));
            mPlane[1] = new TexturedPrimitive("PatrolEnemy", new Vector2(90, 15), new Vector2(5, 10));
            mPlane[2] = new TexturedPrimitive("PatrolEnemy", new Vector2(90, 55), new Vector2(5, 10));
            mPlane[3] = new TexturedPrimitive("PatrolEnemy", new Vector2(10, 55), new Vector2(5, 10));

            mHeroTarget         = new TexturedPrimitive("Target", new Vector2(0, 0), new Vector2(3, 3));
            mCurrentPrim        = mPlane[0];
            mHeroBoundCollision = false;
            mHeroPixelCollision = false;

            mHero = new SpritePrimitive("SimpleSpriteSheet", new Vector2(20, 30), new Vector2(10, 10),
                                        4,  // Number of rows
                                        2,  // Number of columns
                                        0); // Padding between images


            // Start Hero by walking left and AnotherHero by walking towards right
            mHero.SetSpriteAnimation(0, 0, 0, 3, 10); // Slowly
        }
示例#9
0
        public GameState()
        {
            // Set up the flower ...
            mFlower         = new TexturedPrimitive("ColisoesT", new Vector2(50, 35), new Vector2(450, 450));
            chao            = new TexturedPrimitive("ChaoT", new Vector2(50, 35), new Vector2(450, 450));
            Redes           = new TexturedPrimitive("RedesT", new Vector2(50, 35), new Vector2(450, 450));
            EntradaEdificio = new TexturedPrimitive("Saidadefora", new Vector2(50, 35), new Vector2(450, 450));

            mBullet = new TexturedPrimitive("Bullet", new Vector2(50, 35), new Vector2(3, 3));

            // Planes
            mPlane    = new TexturedPrimitive[kNumPlanes];
            mPlane[0] = new TexturedPrimitive("PatrolEnemy", new Vector2(100, -80), new Vector2(20, 40));
            mPlane[1] = new TexturedPrimitive("PatrolEnemy", new Vector2(150, -100), new Vector2(20, 40));
            mPlane[2] = new TexturedPrimitive("PatrolEnemy", new Vector2(150, 120), new Vector2(20, 40));
            mPlane[3] = new TexturedPrimitive("PatrolEnemy", new Vector2(20, 170), new Vector2(20, 40));

            mHeroTarget         = new TexturedPrimitive("Target", new Vector2(0, 0), new Vector2(3, 3));
            mHeroBoundCollision = false;
            mHeroPixelCollision = false;


            mBulletCollision = false;

            mHero = new SpritePrimitive("SimpleSpriteSheet", new Vector2(10, 0), new Vector2(5, 5),
                                        4,  // Number of rows
                                        2,  // Number of columns
                                        0); // Padding between images


            // Start Hero by walking left and AnotherHero by walking towards right
            mHero.SetSpriteAnimation(0, 0, 0, 3, 10); // Slowly
        }
示例#10
0
 /// <summary>
 /// Constructor
 /// </summary>
 public GameState()
 {
     //create the primitives
     mBall     = new TexturedPrimitive("Soccer", new Vector2(30, 30), new Vector2(10, 15));
     mUWBLogo  = new TexturedPrimitive("UWB-JPG", new Vector2(60, 30), new Vector2(20, 20));
     mWorkPrim = mBall;
 }
示例#11
0
 public ChaserGameObject(String imageName, Vector2 position, Vector2 size, TexturedPrimitive target)
     : base(imageName, position, size, null)
 {
     Target      = target;
     mHomeInRate = 0.05f;
     mHitTarget  = false;
     mSpeed      = 0.1f;
 }
 public void UpdateGameOverScreen()
 {
     if (InputWrapper.Buttons.A == ButtonState.Pressed)
     {
         mGameOverScreen   = null;
         mCurrentGameState = GameStates.Playing;
         InitializeGamePlay();
     }
 }
示例#13
0
        /// <summary>
        /// Constructor of game state, allocate memory and initialize
        /// </summary>
        public MyGame()
        {
            // hero ...
            mHero = new TexturedPrimitive("Me", kHeroPosition, kHeroSize);

            // Basketballs
            mCreationTimeStamp = new TimeSpan(0);
            mBBallList         = new List <BasketBall>();
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public GameState()
 {
     // Create the primitives
     mPa             = new TexturedPrimitive("Position", new Vector2(30, 30), kPointSize, "Pa");
     mPb             = new TexturedPrimitive("Position", new Vector2(60, 30), kPointSize, "Pb");
     mPx             = new TexturedPrimitive("Position", new Vector2(20, 10), kPointSize, "Px");
     mPy             = new TexturedPrimitive("Position", new Vector2(20, 50), kPointSize, "Py");
     mCurrentLocator = mPa;
 }
示例#15
0
        private void UserControlUpdate()
        {
            #region Selecting Hero
            if (InputWrapper.Buttons.A == ButtonState.Pressed)
            {
                mCurrentPrim = mFlower;
            }
            if (InputWrapper.Buttons.B == ButtonState.Pressed)
            {
                mCurrentPrim = mPlane[0];
            }
            mCurrentPrim.Position += InputWrapper.ThumbSticks.Right;
            #endregion

            #region Specifying hero rotation
            if (InputWrapper.Buttons.X == ButtonState.Pressed)
            {
                mHero.RotateAngleInRadian += MathHelper.ToRadians(1);
            }
            if (InputWrapper.Buttons.Y == ButtonState.Pressed)
            {
                mHero.RotateAngleInRadian += MathHelper.ToRadians(-1);
            }
            #endregion

            #region Specifying flower rotation
            mCurrentPrim.RotateAngleInRadian += MathHelper.ToRadians(
                InputWrapper.Triggers.Left);
            mCurrentPrim.RotateAngleInRadian -= MathHelper.ToRadians(
                InputWrapper.Triggers.Right);
            #endregion

            #region Sprite Sheet Update
            if (InputWrapper.ThumbSticks.Left.X == 0)
            {
                mHero.SpriteEndColumn = 0;  // stops the animation
            }
            else
            {
                float useX = InputWrapper.ThumbSticks.Left.X;
                mHero.SpriteEndColumn = 3;
                if (useX < 0)
                {
                    mHero.SpriteBeginRow = 1;
                    mHero.SpriteEndRow   = 1;
                    useX *= -1f;
                }
                else
                {
                    mHero.SpriteBeginRow = 0;
                    mHero.SpriteEndRow   = 0;
                }
                mHero.SpriteAnimationTicks = (int)((1f - useX) * kSpriteSpeedFactor);
            }
            #endregion
        }
示例#16
0
        /// <summary>
        /// Check for bound overlaps
        /// </summary>
        /// <param name="otherPrim">Primitive testing for collision</param>
        /// <returns>True: collides</returns>
        public bool PrimitivesTouches(TexturedPrimitive otherPrim)
        {
            Vector2 myMin    = MinBound;
            Vector2 myMax    = MaxBound;
            Vector2 otherMin = otherPrim.MinBound;
            Vector2 otherMax = otherPrim.MaxBound;

            return
                ((myMin.X < otherMax.X) && (myMax.X > otherMin.X) &&
                 (myMin.Y < otherMax.Y) && (myMax.Y > otherMin.Y));
        }
        public void InitializeGameOverScreen()
        {
            float centerX = Camera.CameraWindowUpperRightPosition.X - Camera.Width / 2;
            float centerY = Camera.CameraWindowUpperRightPosition.Y - Camera.Height / 2;

            mGameOverScreen = new TexturedPrimitive("GAMEOVERSCREEN_1", new Vector2(centerX, centerY), new Vector2(Camera.Width, Camera.Height));
            String msg = mDistantTraveled + "m traveled. Press the 'K' key to try agian.";

            mGameOverScreen.Label      = msg;
            mGameOverScreen.LabelColor = Color.Black;
        }
        public void InitializeStartMenu()
        {
            float centerX = Camera.CameraWindowUpperRightPosition.X - Camera.Width / 2;
            float centerY = Camera.CameraWindowUpperRightPosition.Y - Camera.Height / 2;

            mSplashScreen = new TexturedPrimitive("SPLASHSCREEN_1", new Vector2(centerX, centerY), new Vector2(Camera.Width, Camera.Height));
            String msg = "Press the 'K' key to start.";

            mSplashScreen.Label      = msg;
            mSplashScreen.LabelColor = Color.Black;
        }
示例#19
0
文件: Game1.cs 项目: Metlina/dev
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Game1.sSpriteBatch = new SpriteBatch(GraphicsDevice);

            // Define Camera Window Bounds
            Camera.SetCameraWindow(new Vector2(10f, 20f), 100f);

            // Create the primitives
            mUWBLogo = new TexturedPrimitive("UWB-PNG", new Vector2(30, 30), new Vector2(20, 20));
            mBall    = new SoccerBall(mSoccerPosition, mSoccerBallRadius * 2f);
        }
        /// <summary>
        /// Update function for steady state spinning, capable of detecting the hero
        /// </summary>
        /// <param name="hero">if hero gets too close, hero will be tracked</param>
        private void UpdateSpinningState(TexturedPrimitive hero)
        {
            SpinTheArrow();

            // Check for hero ...
            Vector2 toHero = hero.Position - Position;

            if (toHero.Length() < kHeroTriggerDistance)
            {
                // Transition to PointsToHeroState
                mSpinRate   = 0f;
                mArrowState = SpinningArrowState.ArrowPointsToHero;
            }
        }
示例#21
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Game1.sSpriteBatch = new SpriteBatch(GraphicsDevice);

            // Create the primitives
            mGraphicsObjects    = new TexturedPrimitive[kNumObjects];
            mGraphicsObjects[0] = new TexturedPrimitive("UWB-JPG", new Vector2(10, 10), new Vector2(30, 30));
            mGraphicsObjects[1] = new TexturedPrimitive("UWB-JPG", new Vector2(200, 200), new Vector2(100, 100));
            mGraphicsObjects[2] = new TexturedPrimitive("UWB-PNG", new Vector2(50, 10), new Vector2(30, 30));
            mGraphicsObjects[3] = new TexturedPrimitive("UWB-PNG", new Vector2(50, 200), new Vector2(100, 100));

            // NOTE: Since the creation of TextruedPrimitive involves loading of textures
            // The creation should occure in or after LoadContent()
        }
示例#22
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Game1.sSpriteBatch = new SpriteBatch(GraphicsDevice);

            // Define Camera Window Bounds
            Camera.SetCameraWindow(new Vector2(10f, 20f), 100f);

            // Create the primitives
            mGraphicsObjects    = new TexturedPrimitive[kNumObjects];
            mGraphicsObjects[0] = new TexturedPrimitive("UWB-JPG", new Vector2(15f, 25f), new Vector2(10f, 10f));
            mGraphicsObjects[1] = new TexturedPrimitive("UWB-JPG", new Vector2(35f, 60f), new Vector2(50f, 50f));
            mGraphicsObjects[2] = new TexturedPrimitive("UWB-PNG", new Vector2(105f, 25f), new Vector2(10f, 10f));
            mGraphicsObjects[3] = new TexturedPrimitive("UWB-PNG", new Vector2(90f, 60f), new Vector2(35f, 35f));
            // NOTE: Since the creation of TextruedPrimitive involves loading of textures
            // The creation should occure in or after LoadContent()
        }
示例#23
0
        public bool PixelTouches(TexturedPrimitive otherPrim, out Vector2 collidePoint)
        {
            bool touches = PrimitivesTouches(otherPrim);

            collidePoint = Position;

            if (touches)
            {
                bool pixelTouch = false;

                #region Step 3a.
                Vector2 myXDir    = ShowVector.RotateVectorByAngle(Vector2.UnitX, RotateAngleInRadian);
                Vector2 myYDir    = ShowVector.RotateVectorByAngle(Vector2.UnitY, RotateAngleInRadian);
                Vector2 otherXDir = ShowVector.RotateVectorByAngle(Vector2.UnitX, otherPrim.RotateAngleInRadian);
                Vector2 otherYDir = ShowVector.RotateVectorByAngle(Vector2.UnitY, otherPrim.RotateAngleInRadian);
                #endregion

                #region Step 3b.
                int i = 0;
                while ((!pixelTouch) && (i < mImage.Width))
                {
                    int j = 0;
                    while ((!pixelTouch) && (j < mImage.Height))
                    {
                        collidePoint = IndexToCameraPosition(i, j, myXDir, myYDir);
                        Color myColor = GetColor(i, j);
                        if (myColor.A > 0)
                        {
                            Vector2 otherIndex = otherPrim.CameraPositionToIndex(collidePoint, otherXDir, otherYDir);
                            int     xMin       = (int)otherIndex.X;
                            int     yMin       = (int)otherIndex.Y;
                            if ((xMin >= 0) && (xMin < otherPrim.mImage.Width) &&
                                (yMin >= 0) && (yMin < otherPrim.mImage.Height))
                            {
                                pixelTouch = (otherPrim.GetColor(xMin, yMin).A > 0);
                            }
                        }
                        j++;
                    }
                    i++;
                }
                #endregion
                touches = pixelTouch;
            }
            return(touches);
        }
        /// <summary>
        /// Updates the FSM of the spinning arrow
        /// </summary>
        /// <param name="hero">If in proper state, the arrow will track the hero</param>
        public void UpdateSpinningArrow(TexturedPrimitive hero)
        {
            switch (mArrowState)
            {
            case SpinningArrowState.ArrowTransition:
                UpdateTransitionState();
                break;

            case SpinningArrowState.ArrowSpinning:
                UpdateSpinningState(hero);
                break;

            case SpinningArrowState.ArrowPointsToHero:
                UpdatePointToHero(hero.Position - Position);
                break;
            }
        }
        /// <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 3a. Change current selected vector
            if (InputWrapper.Buttons.A == ButtonState.Pressed)
            {
                mCurrentLocator = mPa;
            }
            else if (InputWrapper.Buttons.B == ButtonState.Pressed)
            {
                mCurrentLocator = mPb;
            }
            else if (InputWrapper.Buttons.X == ButtonState.Pressed)
            {
                mCurrentLocator = mPx;
            }
            else if (InputWrapper.Buttons.Y == ButtonState.Pressed)
            {
                mCurrentLocator = mPy;
            }
            #endregion

            #region Step 3b. Move Vector
            // Change the current locator position
            mCurrentLocator.Position += InputWrapper.ThumbSticks.Right;
            #endregion

            #region Step 3c. Rotate Vector
            // Left thumbstick-X rotates the vector at Py
            float rotateYByRadian = MathHelper.ToRadians(
                InputWrapper.ThumbSticks.Left.X);
            #endregion

            #region Step 3d. Increase/Decrease the length of vector
            // Left thumbstick-Y increase/decrease the length of vector at Py
            float vecYLen = mVectorAtPy.Length();
            vecYLen += InputWrapper.ThumbSticks.Left.Y;
            #endregion

            #region Step 3e. Compute vector changes
            // Compute the rotated direction of vector at Py
            mVectorAtPy = ShowVector.RotateVectorByAngle(mVectorAtPy, rotateYByRadian);
            mVectorAtPy.Normalize(); // Normalize vectorATY to size of 1f
            mVectorAtPy *= vecYLen;  // Scale the vector to the new size
            #endregion
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public GameState()
        {
            // Create and set up the primitives
            mRocket = new TexturedPrimitive("Rocket", new Vector2(5, 5), new Vector2(3, 10));
            mRocketInitDirection = Vector2.UnitY; // initially umbrella is pointing in the positive y-direction

            mNet         = new TexturedPrimitive("Net", new Vector2(0, 0), new Vector2(2, 5));
            mNetInFlight = false; // until user press "A", rocket is not in flight
            mNetVelocity = Vector2.Zero;
            mNetSpeed    = 0.5f;

            // initialize a new insect
            mInsect       = new TexturedPrimitive("Insect", Vector2.Zero, new Vector2(5, 5));
            mInsectPreset = false;

            // initialize game status
            mNumInsectShot = 0;
            mNumMissed     = 0;
        }
示例#27
0
        public bool PixelTouches(TexturedPrimitive otherPrim, out Vector2 collidePoint)
        {
            bool touches = PrimitivesTouches(otherPrim);

            collidePoint = Position;

            if (touches)
            {
                bool pixelTouch = false;

                int i = 0;
                while ((!pixelTouch) && (i < mImage.Width))
                {
                    int j = 0;
                    while ((!pixelTouch) && (j < mImage.Height))
                    {
                        collidePoint = IndexToCameraPosition(i, j);
                        Color myColor = GetColor(i, j);
                        if (myColor.A > 0)
                        {
                            Vector2 otherIndex = otherPrim.CameraPositionToIndex(collidePoint);
                            int     xMin       = (int)otherIndex.X;
                            int     yMin       = (int)otherIndex.Y;

                            if ((xMin >= 0) && (xMin < otherPrim.mImage.Width) &&
                                (yMin >= 0) && (yMin < otherPrim.mImage.Height))
                            {
                                pixelTouch = (otherPrim.GetColor(xMin, yMin).A > 0);
                            }
                        }
                        j++;
                    }
                    i++;
                }

                touches = pixelTouch;
            }
            return(touches);
        }
示例#28
0
        /// <summary>
        /// Test and return the status of colliding input primitive with the bounds of the camera window
        /// </summary>
        /// <param name="prim">Primitive to be tested</param>
        /// <returns>Camera Window Collusion Stats: inside or collided with one of the bounds</returns>
        static public CameraWindowCollisionStatus CollidedWithCameraWindow(TexturedPrimitive prim)
        {
            Vector2 min = CameraWindowLowerLeftPosition;
            Vector2 max = CameraWindowUpperRightPosition;

            if (prim.MaxBound.Y > max.Y)
            {
                return(CameraWindowCollisionStatus.CollideTop);
            }
            if (prim.MinBound.X < min.X)
            {
                return(CameraWindowCollisionStatus.CollideLeft);
            }
            if (prim.MaxBound.X > max.X)
            {
                return(CameraWindowCollisionStatus.CollideRight);
            }
            if (prim.MinBound.Y < min.Y)
            {
                return(CameraWindowCollisionStatus.CollideBottom);
            }

            return(CameraWindowCollisionStatus.InsideWindow);
        }
示例#29
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
        }