Esempio n. 1
0
 public override void Draw(Graphics.Graphics graphics)
 {
     var texture = graphics.GetTexture2DByName(SheetName);
     graphics.GetSpriteBatch().Draw(
         texture,
         Position.ToRectangle(),
         Region,
         Color.White
     );
 }
Esempio n. 2
0
        private void DrawBackground(Graphics.Graphics graphics)
        {
            var texture = graphics.GetTexture2DByName("terrain");
            int tx, ty;
            tx = (int)Math.Ceiling((double)graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width / 32);
            ty = (int)Math.Ceiling((double)graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height / 32);

            Vector2 textureIndex = new Vector2(13 * Constants.SpriteSize, 7 * Constants.SpriteSize);

            for (int x = 0; x < tx; x++)
                for (int y = 0; y < ty; y++)
                    graphics.GetSpriteBatch().Draw(texture, new Vector2(x * Constants.TileSize, y * Constants.TileSize).ToRectangle(),
                        textureIndex.ToRectangle(Constants.SpriteSize), Color.White);
        }
        public void DrawLights(Graphics.Graphics graphics)
        {
            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(LightScene);
            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(AmbientLight);
            graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, transformMatrix: Camera.Transformation(graphics.GetGraphicsDeviceManager().GraphicsDevice));

            var texture = graphics.GetTexture2DByName("circle");

            ((List<LightSource>)StaticLights).ForEach(light =>
            {
                graphics.GetSpriteBatch().Draw(
                    texture, light.Size, light.Color
                );
            });

            //The dynamic lights
            foreach (var entity in Entities.Where(x => x is IDynamicLightEntity))
            {
                if (entity is IDynamicLightEntity)
                {
                    var entityAsLight = (IDynamicLightEntity)entity;
                    var drawingPoint = entityAsLight.Position.ToRectangle();
                    drawingPoint.Width = texture.Width;
                    drawingPoint.Height = texture.Height;
                    if (entityAsLight.LightSize != 1.0f)
                    {
                        drawingPoint.Width = (int)(drawingPoint.Width * entityAsLight.LightSize);
                        drawingPoint.Height = (int)(drawingPoint.Height * entityAsLight.LightSize);
                    }

                    if (entityAsLight.LightOffset != null)
                    {
                        drawingPoint.X += (int)(entityAsLight.LightOffset.X - (drawingPoint.Width / 2));
                        drawingPoint.Y += (int)(entityAsLight.LightOffset.Y - (drawingPoint.Height / 2));
                    }

                    graphics.GetSpriteBatch().Draw(texture, drawingPoint, entityAsLight.LightColor);
                }
            }

            graphics.GetSpriteBatch().End();

            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null);
        }
Esempio n. 4
0
        private void DrawLight(Graphics.Graphics graphics)
        {
            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(Lightpass);
            graphics.GetSpriteBatch().Begin(blendState: BlendState.Additive);
            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(new Color(75, 75, 75, 100)); //ambient light

            Lights.ForEach(light =>
            {
                graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("circle"),
                    light.rectangle,
                    light.color);
            });

            var point = Minecraft2D.InputHelper.MousePosition.ToPoint();
            point.X -= (graphics.GetTexture2DByName("circle").Width / 2);
            point.Y -= (graphics.GetTexture2DByName("circle").Height / 2);

            graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("circle"), point.ToVector2(), Color.White);

            graphics.GetSpriteBatch().End();
            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null);
        }
Esempio n. 5
0
        private void DrawFullyLit(Graphics.Graphics graphics)
        {
            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(FullyLitWorld);
            graphics.GetSpriteBatch().Begin();

            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.CornflowerBlue);

            graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("trivium"),
                new Rectangle(0, 0, 800, 350), Color.White);

            graphics.GetSpriteBatch().End();
            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null);
        }