Exemplo n.º 1
0
        private void DrawMap2(Graphics graphics)
        {
            if (Terrain == null)
            {
                if (Image != null)
                {
                    graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;

                    graphics.DrawImage(Image, new Rectangle(0, 0, Width, Height), new Rectangle(0, 0, 128, 128), GraphicsUnit.Pixel);
                }
                return;
            }

            if (_TileRenderer == null)
            {
                _TileRenderer    = new TileRenderer(32);
                _OceanLayerId    = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\Ocean.png"), Bitmaps.Get("Data\\SeaWrap.png"));
                _LandLayerId     = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\Land.png"), null);
                _FogOfWarLayerId = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\FogOfWar.png"), Bitmaps.Get("Data\\FogOfWarWrap.png"));
                _RangesLayerId   = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\Ranges.png"), null);
            }

            CameraScale    = Width / Terrain.Width;
            CameraPosition = new Point(Terrain.Width / 2, Terrain.Height / 2);

            _TileRenderer.TileSize = CameraScale;
            _TileRenderer.DrawTiles(graphics, MapToDisplay(new Point(0, 0)), new Rectangle(0, 0, Terrain.Width, Terrain.Height), p =>
            {
                p.X           = Math.Min(Math.Max(p.X, 0), Terrain.Width - 1);
                p.Y           = Math.Min(Math.Max(p.Y, 0), Terrain.Height - 1);
                TerrainType t = Terrain.Get(p.X, p.Y, TerrainType.Sea);
                int result    = 0;
                switch (t)
                {
                case TerrainType.Sea: result |= _OceanLayerId; break;

                case TerrainType.Land: result |= _OceanLayerId | _LandLayerId; break;

                default: throw new Exception();
                }
                return(result);
            });

            Pen pen = new Pen(Color.FromArgb(64, 0, 0, 0));

            for (int x = 0; x < Terrain.Width; x++)
            {
                graphics.DrawLine(pen, MapToDisplay(new Point(x, 0)), MapToDisplay(new Point(x, Terrain.Height)));
            }
            for (int y = 0; y < Terrain.Height; y++)
            {
                graphics.DrawLine(pen, MapToDisplay(new Point(0, y)), MapToDisplay(new Point(Terrain.Width, y)));
            }
        }
Exemplo n.º 2
0
 public MapDisplay()
 {
     _TileRenderer    = new TileRenderer(32);
     _OceanLayerId    = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\Ocean.png"), Bitmaps.Get("Data\\SeaWrap.png"));
     _LandLayerId     = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\Land.png"), null);
     _FogOfWarLayerId = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\FogOfWar.png"), Bitmaps.Get("Data\\FogOfWarWrap.png"));
     _RangesLayerId   = _TileRenderer.AddLayer(TileRenderer.LayerLayout.Corners, Bitmaps.Get("Data\\Ranges.png"), null);
     _SoundPlayer     = new SoundPlayer();
     _ToolTip         = new ToolTip();
     CachedTiles      = new Bitmap[16];
     CameraScale      = 20;
     _CurrentOrder    = null;
 }