Exemple #1
0
        public void Draw(LevelSpriteBatchPool spriteBatchPool, GameTime gameTime)
        {
            RenderState renderState = Prepare(true);

            spriteBatchPool.Begin(_gameState.Camera);

            // Draw Tiles.
            for (int x = renderState.RenderBegin.X; x < renderState.RenderEnd.X; x++)
            {
                for (int y = renderState.RenderBegin.Y; y < renderState.RenderEnd.Y; y++)
                {
                    Coordinates tile = new Coordinates(x, y);
                    GetTile(tile).Draw(spriteBatchPool.TileSpriteBatch, tile, GetTileDataAt(tile), this, gameTime);
                }
            }

            ParticleSystem.Draw(spriteBatchPool.TileSpriteBatch, gameTime);

            // Draw Entities, Shadows and lights.
            foreach (var e in renderState.OnScreenEntities)
            {
                // Draw the entity.
                e.Draw(spriteBatchPool.EntitiesSpriteBatch, gameTime);

                // Draw Entity overlay.
                if (Rise.ShowGui)
                {
                    e.DrawOverlay(spriteBatchPool.OverlaySpriteBatch, gameTime);
                    if (Rise.ShowDebugOverlay)
                    {
                        spriteBatchPool.OverlaySpriteBatch.PutPixel(e.Position, Color.Magenta);
                    }
                }

                // Draw Entity light source.
                LightSource light = e.GetComponent <LightSource>();
                if (light != null && light.IsOn)
                {
                    DrawLight(spriteBatchPool.LightsSpriteBatch, e.X, e.Y, light.Power, light.Color);
                }

                // TODO: Draw Entity shadow.
            }

            FinalizeDraw(spriteBatchPool);
        }
        private void FinalizeDraw(LevelSpriteBatchPool spriteBatchPool)
        {
            // Get the ambiant lightning.
            var ambiantLight = Properties.AmbiantLight;

            if (Properties.AffectedByDayNightCycle)
            {
                ambiantLight = _world.DayNightCycle.GetAmbiantLight();
            }

            // Get temporary render targets.
            var worldRenderTarget = Rise.Graphic.RenderTarget[0];
            var lightRenderTarget = Rise.Graphic.RenderTarget[1];

            // Draw Entities and tiles to their own rendertarget.
            Rise.Graphic.SetRenderTarget(worldRenderTarget);
            Rise.Graphic.Clear(new Color(148, 120, 92));
            spriteBatchPool.Tiles.End();
            spriteBatchPool.Shadows.End();
            spriteBatchPool.Entities.End();
            spriteBatchPool.Overlay.End();

            // Draw shadow to their own rendertarget.
            Rise.Graphic.SetRenderTarget(lightRenderTarget);
            Rise.Graphic.Clear(ambiantLight);
            spriteBatchPool.Lights.End();

            // Now let's draw everything to the screen.
            Rise.Graphic.SetDefaultRenderTarget();

            // Blit the world on screen.
            spriteBatchPool.Generic.Begin();
            spriteBatchPool.Generic.Draw(worldRenderTarget, Rise.Graphic.GetBound(), Color.White);
            spriteBatchPool.Generic.End();

            // Apply lightning.
            spriteBatchPool.Generic.Begin(SpriteSortMode.Immediate, LightBlend);
            spriteBatchPool.Generic.Draw(lightRenderTarget, Rise.Graphic.GetBound(), Color.White);
            spriteBatchPool.Generic.End();
        }
        public void Draw(LevelSpriteBatchPool spriteBatchPool, GameTime gameTime)
        {
            spriteBatchPool.Begin(_gameState.Camera);

            // Draw Tiles.
            foreach (var coords in QueryCoordinates(_gameState.Camera.Bound))
            {
                GetTile(coords).Draw(spriteBatchPool.Tiles, coords, GetTileDataAt(coords), this, gameTime);
            }

            ParticleSystem.Draw(spriteBatchPool.Tiles, gameTime);

            var entitiesToDraw = new EntityCollection();

            entitiesToDraw.AddRange(QueryEntity(_gameState.Camera.Bound.Inflate(Game.Unit * 4f, Game.Unit * 12f)));
            entitiesToDraw.SortForRender();

            // Draw Entities, Shadows and lights.
            foreach (var e in entitiesToDraw)
            {
                // Draw the entity.
                e.Draw(spriteBatchPool, gameTime);

                // Draw Entity overlay.
                if (Rise.Ui.Enabled)
                {
                    e.Overlay(spriteBatchPool.Overlay, gameTime);
                }

                if (Rise.Debug.GAME)
                {
                    spriteBatchPool.Overlay.PutPixel(e.Position, Color.Magenta);
                }
            }

            FinalizeDraw(spriteBatchPool);
        }