示例#1
0
        public override void Draw(GameTime gameTime)
        {
            ResolutionManager.BeginDraw();

            spriteBatch.Begin(SpriteSortMode.FrontToBack,
                              BlendState.AlphaBlend,
                              SamplerState.PointClamp,
                              null,
                              null,
                              null,
                              Camera2D.GetTransformMatrix());

            mapManager.Draw(spriteBatch);
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.FrontToBack,
                              BlendState.AlphaBlend,
                              SamplerState.PointClamp,
                              null,
                              null,
                              null,
                              ResolutionManager.GetTransformationMatrix());
            windowManager.Draw(spriteBatch);

            spriteBatch.End();
        }
示例#2
0
        /// <summary>
        /// Takes screen coordinates (2D position like where the mouse is on screen) then converts it to world position (where we clicked at in the world).
        /// </summary>
        private static Vector2 ScreenToWorld(Vector2 input)
        {
            input.X -= ResolutionManager.VirtualViewportX;
            input.Y -= ResolutionManager.VirtualViewportY;

            return(Vector2.Transform(input, Matrix.Invert(Camera2D.GetTransformMatrix())));
        }
        public void UpdateMove(Camera2D _camera)
        {
            Matrix pos = _camera.GetTransformMatrix();

            if (-pos.M41 % _width*2 == 0)
                _position.X = -pos.M41 + _width;
            _position.X += -_speed;
        }
示例#4
0
        public void Draw(SpriteBatch spriteBatch)
        {
            tiledRenderer.Draw(Camera2D.GetTransformMatrix(), null, null, 0f);

            for (int i = 0; i < objects.Count; i++)
            {
                objects[i].Draw(spriteBatch);
            }

#if DEBUG
            for (int i = 0; i < tileCollisionsDoor.Count; i++)
            {
                spriteBatch.Draw(tileTexture, tileCollisionsDoor[i].Rectangle, Color.Green);
            }
#endif
            spriteBatch.End();

            spriteBatch.Begin();
            if (tiledMap.GetLayer("Overlay") != null)
            {
                tiledRenderer.Draw(tiledMap.GetLayer("Overlay"), Camera2D.GetTransformMatrix(), null, null, 1f);
            }
        }
