Ejemplo n.º 1
0
        public void Animate()
        {
            //
            var stage = new Bitmap(this.Width * Piece.BLOCK_WIDTH, this.Height * Piece.BLOCK_WIDTH);
            var g     = Graphics.FromImage(stage);

            g.Clear(Color.White);

            for (var i = 0; i < this.Height; i++)
            {
                for (var j = 0; j < this.Width; j++)
                {
                    g.DrawRectangle(new Pen(Color.Silver), new Rectangle(j * Piece.BLOCK_WIDTH, i * Piece.BLOCK_WIDTH, Piece.BLOCK_WIDTH, Piece.BLOCK_WIDTH));
                }
            }

            foreach (var p1 in m_pieces)
            {
                //

                if (p1.GetHashCode() == ActivePiece.GetHashCode())
                {
                    continue;
                }

                g.DrawImage(p1.ToImage(), p1.X * Piece.BLOCK_WIDTH, p1.Y * Piece.BLOCK_WIDTH);
            }

            var ostage = new Bitmap(stage);

            var p = ActivePiece;

            var angle2 = p.Rotation;

            if (angle2 == 0)
            {
                angle2 = 360;
            }

            //p.Rotate(Direction.Left);
            p.Rotate(Direction.Right);
            p.Rotate(Direction.Right);
            p.Rotate(Direction.Right);

            var angle1 = p.Rotation;

            var img = p.ToImage();
            var dx  = p.X * Piece.BLOCK_WIDTH + p.Center.X * Piece.BLOCK_WIDTH + Piece.BLOCK_WIDTH / 2;
            var dy  = p.Y * Piece.BLOCK_WIDTH + p.Center.Y * Piece.BLOCK_WIDTH + Piece.BLOCK_WIDTH / 2;

            for (var i = 0; i <= angle2 - angle1; i++)
            {
                stage = new Bitmap(ostage);
                var g2 = Graphics.FromImage(stage);

                g2.ResetTransform();
                g2.TranslateTransform(-dx, -dy);
                g2.RotateTransform(i, System.Drawing.Drawing2D.MatrixOrder.Append);
                g2.TranslateTransform(dx, dy, System.Drawing.Drawing2D.MatrixOrder.Append);

                g2.DrawImage(img, p.X * Piece.BLOCK_WIDTH, p.Y * Piece.BLOCK_WIDTH);
                UpdateEvent(new UpdateEventArgs(stage));
                //System.Threading.Thread.Sleep(1);
            }
            p.Rotate(Direction.Right);
            Update();


            g.Dispose();
        }