示例#1
0
        public void Draw(Graphics.Graphics graphics, Camera2D camera = null)
        {
            int tx = 0, ty = 0;
            int wBounds = Metadata.Width, hBounds = Metadata.Height;
            if(camera != null) //if given a full camera, let's only render a viewport so we don't use as many resources!
            {
                var renderPoints = GetMaxRenderPoints(graphics, camera);
                tx = renderPoints[0] - 1;
                wBounds = renderPoints[1] + 1;
                ty = renderPoints[2] - 1;
                hBounds = renderPoints[3] + 1;
            }

            for(int y = ty; y < hBounds; y++)
            {
                for(int x = tx; x < wBounds; x++)
                {
                    if (y < 0 || y > Metadata.Height - 1)
                        continue;
                    if (x < 0 || x > Metadata.Width - 1)
                        continue;

                    if (TileMap[y, x] != null)
                        TileMap[y, x].Draw(graphics);
                }
            }
        }
        public BasicLightableScene(Graphics.Graphics graphics)
        {
            int width, height;
            width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width;
            height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height;

            Camera = new Camera2D();

            LightScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                width, height);
            BaseScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                width, height);

            _Entities = new List<IAnimatedEntity>();
            _StaticLights = new List<LightSource>();

            if (!Minecraft2D.ScaleGame)
            {
                graphics.ResolutionChanged += (sender, e) =>
                {
                    Console.WriteLine("[BasicLightableScene] Destroying and recreating render targets.");

                    width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width;
                    height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height;
                    LightScene.Dispose();
                    BaseScene.Dispose();

                    LightScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                        width, height);
                    BaseScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                        width, height);
                };
            }
        }
示例#3
0
        public override void Draw(Graphics.Graphics graphics)
        {
            frameCounter++;

            SpriteFont fallbackFont = graphics.GetSpriteFontByName("fallback");
            //Current screen should never be null. Previous could, however.
            graphics.GetSpriteBatch().DrawString(fallbackFont, $"CurrentScreen: {screenManager.CurrentScreen.ScreenName}", Vector2.Zero, Color.Black);
            if(screenManager.PreviousScreen != null)
            {
                graphics.GetSpriteBatch().DrawString(fallbackFont, $"PreviousScreen: {screenManager.PreviousScreen.ScreenName}", new Vector2(0, 16), Color.Black);
            }

            graphics.GetSpriteBatch().DrawString(fallbackFont,
                    $"FPS: " + framerate, new Vector2(0, 64), Color.Black);

            if (screenManager.CurrentScreen != null && screenManager.CurrentScreen.GetType() == typeof(BlankScreen))
            {
                var debugScreen = (BlankScreen)screenManager.CurrentScreen;
                //graphics.GetSpriteBatch().DrawString(fallbackFont,
                //    $"Lights: " + debugScreen.LightsRenderer.Lights.Count(), new Vector2(0, 64 + 16), Color.Black);
                graphics.GetSpriteBatch().DrawString(fallbackFont,
                    $"X-Velocity: " + debugScreen.TestEntity.xVelocity, new Vector2(0, 64 + 32), Color.Black);
            }

            graphics.GetSpriteBatch().DrawString(fallbackFont, $"Mouse Position: {Minecraft2D.InputHelper.MousePosition.ToString()}; Inside: {Minecraft2D.InputHelper.IsMouseInsideWindow()}"
                , new Vector2(0, 32), Color.Black);
        }
示例#4
0
 public Texture2D GetRectangle(Graphics.Graphics graphics)
 {
     if (_Rectangle == null)
     {
         _Rectangle = new Texture2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, 1, 1);
         _Rectangle.SetData<Color>(new Color[] { Color.White });
     }
     return _Rectangle;
 }
示例#5
0
        public override void Draw(Graphics.Graphics graphics)
        {
            graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);
            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.Black);
            DrawBackground(graphics);
            DrawControls(graphics);

            DrawCursor(graphics);
            graphics.GetSpriteBatch().End();
        }
示例#6
0
 public override void Draw(Graphics.Graphics graphics)
 {
     var texture = graphics.GetTexture2DByName(SheetName);
     graphics.GetSpriteBatch().Draw(
         texture,
         Position.ToRectangle(),
         Region,
         Color.White
     );
 }
示例#7
0
 public void Draw(Graphics.Graphics graphics, Camera2D camera = null)
 {
     // TODO: camera shit
     for(int y = 0; y < Metadata.Height; y++)
     {
         for(int x = 0; x < Metadata.Width; x++)
         {
             if(TileMap[y, x] != null)
                 TileMap[y, x].Draw(graphics);
         }
     }
 }
