/// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // STUDENTS: update rocks
            if(rock0 != null)
            {
                rock0.Update(gameTime);
            }
            if (rock1 != null)
            {
                rock1.Update(gameTime);
            }
            if (rock2 != null)
            {
                rock2.Update(gameTime);
            }

            // update timer
            elapsedDelayMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedDelayMilliseconds >= TotalDelayMilliseconds)
            {
                // STUDENTS: timer expired, so spawn new rock if fewer than 3 rocks in window
                // Call the GetRandomRock method to do this
                if (rock0 == null)
                {
                    rock0 = GetRandomRock();
                }
                else if (rock1 == null)
                {
                    rock1 = GetRandomRock();
                }
                else if (rock2 == null)
                {
                    rock2 = GetRandomRock();
                }

                // restart timer
                elapsedDelayMilliseconds = 0;
            }

            // STUDENTS: Check each rock to see if it's outside the window. If so
            // spawn a new random rock for it by calling the GetRandomRock method
            // Caution: Only check the property if the variable isn't null
            if (rock0 != null  && rock0.OutsideWindow)
            {
                rock0 = GetRandomRock();
            }
            if (rock1 != null  && rock1.OutsideWindow)
            {
                rock1 = GetRandomRock();
            }
            if (rock2 != null  && rock2.OutsideWindow)
            {
                rock2 = GetRandomRock();
            }

            base.Update(gameTime);
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // STUDENTS: update rocks
            Rock1.Update(gameTime);
            Rock2.Update(gameTime);
            Rock3.Update(gameTime);

            // update timer
            elapsedDelayMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedDelayMilliseconds >= TOTAL_DELAY_MILLISECONDS)
            {
                // STUDENTS: timer expired, so spawn new rock if fewer than 3 rocks in window
                if(Rock1 == null)
                {
                    Rock1 = GetRandomRock();
                }
                if(Rock2 == null)
                {
                    Rock2 = GetRandomRock();
                }
                if(Rock3 == null)
                {
                    Rock3 = GetRandomRock();
                }
                // restart timer
                elapsedDelayMilliseconds = 0;
            }

            // STUDENTS: Check each rock to see if it's outside the window. If so
            // spawn a new random rock for it by calling the GetRandomRock method
            // Caution: Only check the property if the variable isn't null
            if(Rock1.OutsideWindow)
            {
                Rock1 = GetRandomRock();
            }
            if(Rock2.OutsideWindow)
            {
                Rock2 = GetRandomRock();
            }
            if(Rock3.OutsideWindow)
            {
                Rock3 = GetRandomRock();
            }

            base.Update(gameTime);
        }
        /// <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.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // STUDENTS: Load content for 3 sprites
            rockSprite0 = Content.Load<Texture2D>("greenrock");
            rockSprite1 = Content.Load<Texture2D>("magentarock");
            rockSprite2 = Content.Load<Texture2D>("whiterock");
            //rock0 = new Rock(rockSprite0, centerLocation, GetRandomVelocity, WINDOW_WIDTH, WINDOW_HEIGHT);
            //rock1 = new Rock(rockSprite1, centerLocation, GetRandomVelocity, WINDOW_WIDTH, WINDOW_HEIGHT);
            //rock2 = new Rock(rockSprite2, centerLocation, GetRandomVelocity, WINDOW_WIDTH, WINDOW_HEIGHT);

            // STUDENTS: Create a new random rock by calling the GetRandomRock method
            rock0 = GetRandomRock();

        }