示例#5
0
        public void Draw(Level level)
        {
            if (RenderTargetsAreOutdated())
            {
                UpdateRenderTargets();
            }

            _camera.Position = Vector2.Round(GraphicsConstants.PhysicsToView(level.CameraCenter) - _graphicsDevice.Viewport.Bounds.Size.ToVector2() / 2f);

            _renderTargetStack.Push(_worldTarget);
            {
                _graphicsDevice.Clear(Color.Transparent);
                Background.Draw(_camera);
                TileMap.Draw(level, _camera);

                if (HideProgress)
                {
                    _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: _camera.GetTransformMatrix());

                    _spriteBatch.DrawString(_regularFont, "Press SPACE BAR to jump/kick.", new Vector2(256f, 2048f), Color.White);
                    _spriteBatch.DrawString(_regularFont, "Use the ARROW KEYS to move.", new Vector2(60f, 1700f), Color.White);
                    _spriteBatch.DrawString(_regularFont, "Tap DOWN to fall through platforms.", new Vector2(140f, 1520f), Color.White);
                    _spriteBatch.DrawString(_regularFont, "Strike R to restart.", new Vector2(670f, 1800f), Color.White);
                    _spriteBatch.DrawString(_regularFont, "Slap SHIFT while running to dash.", new Vector2(200f, 1190f), Color.White);
                    _spriteBatch.DrawString(_regularFont, "You can chain kicks and dashes...", new Vector2(80f, 900f), Color.White);
                    _spriteBatch.DrawString(_regularFont, "... if you hit your torch.", new Vector2(300f, 800f), Color.White);
                    _spriteBatch.DrawString(_regularFont, "Psst... you can press P\nto skip this tutorial.", new Vector2(-350f, 2170f), Color.White);

                    _spriteBatch.End();
                }

                if (TheWinnerIsYou)
                {
                    _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: _camera.GetTransformMatrix());

                    _spriteBatch.DrawString(_regularFont, "You win! Sleep tight.", new Vector2(80f, 270f), Color.White);

                    _spriteBatch.End();
                }

                _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: _camera.GetTransformMatrix());

                int startX = (int)Math.Floor(_camera.Position.X / _finishTexture.Width);
                int endX   = (int)Math.Floor((_camera.Position.X + _spriteBatch.GraphicsDevice.Viewport.Width) / _finishTexture.Width);

                float y = GraphicsConstants.PhysicsToView(level.FinishHeight);

                for (int x = startX; x <= endX; x++)
                {
                    _spriteBatch.Draw(_finishTexture, new Vector2(x * _finishTexture.Width, y - _finishTexture.Height / 2f), Color.White);
                }

                _spriteBatch.End();

                Particles.Draw(_camera);
                Entities.Draw(level, _camera);

                TileMap.DrawGrates(level, _camera);
            }
            _renderTargetStack.Pop();

            _renderTargetStack.Push(_waterTarget);
            {
                _graphicsDevice.Clear(Color.Transparent);
                _waterView.DrawMask(level, _camera);
            }
            _renderTargetStack.Pop();

            _waterEffect.Parameters["Time"].SetValue(_shaderTimer);

            Vector2 camera = _camera.Position / _graphicsDevice.Viewport.Bounds.Size.ToVector2();

            _waterEffect.Parameters["Camera"].SetValue(camera);

            _waterEffect.Parameters["Position"].SetValue(_camera.Position);
            _waterEffect.Parameters["Dimensions"].SetValue(_graphicsDevice.Viewport.Bounds.Size.ToVector2() + new Vector2(128f));

            if (level.EntityWorld.TryGetEntity(TorchEntityID, out Entity? te))
            {
                if (!te.IsPutOut && level.PhysicsWorld.TryGetBody(te.BodyID, out Body? torchBody))
                {
                    _waterEffect.Parameters["Light1"].SetValue(GraphicsConstants.PhysicsToView(torchBody.Position + torchBody.Bounds.Center));
                }
                else
                {
                    _waterEffect.Parameters["Light1"].SetValue(new Vector2(-1000f));
                }
            }

            _waterEffect.Parameters["Radius"].SetValue(_lightRadius);
            _waterEffect.Parameters["Ambience"].SetValue(_ambience);

            _spriteBatch.Begin(effect: _waterEffect);
            _spriteBatch.Draw(_worldTarget, Vector2.Zero, Color.White);
            _spriteBatch.End();

            _waterView.Draw(level, _camera);

            if (HideProgress)
            {
                _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: _camera.GetTransformMatrix());

                //_spriteBatch.DrawString(_regularFont, "Press SPACE BAR to jump/kick.", new Vector2(256f, 2048f), Color.White);
                //_spriteBatch.DrawString(_regularFont, "Use the ARROW KEYS to move.", new Vector2(60f, 1700f), Color.White);

                _spriteBatch.End();
            }

            _spriteBatch.Begin(samplerState: SamplerState.PointClamp);

            Vector2 progPos = new Vector2(32f, _graphicsDevice.Viewport.Height / 2f);

            if (!HideProgress)
            {
                _spriteBatch.Draw(_progressTexture, progPos + new Vector2(-_progressTexture.Width / 2f, -_progressTexture.Height / 2f), Color.White);
            }

            Vector2 startView  = GraphicsConstants.PhysicsToView(Start);
            float   finishView = GraphicsConstants.PhysicsToView(level.FinishHeight);

            if (level.EntityWorld.TryGetEntity(TorchEntityID, out Entity? torchEntity))
            {
                if (level.PhysicsWorld.TryGetBody(torchEntity.BodyID, out Body? torchBody))
                {
                    Vector2 torchPosition = GraphicsConstants.PhysicsToView(torchBody.Position + torchBody.Bounds.Center);

                    if (!torchEntity.IsPutOut)
                    {
                        Vector2 arrowPosition = torchPosition;

                        arrowPosition.X = MathHelper.Clamp(arrowPosition.X, _camera.Position.X + 32f, _camera.Position.X + _graphicsDevice.Viewport.Width - 32f);
                        arrowPosition.Y = MathHelper.Clamp(arrowPosition.Y, _camera.Position.Y + 32f, _camera.Position.Y + _graphicsDevice.Viewport.Height - 32f);

                        _arrowSprite.Rotation = (torchPosition - arrowPosition).GetAngle();

                        _arrowSprite.Draw(_spriteBatch, arrowPosition - _camera.Position);
                    }

                    float tiy = Math.Clamp((torchPosition.Y - finishView) / (startView.Y - finishView), 0f, 1f);

                    if (!HideProgress)
                    {
                        _spriteBatch.Draw(_torchIconTexture,
                                          progPos + new Vector2(-_torchIconTexture.Width / 2f, (tiy - 0.5f) * (_progressTexture.Height - 32f) - _torchIconTexture.Height / 2f),
                                          Color.White);
                    }
                }
            }

            if (level.EntityWorld.TryGetEntity(PlayerEntityID, out Entity? playerEntity))
            {
                if (level.PhysicsWorld.TryGetBody(playerEntity.BodyID, out Body? playerBody))
                {
                    Vector2 playerPosition = GraphicsConstants.PhysicsToView(playerBody.Position + playerBody.Bounds.Center);

                    float piy = Math.Clamp((playerPosition.Y - finishView) / (startView.Y - finishView), 0f, 1f);

                    if (!HideProgress)
                    {
                        _spriteBatch.Draw(_playerIconTexture,
                                          progPos + new Vector2(-_playerIconTexture.Width / 2f, (piy - 0.5f) * (_progressTexture.Height - 32f) - _playerIconTexture.Height / 2f),
                                          Color.White);
                    }
                }
            }

            _spriteBatch.Draw(_pixelTexture, _graphicsDevice.Viewport.Bounds, Color.Black * 0.5f * _loseScreenOpacity);

            _spriteBatch.DrawString(_regularFont, "Press R to restart.",
                                    _graphicsDevice.Viewport.Bounds.Center.ToVector2() - _regularFont.MeasureString("Press R to restart.") / 2f, Color.White * _loseScreenOpacity);

            _spriteBatch.Draw(_pixelTexture, _graphicsDevice.Viewport.Bounds, Color.Black * _fadeOutOpacity);

            if (Header != null)
            {
                float headerOpacity = MathHelper.Clamp(1f - _headerTimer / _headerTime, 0f, 1f);

                _spriteBatch.Draw(_gradientTexture, Vector2.Zero, Color.White * headerOpacity);
                _spriteBatch.DrawString(_regularFont, Header, new Vector2(_graphicsDevice.Viewport.Bounds.Center.X - _regularFont.MeasureString(Header).X / 2f, 24f), Color.White * headerOpacity);
            }

            _spriteBatch.End();
        }
