Beispiel #1
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // Update player
            player.Update(gameTime, Game.Window.ClientBounds);

            // Update all sprites
            foreach (Sprite s in spriteList)
            {
                s.Update(gameTime, Game.Window.ClientBounds);

                // Check for collisions and exit game if there is one

                if (s.collisionRect.Intersects(player.collisionRect))
                {
                    Game.Exit();
                }
            }

            base.Update(gameTime);
        }
        protected void UpdateSprites(GameTime gameTime)
        {
            // Update player
            player.Update(gameTime, GraphicsDevice.PresentationParameters.Bounds);

            // Update all non-player sprites
            for (int i = 0; i < spriteList.Count; ++i)
            {
                Sprite s = spriteList[i];

                s.Update(gameTime, GraphicsDevice.PresentationParameters.Bounds);

                // Check for collisions
                if (s.collisionRect.Intersects(player.collisionRect))
                {
                    // Play collision sound
                    //if (s.collisionCueName != null)
                    //    ((Game1)Game).PlayCue(s.collisionCueName);

                    // If collided with AutomatedSprite
                    // remove a life from the player
                    if (s is AutomatedSprite)
                    {
                        // sound2.Play();
                        if (livesList.Count > 0)
                        {
                            livesList.RemoveAt(livesList.Count - 1);
                            --((Game1)Game).NumberLivesRemaining;
                        }
                    }
                    else if (s.collisionCueName == "pluscollision")
                    {
                        // Collided with plus - start plus power-up
                        //sound3.Play();
                        powerUpExpiration = 5000;
                        player.ModifyScale(2);
                    }
                    else if (s.collisionCueName == "skullcollision")
                    {
                        // Collided with skull - start skull power-up
                        //sound4.Play();
                        powerUpExpiration = 5000;
                        player.ModifySpeed(.5f);
                    }
                    else if (s.collisionCueName == "boltcollision")
                    {
                        // Collided with bolt - start bolt power-up
                        // sound1.Play();
                        powerUpExpiration = 5000;
                        player.ModifySpeed(2);
                        ((Game1)Game).AddScore(100);
                    }
                    else if (s.collisionCueName == "boltcollision1")
                    {
                        // Collided with bolt - start bolt power-up
                        // sound5.Play();
                        powerUpExpiration = 8000;
                        player.ModifyScale(0.6f);
                        ((Game1)Game).AddScore(500);
                    }
                    else if (s.collisionCueName == "boltcollision2")
                    {
                        // Collided with bolt - start bolt power-up
                        // sound5.Play();
                        powerUpExpiration = 1000;
                        // player.ModifySpeed(2);
                        if (livesList.Count < 8)
                        {
                            int offset = 10 + ((Game1)Game).NumberLivesRemaining * 40;
                            livesList.Add(new AutomatedSprite(
                                              Game.Content.Load <Texture2D>(@"images\threerings"),
                                              new Vector2(offset, 35), new Point(75, 75), 10,
                                              new Point(0, 0), new Point(6, 8), Vector2.Zero,
                                              null, 0, .5f));
                            ++((Game1)Game).NumberLivesRemaining;
                            ((Game1)Game).AddScore(200);
                        }
                    }

                    // Remove collided sprite from the game
                    spriteList.RemoveAt(i);
                    --i;
                }

                // Remove object if it is out of bounds
                if (s.IsOutOfBounds(GraphicsDevice.PresentationParameters.Bounds))
                {
                    ((Game1)Game).AddScore(spriteList[i].scoreValue);
                    spriteList.RemoveAt(i);
                    --i;
                }
            }

            // Update lives-list sprites
            foreach (Sprite sprite in livesList)
            {
                sprite.Update(gameTime, Game.Window.ClientBounds);
            }
        }