Ejemplo n.º 1
0
        public void Update(GameTime gameTime, Vector2 matchPos, Player player)
        {
            m_iEffectDuration   -= gameTime.ElapsedGameTime.Milliseconds;
            m_iBurstCountdownMS -= gameTime.ElapsedGameTime.Milliseconds;

            if ((m_iBurstCountdownMS <= 0) && (m_iEffectDuration >= 0))
            {
                for (int i = 0; i < m_iNewParticleAmmount; i++)
                {
                    createParticle(matchPos);
                }
                m_iBurstCountdownMS = m_iBurstFrequencyMS;
            }

            for (int i = m_allParticles.Count() - 1; i >= 0; i--)
            {
                m_allParticles[i].Update(gameTime);

                if (m_allParticles[i].m_iAge <= 0)
                {
                    if (this.m_eType == EffectType.spew)
                    {
                        m_emManager.AddEffect(EffectType.explosion, m_allParticles[i].m_vPos);
                    }
                    m_allParticles.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 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
            double timePassed = gameTime.ElapsedGameTime.TotalMilliseconds;

            m_iElapsedMilliseconds += timePassed;
            explosionTimer         += timePassed;

            if (m_iElapsedMilliseconds > 1000)
            {
                m_iElapsedMilliseconds -= 1000;
                m_iFPS        = m_iFrameCount;
                m_iFrameCount = 0;
            }

            if (explosionTimer > 4000)
            {
                explosionTimer = 0;
                Random  rand = new Random();
                Vector2 loc;
                loc.X = rand.Next(graphics.PreferredBackBufferWidth);
                loc.Y = rand.Next(graphics.PreferredBackBufferHeight);

                if (mGameState == GameState.Won)
                {
                    mEffectManager.AddEffect(EffectType.explosion, loc);
                }
            }


            mGameState = mInputManager.processInputs(mGameState, mDeanRunner, gameTime, mGameLanguage);
            foreach (Enemies ham in hamUnitList)
            {
                ham.update(gameTime);
            }

            if (mGameState == GameState.Title)
            {
            }
            if (mGameState == GameState.Menu)
            {
                mDeanRunner = new Player(mDeanRunnerTexture, 12, new Rectangle(0, 0, 128, 128), new Vector2(640, 480), new Vector2(64, 64), Color.White, 0.0f, 1.0f, SpriteEffects.None);
                gHamsFound  = new int[NUM_HAM];
                loadUnits();

                if (mInputManager.menuOption == 1)      //play
                {
                    mCursor = new Unit(mBulletTexture, new Rectangle(0, 0, 8, 8), new Vector2(350, 250), new Vector2(4, 4), Color.White, 0.0f, 1.0f, SpriteEffects.None, 1);
                }
                else if (mInputManager.menuOption == 2) //Controls
                {
                    mCursor = new Unit(mBulletTexture, new Rectangle(0, 0, 8, 8), new Vector2(350, 300), new Vector2(4, 4), Color.White, 0.0f, 1.0f, SpriteEffects.None, 1);
                }
                else if (mInputManager.menuOption == 3) //Options
                {
                    mCursor = new Unit(mBulletTexture, new Rectangle(0, 0, 8, 8), new Vector2(350, 350), new Vector2(4, 4), Color.White, 0.0f, 1.0f, SpriteEffects.None, 1);
                }
                else if (mInputManager.menuOption == 4) //Quit
                {
                    mCursor = new Unit(mBulletTexture, new Rectangle(0, 0, 8, 8), new Vector2(350, 400), new Vector2(4, 4), Color.White, 0.0f, 1.0f, SpriteEffects.None, 1);
                }
            }
            if (mGameState == GameState.Playing)
            {
                //movements handled in InputManager
                int found = checkHamProximity();
                int score = 0;


                if (found == 7)
                {
                }
                else
                {
                    gHamsFound[found] = 1;
                }

                foreach (int i in gHamsFound)
                {
                    if (i == 1)
                    {
                        score += 100;
                    }
                }

                found_ham_string = "Score: " + score;

                if (score == 600)
                {
                    mGameState = GameState.Won;
                }
            }
            if (mGameState == GameState.Paused)
            {
                if (mInputManager.menuOption == 1)
                {
                    mCursor = new Unit(mBulletTexture, new Rectangle(0, 0, 8, 8), new Vector2(350, 250), new Vector2(4, 4), Color.White, 0.0f, 1.0f, SpriteEffects.None, 1);
                }
                else if (mInputManager.menuOption == 2)
                {
                    mCursor = new Unit(mBulletTexture, new Rectangle(0, 0, 8, 8), new Vector2(350, 300), new Vector2(4, 4), Color.White, 0.0f, 1.0f, SpriteEffects.None, 1);
                }
                else if (mInputManager.menuOption == 3)
                {
                    mCursor = new Unit(mBulletTexture, new Rectangle(0, 0, 8, 8), new Vector2(350, 350), new Vector2(4, 4), Color.White, 0.0f, 1.0f, SpriteEffects.None, 1);
                }
            }
            if (mGameState == GameState.Won)
            {
                mEffectManager.Update(gameTime, mDeanRunner.mAnimation.mSpritePosition, mDeanRunner);
            }
            if (mGameState == GameState.Finish)
            {
                Exit();
            }

            gSeconds.SetValue((float)gameTime.TotalGameTime.Milliseconds / 1000);

            base.Update(gameTime);
        }