示例#8
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 BasicLightableSceneWithMap(Graphics.Graphics graphics)
     : base(graphics)
 {
     Map = new MinecraftMap();
     _Map.GenerateTestMap();
     Camera = new Camera2D();
     int x = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width / 2;
     int y = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height / 2;
     //minX = x;
     //minY = y;
     //maxX = (int)world.WorldSize.X - (MainGame.GlobalGraphicsDeviceManager.PreferredBackBufferWidth / 2);
     //maxY = (int)world.WorldSize.Y - (MainGame.GlobalGraphicsDeviceManager.PreferredBackBufferHeight / 2);
     Camera.Position = new Vector2(x + (32 * 32), y + (25 * 32));
 }
示例#10
0
        //This is called second
        protected override void LoadContent()
        {
            Console.WriteLine("Load Content");

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            graphics = new Graphics.Graphics(this, _spriteBatch, this.Content, _graphics);
            graphics.LoadContent();

            InputHelper = new InputHelper(this); //this will not copy. my C++ instincts are kicking in ;)
#if DEBUG
            graphics.DebugModeStuff();
#endif
        }
示例#11
0
 public override void Draw(Graphics.Graphics graphics)
 {
     var spriteFont = graphics.GetSpriteFontByName("minecraft");
     var textSize = spriteFont.MeasureString(Text);
     var center = textSize / 2;
     graphics.GetSpriteBatch().DrawString (
         spriteFont,
         Text,
         PositionSize.ToVector2(),
         Color.Yellow,
         (float)DegreesToRadians(-20),
         center,
         (float)Scale,
         Microsoft.Xna.Framework.Graphics.SpriteEffects.None, 1f
     );
 }
示例#12
0
        public void Draw(Graphics.Graphics graphics)
        {
            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.CornflowerBlue);
            graphics.GetSpriteBatch().Begin(sortMode: Microsoft.Xna.Framework.Graphics.SpriteSortMode.Deferred,
                /*transformMatrix: Camera.Transformation(graphics.GetGraphicsDeviceManager().GraphicsDevice)
                ,*/ depthStencilState: DepthStencilState.None, samplerState: SamplerState.PointClamp);
            Map.Draw(graphics);

            int tx, ty;
            tx = (int)Math.Floor(Minecraft2D.InputHelper.MousePosition.X / Constants.TileSize);
            ty = (int)Math.Floor(Minecraft2D.InputHelper.MousePosition.Y / Constants.TileSize);
            if(Map.GetTileAtIndex(tx, ty) != null)
                graphics.GetSpriteBatch().Draw(GetRectangle(graphics), new Rectangle(tx * Constants.TileSize, ty * Constants.TileSize, Constants.TileSize, Constants.TileSize), Color.Gray * .32f);
            TestPlayer.Draw(graphics);
            graphics.GetSpriteBatch().End();
        }
        public new void Draw(Graphics.Graphics graphics)
        {
            DrawBaseScene(graphics);
            DrawLights(graphics);

            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.White);
            graphics.GetSpriteBatch().Begin(blendState: Lighted.Multiply, samplerState: SamplerState.PointClamp);

            var screenRect = graphics.ScreenRectangle();
            graphics.GetSpriteBatch().Draw(BaseScene, screenRect, Color.White);
            ScreenRect = screenRect;

            if (RenderLights)
                graphics.GetSpriteBatch().Draw(LightScene, screenRect, Color.White);

            graphics.GetSpriteBatch().End();
        }
        public void DrawBaseScene(Graphics.Graphics graphics)
        {
            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(BaseScene);
            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.CornflowerBlue);
            graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone,
                transformMatrix: Camera.Transformation(graphics.GetGraphicsDeviceManager().GraphicsDevice));

            Map.Draw(graphics, Camera);
            //Draws the regular entites and their sprites and whatnot.
            ((List<IAnimatedEntity>)Entities).ForEach(entity =>
            {
                entity.Draw(graphics);
            });

            graphics.GetSpriteBatch().End();

            graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null);
        }
示例#15
0
        public BlankScreen(Graphics.Graphics graphics)
        {
            TestEntity = new PlayerTest();
            Console.WriteLine(TestEntity.Hitbox.ToString());
            TestEntity.Animating = false;

            Scene = new BasicMapScene();
            //Scene.AmbientLight = Color.White;//new Color(20, 20, 20);
            TestEntity.LightSize = 0f;

            //int x = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width / 2;
            //int y = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height / 2;
            //TestEntity.Position = new Vector2(x + (32 * 32), y + (25 * 32) - 64);

            //Scene.AddEntity(TestEntity); //player entity
            //FakeSunEntity = new AnnoyingLightEntityTest();
            //Scene.AddEntity(FakeSunEntity); //lol
        }