Exemple #4
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.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // STUDENTS: Load content for 3 sprites
            sprite1 = Content.Load<Texture2D>("greenrock");
            sprite2 = Content.Load<Texture2D>("magentarock");
            sprite3 = Content.Load<Texture2D>("whiterock");

            // STUDENTS: Create a new random rock by calling the GetRandomRock method
            Rock1 = GetRandomRock();
            Rock2 = GetRandomRock();
            Rock3 = GetRandomRock();
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // STUDENTS: update rocks

            // update the rocks, if they are not null
            if (rock0 != null)
            {
                rock0.Update(gameTime);
            }
            if (rock1 != null)
            {
                rock1.Update(gameTime);
            }
            if (rock2 != null)
            {
                rock2.Update(gameTime);
            }

            // update timer
            elapsedDelayMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedDelayMilliseconds >= TOTAL_DELAY_MILLISECONDS)
            {
                // STUDENTS: timer expired, so spawn new rock if fewer than 3 rocks in window

                // if a rock doesn't exist anymore, it is null, so we create a new random rock then,
                // to have 3 rocks again
                if (rock0 == null)
                {
                    rock0 = GetRandomRock();
                }
                if (rock1 == null)
                {
                    rock1 = GetRandomRock();
                }
                if (rock2 == null)
                {
                    rock2 = GetRandomRock();
                }

                // restart timer
                elapsedDelayMilliseconds = 0;
            }

            // STUDENTS: Check each rock to see if it's outside the window. If so
            // spawn a new random rock for it by calling the GetRandomRock method
            // Caution: Only check the property if the variable isn't null

            // if a rock is outside the window, a new random rock takes its place
            if(rock0 != null)
            {
                if(rock0.OutsideWindow)
                    rock0 = GetRandomRock();
            }

            if(rock1 != null)
            {
                if (rock1.OutsideWindow)
                    rock1 = GetRandomRock();
            }

            if (rock2 != null)
            {
                if (rock2.OutsideWindow)
                    rock2 = GetRandomRock();
            }

            base.Update(gameTime);
        }
Exemple #6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // STUDENTS: update rocks
            //update each rock if it exists by calling the Update method
            if (rock0 != null)
            {
                rock0.Update(gameTime);
            }
            if (rock1 != null)
            {
                rock1.Update(gameTime);
            }
            if (rock2 != null)
            {
                rock2.Update(gameTime);
            }

            // update timer
            elapsedDelayMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedDelayMilliseconds >= TotalDelayMilliseconds)
            {
                // STUDENTS: timer expired, so spawn new rock if fewer than 3 rocks in window
                // Call the GetRandomRock method to do this
                if (rock0 == null)
                {
                    rock0 = GetRandomRock();
                }
                else if (rock1 == null)
                {
                    rock1 = GetRandomRock();
                }
                else if (rock2 == null)
                {
                    rock2 = GetRandomRock();
                }
                // restart timer
                elapsedDelayMilliseconds = 0;
            }

            // STUDENTS: Check each rock to see if it's outside the window. If so
            // spawn a new random rock for it by calling the GetRandomRock method
            // Caution: Only check the property if the variable isn't null
            if (rock0 != null && rock0.OutsideWindow)
            {
                rock0 = GetRandomRock();
            }
            if (rock1 != null && rock1.OutsideWindow)
            {
                rock1 = GetRandomRock();
            }
            if (rock2 != null && rock2.OutsideWindow)
            {
                rock2 = GetRandomRock();
            }

            base.Update(gameTime);
        }
        /// <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.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // STUDENTS: Load content for 3 sprites
            rockSpriteGreen = this.Content.Load<Texture2D>("greenrock");
            rockSpriteMagenta = this.Content.Load<Texture2D>("magentarock");
            rockSpriteWhite = this.Content.Load<Texture2D>("whiterock");

            // STUDENTS: Create a new random rock by calling the GetRandomRock method
            rock0 = GetRandomRock();
        }
Exemple #8
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // STUDENTS: update rocks
            if (rockOne != null)
            {
                rockOne.Update(gameTime);
            }
            if (rockTwo != null)
            {
                rockTwo.Update(gameTime);
            }
            if (rockThree != null)
            {
                rockThree.Update(gameTime);
            }

            // update timer
            elapsedDelayMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedDelayMilliseconds >= TOTAL_DELAY_MILLISECONDS)
            {
                // STUDENTS: timer expired, so spawn new rock if fewer than 3 rocks in window

                if (rockOne == null)
                {
                    rockOne = GetRandomRock();
                }
                else if (rockTwo == null)
                {
                    rockTwo = GetRandomRock();
                }
                else if (rockThree == null)
                {
                    rockThree = GetRandomRock();
                }

                // restart timer
                elapsedDelayMilliseconds = 0;
            }

            // STUDENTS: Check each rock to see if it's outside the window. If so
            // spawn a new random rock for it by calling the GetRandomRock method
            // Caution: Only check the property if the variable isn't null
            if (rockOne != null && rockOne.OutsideWindow)
            {
                rockOne = GetRandomRock();
            }
            if (rockTwo != null && rockTwo.OutsideWindow)
            {
                rockTwo = GetRandomRock();
            }
            if (rockThree != null && rockThree.OutsideWindow)
            {
                rockThree = GetRandomRock();
            }


            base.Update(gameTime);
        }