コード例 #1
0
        public override void Update(GameTime gameTime, Rectangle viewportRect)
        {
            base.Update(gameTime, viewportRect);

            /* Get the current score */
            localScore = levelScore.getScore();

            /* Check when the last Pellet dropped */
            lastPellet += (float)gameTime.ElapsedGameTime.TotalSeconds;

            /* Get the time that has passed, minus it from the counter then reset the timer
             * so it count individual seconds */
            timer       += (float)gameTime.ElapsedGameTime.TotalSeconds;
            timeCounter -= (int)timer;

            if (timer >= 1.0f)
            {
                timer = 0f;
            }

            if (lastPellet >= 3.0f)
            {
                // Spawn new pellet
                levelObjects.Add(CreatePellet());
                lastPellet = 0.0f;
            }

            // Iterate through all object in levelObjects
            foreach (gameObject gO in levelObjects)
            {
                gO.Update(gameTime, viewportRect);

                //Check for collision with fish pellet
                if (Gerald.CollidesWith(gO))
                {
                    if (gO.GetType() == typeof(FishPellet))
                    {
                        deadLevelObjects.Add(gO);
                        soundManager.Instance.PlaySound("Pop Cork");
                        levelScore.incrementScore(1);
                    }
                }
            }

            // If Jaws has been spawned.
            if (levelObjects.Contains(Jaws))
            {
                // DO per a pixel collision
                if (Gerald.perPixelCollide(Gerald.BoundingBox, Gerald.textureData, Jaws.BoundingBox, Jaws.textureData))
                {
                    endState(false);
                }
            }

            // IF half time elapsed spawn the shark.
            if (timeCounter < 45)
            {
                levelObjects.Add(Jaws);
                if (sharkAmbient.State == SoundState.Stopped)
                {
                    sharkAmbient.Volume   = 0.75f;
                    sharkAmbient.IsLooped = true;
                    sharkAmbient.Play();
                }
            }

            // if have more then 9 pellet spawn the shark
            if (localScore > 9)
            {
                levelObjects.Add(Jaws);

                if (sharkAmbient.State == SoundState.Stopped)
                {
                    sharkAmbient.Volume   = 0.75f;
                    sharkAmbient.IsLooped = true;
                    sharkAmbient.Play();
                }
            }

            //Clean up dead objects.
            foreach (gameObject gO in deadLevelObjects)
            {
                levelObjects.Remove(gO);
            }

            // Check Win Condition
            if (localScore >= 20)
            {
                soundManager.Instance.PlaySound("Applause");
                theGame.changeState(new winState(theGame));
            }
        }