Ejemplo n.º 1
0
        public void Render(MapControl mapCtrl, Graphics buffer, Rectangle area)
        {
            if (mapCtrl.Map == null)
            {
                return;
            }

            float scale = mapCtrl.ScaleFactor;
            float pixelSize = ConstMap.PIXEL_SIZE * scale;
            ClientMap map = mapCtrl.Map;

            ushort mapX1 = (ushort)Math.Max(Math.Floor(mapCtrl.PosX / pixelSize - 1), 0);
            ushort mapY1 = (ushort)Math.Max(Math.Floor(mapCtrl.PosY / pixelSize - 1), 0);
            ushort mapX2 = (ushort)Math.Min(Math.Ceiling(mapCtrl.Width / scale / pixelSize + 2) + mapX1, map.Width);
            ushort mapY2 = (ushort)Math.Min(Math.Ceiling(mapCtrl.Height / scale / pixelSize + 2) + mapY1, map.Height);

            for (ushort y = mapY1; y < mapY2; y++)
            {
                for (ushort x = mapX1; x < mapX2; x++)
                {
                    Tile* tile = map[x, y];
                    if (tile != null && (*tile).Type == TileType.Wall)
                    {
                        float pixXToRealX = x * pixelSize - mapCtrl.PosX;
                        float pixXToRealY = y * pixelSize - mapCtrl.PosY;
                        RectangleF rect = new RectangleF(
                            pixXToRealX - -0,
                            pixXToRealY - -0,
                            pixelSize + -0,
                            pixelSize + -0);
                        buffer.FillRectangle(_fillBrush, rect);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Render(MapControl mapCtrl, Graphics buffer, Rectangle area)
        {
            ClientMap map = mapCtrl.Map;
            Player player = mapCtrl.PlayerData;
            if (map == null || player == null)
            {
                return;
            }

            int posX = (int)(player.Position.X + player.Size.Width / 2 - area.X - _fovRect.Width / 2);
            int posY = (int)(player.Position.Y + player.Size.Height / 2 - area.Y - _fovRect.Height / 2);

            float pSizeW = _fovBitmap.Width, pSizeHw = (float)_fovBitmap.Width / 2;
            float pSizeH = _fovBitmap.Height, pSizeHh = (float)_fovBitmap.Height / 2;

            if (player.Angle != _prewPlayerAngle)
            {
                _fovRotated.Clear(Color.FromArgb(0, 0, 0, 0));
                _fovRotated.TranslateTransform(pSizeHw, pSizeHh);
                _fovRotated.RotateTransform(player.Angle - _prewPlayerAngle);
                _fovRotated.TranslateTransform(-pSizeHw, -pSizeHh);
                _fovRotated.DrawImage(_fovBitmap, 0, 0);
                _prewPlayerAngle = player.Angle;
            }

            buffer.DrawImage(_fovRotatedBitmap, posX, posY, _fovRect, GraphicsUnit.Pixel);

            if (posX > 0)
            {
                buffer.FillRectangle(_fillBrush, new Rectangle(0, 0, posX, area.Height));
            }
            if (posY > 0)
            {
                buffer.FillRectangle(_fillBrush, new Rectangle(posX, 0, area.Width - posX, posY));
            }
            if (posX + _fovRect.Width < area.X + area.Width)
            {
                buffer.FillRectangle(_fillBrush, new Rectangle((int)(posX + _fovRect.Width), posY,
                    area.Width - posX, area.Height - posY));
            }
            if (posY + _fovRect.Height < area.Y + area.Height)
            {
                buffer.FillRectangle(_fillBrush, new Rectangle(posX, (int)(posY + _fovRect.Height),
                    area.Width - posX, area.Height - posY));
            }
        }
Ejemplo n.º 3
0
        public void Render(MapControl mapCtrl, Graphics buffer, Rectangle area)
        {
            if (_textBrush == null)
            {
                _textBrush = new SolidBrush(mapCtrl.ForeColor);
            }

            int startTileX, startTileY, tilesCntX, tilesCntY;
            _map.InvalidateArea(area, out startTileX, out startTileY, out tilesCntX, out tilesCntY);
            for (int x = startTileX; x < startTileX + tilesCntX; x++)
            {
                for (int y = startTileY; y < startTileY + tilesCntY; y++)
                {
                    Rectangle destRect = new Rectangle(x * _map.TileWidth - area.X,
                        y * _map.TileHeight - area.Y, _map.TileWidth, _map.TileHeight);
                    buffer.DrawImageUnscaledAndClipped(_map[x, y], destRect);
                    if (mapCtrl.ShowTileNumber)
                    {
                        buffer.DrawString(string.Format("{0}:{1}", x, y), mapCtrl.Font, _textBrush,
                            destRect, _textFormat);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public void UpdateTile(MapControl mapCtrl, ushort x, ushort y, Tile tile)
 {
 }
Ejemplo n.º 5
0
 public void ChangeScaleFactor(MapControl mapCtrl, float scaleFactor)
 {
 }
Ejemplo n.º 6
0
 public void ChangeMap(MapControl mapCtrl)
 {
 }
Ejemplo n.º 7
0
 public void ChangeScaleFactor(MapControl mapCtrl, float scaleFactor)
 {
     _map.Initialize(scaleFactor, true);
 }
Ejemplo n.º 8
0
 public void UpdateTile(MapControl mapCtrl, ushort x, ushort y, Tile tile)
 {
     ushort minX = (ushort) Math.Max(x - 1, 0);
     ushort maxX = (ushort) Math.Min(x + 1, mapCtrl.Map.Width - 1);
     ushort minY = (ushort) Math.Max(y - 1, 0);
     ushort maxY = (ushort) Math.Min(y + 1, mapCtrl.Map.Height - 1);
     for (y = minY; y <= maxY; y++)
     {
         for (x = minX; x <= maxX; x++)
         {
             mapCtrl.Map.FlagClearBorders(x, y);
         }
     }
 }
Ejemplo n.º 9
0
        public void Render(MapControl mapCtrl, Graphics buffer, Rectangle area)
        {
            ClientMap map = mapCtrl.Map;
            if (map == null)
            {
                return;
            }

            float scale = mapCtrl.ScaleFactor;
            float pixelSize = ConstMap.PIXEL_SIZE * scale;

            ushort mapX1 = (ushort)Math.Max(Math.Floor(mapCtrl.PosX / pixelSize - 1), 0);
            ushort mapY1 = (ushort)Math.Max(Math.Floor(mapCtrl.PosY / pixelSize - 1), 0);
            ushort mapX2 = (ushort)Math.Min(Math.Ceiling(mapCtrl.Width / scale / pixelSize + 2) + mapX1, map.Width);
            ushort mapY2 = (ushort)Math.Min(Math.Ceiling(mapCtrl.Height / scale / pixelSize + 2) + mapY1, map.Height);

            for (ushort y = mapY1; y < mapY2; y++)
            {
                for (ushort x = mapX1; x < mapX2; x++)
                {
                    Tile* tile = map[x, y];
                    if (tile != null && (*tile).Type == TileType.Wall)
                    {
                        float x1 = x*pixelSize - mapCtrl.PosX;
                        float y1 = y*pixelSize - mapCtrl.PosY;

                        int borders = map.Borders(x, y);
                        if (borders == 0)
                        {
                            borders = TileBorders.ScanAndSetBorders(x, y, TileType.Wall, map);
                        }

                        if (borders < 2)
                        {
                            continue;
                        }

                        float x2, y2;
                        if ((borders | 2) == borders)
                        {
                            y2 = y1 + pixelSize - 0;
                            buffer.DrawLine(_borderPen, x1, y1, x1, y2);
                        }
                        if ((borders | 4) == borders)
                        {
                            x2 = x1 + pixelSize - 0;
                            y2 = y1 + pixelSize - 0;
                            buffer.DrawLine(_borderPen, x2, y1, x2, y2);
                        }
                        if ((borders | 8) == borders)
                        {
                            x2 = x1 + pixelSize - 0;
                            buffer.DrawLine(_borderPen, x1, y1, x2, y1);
                        }
                        if ((borders | 16) == borders)
                        {
                            x2 = x1 + pixelSize - 0;
                            y2 = y1 + pixelSize - 0;
                            buffer.DrawLine(_borderPen, x1, y2, x2, y2);
                        }
                    }
                }
            }
        }