示例#6
0
        public void DrawMask(Level level, Camera2D camera)
        {
            _waterMaskAnimation.Apply(_waterMaskSprite, _animationTimer);

            _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: camera.GetTransformMatrix());

            int startX = (int)Math.Floor(camera.Position.X / _waterSize);
            int endX   = (int)Math.Floor((camera.Position.X + _spriteBatch.GraphicsDevice.Viewport.Width) / _waterSize);

            int top    = level.TileMap.Height * GraphicsConstants.TileSize - (int)Math.Round(GraphicsConstants.PhysicsToView(level.WaterLevel));
            int bottom = level.TileMap.Height * GraphicsConstants.TileSize + 300;

            for (int x = startX; x <= endX; x++)
            {
                _waterMaskSprite.Draw(_spriteBatch, new Vector2(x * _waterSize, top - _waterSize / 2f));
            }
            _spriteBatch.Draw(_pixelTexture, new Rectangle(startX * _waterSize, top + _waterSize / 2, (endX - startX + 1) * _waterSize, bottom - top), Color.White);

            _spriteBatch.End();
        }
示例#7
0
        public void Draw(Level level, Camera2D camera)
        {
            _waterOutlineAnimation.Apply(_waterOutlineSprite, _animationTimer);

            _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: camera.GetTransformMatrix());

            int startX = (int)Math.Floor(camera.Position.X / _waterSize);
            int endX   = (int)Math.Floor((camera.Position.X + _spriteBatch.GraphicsDevice.Viewport.Width) / _waterSize);

            int top = level.TileMap.Height * GraphicsConstants.TileSize - (int)Math.Round(GraphicsConstants.PhysicsToView(level.WaterLevel));

            for (int x = startX; x <= endX; x++)
            {
                _waterOutlineSprite.Draw(_spriteBatch, new Vector2(x * _waterSize, top - _waterSize / 2f));
            }

            _spriteBatch.End();
        }
示例#8
0
        public void Draw(Camera2D camera)
        {
            _spriteBatch.Begin(sortMode: SpriteSortMode.FrontToBack, samplerState: SamplerState.PointClamp, transformMatrix: camera.GetTransformMatrix());

            foreach (Particle particle in _particles)
            {
                particle.Draw(_spriteBatch);
            }

            _spriteBatch.End();
        }
 public void Draw(SpriteBatch spriteBatch, Camera2D camera)
 {
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,null,null,null,null,camera.GetTransformMatrix());
     foreach (Partikel p in _partikelList)
     {
         _shader.CurrentTechnique.Passes[0].Apply();
         _shader.Parameters["_colorTex"].SetValue(p.DrawColor.ToVector4());
         p.Draw(spriteBatch);
     }
     spriteBatch.End();
 }
示例#10
0
        public void Draw(Camera2D camera)
        {
            _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: camera.GetTransformMatrix());

            int startX = (int)Math.Floor(camera.Position.X / _tileSize);
            int startY = (int)Math.Floor(camera.Position.Y / _tileSize);
            int endX   = (int)Math.Floor((camera.Position.X + _spriteBatch.GraphicsDevice.Viewport.Width) / _tileSize);
            int endY   = (int)Math.Floor((camera.Position.Y + _spriteBatch.GraphicsDevice.Viewport.Height) / _tileSize);

            for (int y = startY; y <= endY; y++)
            {
                for (int x = startX; x <= endX; x++)
                {
                    DrawTile(x, y);
                }
            }

            _spriteBatch.End();
        }
示例#11
0
        public void DrawGrates(Level level, Camera2D camera)
        {
            _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: camera.GetTransformMatrix());

            for (int y = 0; y < level.TileMap.Height; y++)
            {
                for (int x = 0; x < level.TileMap.Width; x++)
                {
                    DrawGrate(x, y, level.TileMap);
                }
            }

            _spriteBatch.End();
        }