Пример #1
0
        private void DrawTileRightEdge(Graphics canvas, Tile tile, TileShape shape, ImageAttributes attrs)
        {
            var drawEdge = (tile.Edges & 8) != 0;
            var drawTopCap = (tile.EndCaps & 64) != 0;
            var drawBottomCap = (tile.EndCaps & 128) != 0;

            if (shape.Right == null) {
                Debug.Assert(!drawEdge && !drawTopCap && !drawBottomCap);
                return;
            }

            var transform = new Matrix();
            transform.Translate(tile.X * App.PixelsPerTile + shape.Right.X1 + sliceOverdraw, tile.Y * App.PixelsPerTile + shape.Right.Y1 + sliceOverdraw);
            transform.Rotate(shape.Right.Angle - 90);
            canvas.Transform = transform;
            var length = shape.Right.Length;

            if (drawEdge) {
                var sprite = sprites.LoadTile(tile.SpriteSet, tile.SpriteTile, tile.SpritePalette, 27 + (tile.Y / 2) % 3);
                var sy = (tile.Y & 1) * 48;
                canvas.DrawImage(sprite.Image,
                    new Rectangle(sprite.Hitbox.Left, 0, sprite.Hitbox.Width, length),
                    0, sy - sprite.Hitbox.Top, sprite.Hitbox.Width, 48, GraphicsUnit.Pixel, attrs);
            }

            if (drawTopCap) {
                var sprite = sprites.LoadTile(tile.SpriteSet, tile.SpriteTile, tile.SpritePalette, 26);
                canvas.DrawImage(sprite.Image,
                    new Rectangle(sprite.Hitbox.Left, sprite.Hitbox.Top, sprite.Hitbox.Width, sprite.Hitbox.Height),
                    0, 0, sprite.Hitbox.Width, sprite.Hitbox.Height, GraphicsUnit.Pixel, attrs);
            }

            if (drawBottomCap) {
                var sprite = sprites.LoadTile(tile.SpriteSet, tile.SpriteTile, tile.SpritePalette, 30);
                canvas.DrawImage(sprite.Image,
                    new Rectangle(sprite.Hitbox.Left, sprite.Hitbox.Top + length, sprite.Hitbox.Width, sprite.Hitbox.Height),
                    0, 0, sprite.Hitbox.Width, sprite.Hitbox.Height, GraphicsUnit.Pixel, attrs);
            }

            canvas.ResetTransform();
        }
Пример #2
0
        private void DrawTileTopEdge(Graphics canvas, Tile tile, TileShape shape, ImageAttributes attrs)
        {
            var drawEdge = (tile.Edges & 1) != 0;
            var drawLeftCap = (tile.EndCaps & 1) != 0;
            var drawRightCap = (tile.EndCaps & 2) != 0;

            if (shape.Top == null) {
                Debug.Assert(!drawEdge && !drawLeftCap && !drawRightCap);
                return;
            }

            var transform = new Matrix();
            transform.Translate(tile.X * App.PixelsPerTile + shape.Top.X1 + sliceOverdraw, tile.Y * App.PixelsPerTile + shape.Top.Y1 + sliceOverdraw);
            transform.Rotate(shape.Top.Angle);
            canvas.Transform = transform;
            var length = shape.Top.Length;

            if (drawEdge) {
                var sprite = sprites.LoadTile(tile.SpriteSet, tile.SpriteTile, tile.SpritePalette, 17 + (tile.X / 2) % 3);
                var sx = (tile.X & 1) * 48;
                canvas.DrawImage(sprite.Image,
                    new Rectangle(0, sprite.Hitbox.Top, length, sprite.Hitbox.Height),
                    sx - sprite.Hitbox.Left, 0, 48, sprite.Hitbox.Height, GraphicsUnit.Pixel, attrs);
            }

            if (drawLeftCap) {
                var sprite = sprites.LoadTile(tile.SpriteSet, tile.SpriteTile, tile.SpritePalette, 16);
                canvas.DrawImage(sprite.Image,
                    new Rectangle(sprite.Hitbox.Left, sprite.Hitbox.Top, sprite.Hitbox.Width, sprite.Hitbox.Height),
                    0, 0, sprite.Hitbox.Width, sprite.Hitbox.Height, GraphicsUnit.Pixel, attrs);
            }

            if (drawRightCap) {
                var sprite = sprites.LoadTile(tile.SpriteSet, tile.SpriteTile, tile.SpritePalette, 20);
                canvas.DrawImage(sprite.Image,
                    new Rectangle(sprite.Hitbox.Left + length, sprite.Hitbox.Top, sprite.Hitbox.Width, sprite.Hitbox.Height),
                    0, 0, sprite.Hitbox.Width, sprite.Hitbox.Height, GraphicsUnit.Pixel, attrs);
            }

            canvas.ResetTransform();
        }
Пример #3
0
        private void DrawTileCenter(Graphics canvas, Tile tile, TileShape shape, ImageAttributes attrs)
        {
            var transform = new Matrix();
            transform.Translate(tile.X * App.PixelsPerTile + sliceOverdraw, tile.Y * App.PixelsPerTile + sliceOverdraw);
            canvas.Transform = transform;

            canvas.SetClip(new GraphicsPath(shape.Clip, shape.Clip.Select(p => (byte) 1).ToArray()));

            var chunk = (tile.X / 2) % 5 + ((tile.Y / 2) % 3) * 5 + 1;
            var sprite = sprites.LoadTile(tile.SpriteSet, tile.SpriteTile, tile.SpritePalette, chunk);
            var sx = (tile.X & 1) * 48;
            var sy = (tile.Y & 1) * 48;
            canvas.DrawImage(sprite.Image,
                new Rectangle(0, 0, 48, 48),
                sx - sprite.Hitbox.Left, sy - sprite.Hitbox.Top, 48, 48, GraphicsUnit.Pixel, attrs);

            canvas.ResetClip();
            canvas.ResetTransform();
        }