示例#16
0
        public LightingTest(Graphics.Graphics graphics)
        {
            int width, height;
            width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width;
            height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height;

            FullyLitWorld = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height);
            Lightpass = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height);

            Lights = new List<QuadLightSource>();

            graphics.ResolutionChanged += (sender, e) =>
            {
                width = e.Width;
                height = e.Height;
                Console.WriteLine("Destroying lighting test textures.");
                FullyLitWorld.Dispose();
                FullyLitWorld = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height);
                Lightpass.Dispose();
                Lightpass = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height);
            };
        }
示例#17
0
        public override void Draw(Graphics.Graphics graphics)
        {
            int textX = (int)(PositionSize.Center.X - graphics.GetSpriteFontByName("minecraft").MeasureString(Text).X / 2);

            if (Enabled == true)
            {
                if (Selected)
                {
                    /*graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("widgets"),
                        new Rectangle(PositionSize.X, PositionSize.Y, (int)(PositionSize.Width * Math.Min(ScaleFactor, MaxScaleFactor)),
                            (int)(PositionSize.Height * Math.Min(ScaleFactor, MaxScaleFactor))),
                        new Rectangle(WidgetsMap.HighlightedButton.X, WidgetsMap.HighlightedButton.Y, WidgetsMap.HighlightedButton.RegionWidth, WidgetsMap.HighlightedButton.RegionHeight), Color.White);
                        */

                    graphics.DrawText(Text, new Rectangle(textX, PositionSize.Y + 8, PositionSize.Width, PositionSize.Height), Color.Yellow,
                        (float)Math.Min(ScaleFactor, MaxScaleFactor));
                }
                else
                {
                    /*graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("widgets"),
                        new Rectangle(PositionSize.X, PositionSize.Y, PositionSize.Width, PositionSize.Height),
                        new Rectangle(WidgetsMap.EnabledButton.X, WidgetsMap.EnabledButton.Y, WidgetsMap.EnabledButton.RegionWidth, WidgetsMap.EnabledButton.RegionHeight), Color.White);
                        */

                    graphics.DrawText(Text, new Rectangle(textX, PositionSize.Y + 8, PositionSize.Width, PositionSize.Height), Color.White,
                        (float)Math.Min(ScaleFactor, MaxScaleFactor));
                }
            }
            else
            {
                /*graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("widgets"),
                        new Rectangle(PositionSize.X, PositionSize.Y, PositionSize.Width, PositionSize.Height),
                        new Rectangle(WidgetsMap.DisabledButton.X, WidgetsMap.DisabledButton.Y, WidgetsMap.DisabledButton.RegionWidth, WidgetsMap.DisabledButton.RegionHeight), Color.White);
                        */

                graphics.DrawText(Text, new Vector2((textX * Constants.SpriteScale), (PositionSize.Y + 8) * Constants.SpriteScale), Color.Gray);
            }
        }
示例#18
0
 public override void Draw(Graphics.Graphics graphics)
 {
     Scene.Draw(graphics);
 }
示例#19
0
 private Texture2D MakeRectangle(Graphics.Graphics graphics, Color color)
 {
     var rectangle = new Texture2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, 1, 1);
     rectangle.SetData(new[] { color });
     return rectangle;
 }
示例#20
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);
        }
        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);
        }
示例#22
0
        /// <summary>
        /// size 4 array, meant for tile index not abs X positions
        /// 0: minX
        /// 1: maxX
        /// 2: minY
        /// 3: maxY
        /// </summary>
        /// <returns>
        /// </returns>
        private int[] GetMaxRenderPoints(Graphics.Graphics graphics, Camera2D camera)
        {
            int minX = (int)Math.Ceiling(((float)camera.Position.X - ((Metadata.Width * Constants.TileSize) / 2)) / Constants.TileSize);
            int maxX = (int)Math.Ceiling(((float)camera.Position.X + ((Metadata.Width * Constants.TileSize) / 2)) / Constants.TileSize);
            int minY = (int)Math.Ceiling(((float)camera.Position.Y - ((Metadata.Height * Constants.TileSize) / 2)) / Constants.TileSize);
            int maxY = (int)Math.Ceiling(((float)camera.Position.Y + ((Metadata.Height * Constants.TileSize) / 2)) / Constants.TileSize);

            return new int[4] { Zeroize(minX), Zeroize(maxX), Zeroize(minY), Zeroize(maxY) }; ;
        }
示例#23
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);
        }
示例#24
0
        public override void Draw(Graphics.Graphics graphics)
        {
            DrawFullyLit(graphics);
            DrawLight(graphics);

            graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.White);
            //graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, Multiply, null, null, null, null, null);
            graphics.GetSpriteBatch().Begin(blendState: Multiply, sortMode: SpriteSortMode.Immediate);
            graphics.GetSpriteBatch().Draw(FullyLitWorld, graphics.ScreenRectangle(), Color.White);
            if(RenderLight)
                graphics.GetSpriteBatch().Draw(Lightpass, graphics.ScreenRectangle(), Color.White);
            graphics.GetSpriteBatch().End();
        }