Example #1
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();
            }

            // TODO: Add your update logic here
            ballSimulation.Update(gameTime);
            splitterSystem.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

            base.Update(gameTime);
        }
Example #2
0
        public void Draw(SpriteBatch spriteBatch, float seconds)
        {
            gameSeconds += seconds;

            if (gameSeconds > 3f)
            {
                InitiateParticleSystem();
                gameSeconds = 0;
            }
            splitterSystem.Update(seconds);
            spriteBatch.Begin();
            spriteBatch.Draw(level, camera.GetGameWindow(), Color.Black);
            splitterSystem.Draw(spriteBatch, camera, sprite);
            spriteBatch.End();
        }
Example #3
0
        public override void Update(Microsoft.Xna.Framework.GameTime a_gameTime)
        {
            //Handle paused state
            if (m_isPaused)
            {
                if (m_gameView.DidPlayerPressQuit())
                {
                    m_handlerEvent.Invoke(this, new EventArgs());
                }
                if (m_gameView.DidPlayerPressPause())
                {
                    m_isPaused = !m_isPaused;
                }
            }
            else if (m_levelComplete)
            {
                if (m_gameView.DidPlayerPressQuit())
                {
                    if (m_currentLevel == CurrentLevel.END)
                    {
                        m_handlerEvent.Invoke(this, new EventArgs());
                    }
                    else
                    {
                        ResetGameAtCurrentLevel();
                    }
                }
            }
            else if (m_gameModel.IsPlayerDead())
            {
                //Add an if for a timer here, so if the timer is under 1sec or w/e, these ifs don't run. When that's done, destroy the particles and display the death screen like before.
                if (m_deathAnimationTimer < m_deathAnimationEnd)
                {
                    m_deathAnimationTimer += (float)a_gameTime.ElapsedGameTime.TotalSeconds;
                }
                else if (m_gameView.DidPlayerPressPause())
                {
                    m_handlerEvent.Invoke(this, new EventArgs());
                }
                else if (m_gameView.DidPlayerPressQuit())
                {
                    ResetGameAtCurrentLevel();
                }

                if (m_deathAnimationTimer > m_deathAnimationEnd && m_particles != null)
                {
                    m_particles = null;
                }
                else if (m_particles != null)
                {
                    m_particles.Update(a_gameTime);
                }
            }
            else
            {
                if (m_gameView.DidPlayerPressPause())
                {
                    m_isPaused = !m_isPaused;
                }

                //Input handling
                if (m_gameView.DidPlayerMoveLeft())
                {
                    m_gameModel.movePlayerLeft();
                }
                else if (m_gameView.DidPlayerMoveRight())
                {
                    m_gameModel.movePlayerRight();
                }
                else
                {
                    m_gameModel.StopPlayerMovingSideways();
                }

                if (m_gameView.DidPlayerJump())
                {
                    if (m_gameModel.Jump())
                    {
                        m_gameView.PlayJumpSound();
                    }
                }

                m_gameModel.Update((float)a_gameTime.ElapsedGameTime.TotalSeconds, m_camera);

                if (m_level.DidPlayIntersectWithLethalTile())
                {
                    m_gameModel.KillPlayer();

                    Vector2 playerPos = m_gameModel.GetPlayerPos();

                    m_particles = new SplitterSystem(playerPos);
                    m_particles.LoadContent(m_content);
                    m_gameView.PlayDeathSound();
                }
            }
            if (m_level.DidPlayerHitPortal() && !m_levelComplete)
            {
                m_currentLevel++;
                m_levelComplete = true;
            }

            m_gameView.UpdateKeyboard();

            base.Update(a_gameTime);
        }