Exemplo n.º 1
0
        public override void Dispose()
        {
            // Remove listeners
            EventManager.Instance.UnregisterListener(this);
            EventManager.Instance.UnregisterListener(_mainCamera);
            _livesSystem.UnregisterEventListeners();
            for (int i = 0; i < _directors.Length; i++)
            {
                _directors[i].UnregisterEvents();
            }
            _root.UnregisterListeners();

            PongPostProcessor.Dispose();
        }
Exemplo n.º 2
0
        public override void Update(float dt)
        {
            _inputSystem.Update(dt);
            CheckPause();

            if (!Paused)
            {
                _processManager.Update(dt);

                // Do not need to be in lock-step
                _aiSystem.Update(dt);
                _livesSystem.Update(dt);
                _goalSystem.Update(dt);

                // Deterministic lock-step
                _acculmulator += dt;
                while (_acculmulator >= Constants.Global.TICK_RATE)
                {
                    _acculmulator -= Constants.Global.TICK_RATE;

                    _paddleSystem.Update(Constants.Global.TICK_RATE);
                    _ballMovementSystem.Update(Constants.Global.TICK_RATE);
                }

                // Update the directors
                for (int i = 0; i < _directors.Length; i++)
                {
                    _directors[i].Update(dt);
                }

                // Update particles
                VelocityParticleManager.Update(dt);

                // Update post-processing effects
                PongPostProcessor.Update(dt);
            }
        }
Exemplo n.º 3
0
        void DrawPong(float dt, float betweenFrameAlpha)
        {
            GameManager.GraphicsDevice.SetRenderTarget(_pongRenderTarget);
            Matrix center = Matrix.CreateTranslation(_pongRenderTarget.Bounds.Width / 2,
                                                     _pongRenderTarget.Bounds.Height / 2,
                                                     0);

            _renderSystem.DrawEntities(center,
                                       Constants.Pong.RENDER_GROUP,
                                       dt,
                                       betweenFrameAlpha);
            _renderSystem.SpriteBatch.Begin(SpriteSortMode.Deferred,
                                            null,
                                            null,
                                            null,
                                            null,
                                            null,
                                            center);
            VelocityParticleManager.Draw(_renderSystem.SpriteBatch);
            _renderSystem.SpriteBatch.Draw(Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_EDGE),
                                           new Vector2(0, Constants.Pong.PLAYFIELD_HEIGHT / 2
                                                       + Constants.Pong.EDGE_HEIGHT
                                                       + 100 / 2),
                                           null,
                                           null,
                                           new Vector2(0.5f, 0.5f),
                                           0,
                                           new Vector2(Constants.Pong.PLAYFIELD_WIDTH,
                                                       100),
                                           Color.Black,
                                           SpriteEffects.None,
                                           0);
            _renderSystem.SpriteBatch.Draw(Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_EDGE),
                                           new Vector2(0, -(Constants.Pong.PLAYFIELD_HEIGHT / 2
                                                            + Constants.Pong.EDGE_HEIGHT
                                                            + 100 / 2)),
                                           null,
                                           null,
                                           new Vector2(0.5f, 0.5f),
                                           0,
                                           new Vector2(Constants.Pong.PLAYFIELD_WIDTH,
                                                       100),
                                           Color.Black,
                                           SpriteEffects.None,
                                           0);
            _renderSystem.SpriteBatch.End();
            GameManager.GraphicsDevice.SetRenderTarget(null);

            _quadEffect.View       = _pongCamera.TransformMatrix;
            _quadEffect.Projection = _pongCamera.PerspectiveMatrix;
            _quadEffect.Texture    = _pongRenderTarget;

            PongPostProcessor.Begin();
            foreach (EffectPass pass in _quadEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                _quad.Draw(GameManager.GraphicsDevice);
            }

            RenderTarget2D processedPongRender = PongPostProcessor.End(false);

            _renderSystem.SpriteBatch.Begin(SpriteSortMode.Deferred,
                                            null,
                                            null,
                                            null,
                                            null,
                                            null,
                                            _mainCamera.TransformMatrix);
            _renderSystem.SpriteBatch.Draw(processedPongRender, new Rectangle((int)(processedPongRender.Bounds.X - processedPongRender.Bounds.Width / 2 + Constants.Pong.BUFFER_RENDER_POSITION.X),
                                                                              (int)(processedPongRender.Bounds.Y - processedPongRender.Bounds.Height / 2 + Constants.Pong.BUFFER_RENDER_POSITION.Y),
                                                                              processedPongRender.Bounds.Width,
                                                                              processedPongRender.Bounds.Height), Color.White);
            _renderSystem.SpriteBatch.End();
        }