示例#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 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);
         }
     }
 }
 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));
 }
示例#5
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) }; ;
        }
示例#6
0
 public BasicMapScene()
 {
     Map = BasicTileMap.CreateTestMap();
     Camera = new Camera2D();
     TestPlayer = new PlayerTest();
 }