コード例 #1
0
        void Game_NewDraw(object sender, DrawingArgs e)
        {
            Add2DWall(e);

            //Animate 2D Viewport

            double angle = 0;

            switch (e.Direction)
            {
            case Direction.Down:
                angle = 180;
                break;

            case Direction.Left:
                angle = 90;
                break;

            case Direction.Right:
                angle = 270;
                break;

            case Direction.Up:
                angle = 0;
                break;
            }

            double animatedAngle = canvasRotation.Angle;

            double tmp = Math.Floor(animatedAngle / 360);

            angle = angle + (tmp * 360);
            if (angle > animatedAngle)
            {
                if (Math.Abs(animatedAngle - angle) > 180)
                {
                    angle -= 360;
                }
            }
            else
            {
                if (Math.Abs(animatedAngle - angle) > 180)
                {
                    angle += 360;
                }
            }

            DoubleAnimation animRotation =
                new DoubleAnimation(angle, new Duration(new TimeSpan(0, 0, 0, 0, 300)));

            canvasRotation.ApplyAnimationClock(RotateTransform.AngleProperty, animRotation.CreateClock());

            //3D display

            AddWall(e);
        }
コード例 #2
0
        void Add2DWall(DrawingArgs e)
        {
            Line l = new Line();

            l.StrokeThickness = 2;

            switch (e.PlayerNumber)
            {
            case 0:
                l.Stroke = Brushes.BlueViolet;
                break;

            case 1:
                l.Stroke = Brushes.Navy;
                break;

            case 2:
                l.Stroke = Brushes.BlueViolet;
                break;

            case 3:
                l.Stroke = Brushes.BlueViolet;
                break;
            }

            l.X1 = e.From.X * gridSpace;
            l.Y1 = e.From.Y * gridSpace;

            //l.X2 = e.To.X * gridWidth;
            //l.Y2 = e.To.Y * gridWidth;

            DoubleAnimation animX =
                new DoubleAnimation((e.From.X) * gridSpace, (e.To.X) * gridSpace, new Duration(new TimeSpan(0, 0, 0, 0, speed)));

            l.ApplyAnimationClock(Line.X2Property, animX.CreateClock());
            DoubleAnimation animY =
                new DoubleAnimation((e.From.Y) * gridSpace, (e.To.Y) * gridSpace, new Duration(new TimeSpan(0, 0, 0, 0, speed)));

            l.ApplyAnimationClock(Line.Y2Property, animY.CreateClock());

            canvas.Children.Add(l);
        }
コード例 #3
0
        private void AddWall(DrawingArgs e)
        {
            ModelVisual3D model = new ModelVisual3D();

            model.Content = Resources["wallModel" + e.PlayerNumber.ToString()] as Model3D;

            Transform3DGroup group = new Transform3DGroup();

            model.Transform = group;

            ScaleTransform3D scale = new ScaleTransform3D();

            if (e.From.X == e.To.X)
            {
                scale.ScaleX = 0.01;
            }
            else
            {
                scale.ScaleX = 0.02 * (Math.Abs(e.To.X - e.From.X)) + 0.01;
            }
            if (e.From.Y == e.To.Y)
            {
                scale.ScaleY = 0.01;
            }
            else
            {
                scale.ScaleY = 0.02 * (Math.Abs(e.To.Y - e.From.Y)) + 0.01;
            }
            scale.ScaleZ = 0.02;

            group.Children.Add(scale);
            RotateTransform3D rotate = new RotateTransform3D();

            group.Children.Add(rotate);
            TranslateTransform3D translate = new TranslateTransform3D();

            group.Children.Add(translate);
            double x = (e.To.X + e.From.X) / 2;
            double y = (e.To.Y + e.From.Y) / 2;

            translate.OffsetX = (x) * 0.02;
            translate.OffsetY = (y) * 0.02;

            if (Math.Abs(e.To.X - e.From.X) % 2 == 1)
            {
                translate.OffsetX += 0.01;
            }
            if (Math.Abs(e.To.Y - e.From.Y) % 2 == 1)
            {
                translate.OffsetY += 0.01;
            }

            translate.OffsetY = -translate.OffsetY;

            modelVisual3DRoot.Children.Add(model);

            //Camera animation

            if (e.PlayerNumber == 0)
            {
                AxisAngleRotation3D xRotation
                    = ((camera.Transform as Transform3DGroup).Children[0] as RotateTransform3D).Rotation as AxisAngleRotation3D;
                AxisAngleRotation3D rotation
                    = ((camera.Transform as Transform3DGroup).Children[1] as RotateTransform3D).Rotation as AxisAngleRotation3D;
                TranslateTransform3D translation
                    = (camera.Transform as Transform3DGroup).Children[2] as TranslateTransform3D;

                double offsetX = e.From.X * 0.02;
                double offsetY = e.From.Y * 0.02;

                double recul = 0.2;

                if (e.To.X != e.From.X)
                {
                    if (e.From.X < e.To.X)
                    {
                        offsetX -= recul;
                    }
                    else
                    {
                        offsetX += recul;
                    }
                }
                if (e.To.Y != e.From.Y)
                {
                    if (e.From.Y < e.To.Y)
                    {
                        offsetY -= recul;
                    }
                    else
                    {
                        offsetY += recul;
                    }
                }

                offsetY = -offsetY;

                ApplyDoubleAnimation(offsetX, new TimeSpan(0, 0, 0, 0, 300), translation, TranslateTransform3D.OffsetXProperty);
                ApplyDoubleAnimation(offsetY, new TimeSpan(0, 0, 0, 0, 300), translation, TranslateTransform3D.OffsetYProperty);
                ApplyDoubleAnimation(0.08, new TimeSpan(0, 0, 0, 0, 300), translation, TranslateTransform3D.OffsetZProperty);

                //camera.LookDirection = new Vector3D(-translate.OffsetX, -translate.OffsetY, 0);

                double angle = 0;

                switch (e.Direction)
                {
                case Direction.Down:
                    angle = 180;
                    break;

                case Direction.Left:
                    angle = 90;
                    break;

                case Direction.Right:
                    angle = 270;
                    break;

                case Direction.Up:
                    angle = 0;
                    break;
                }

                double animatedAngle = rotation.Angle;

                double tmp = Math.Floor(animatedAngle / 360);
                angle = angle + (tmp * 360);
                if (angle > animatedAngle)
                {
                    if (Math.Abs(animatedAngle - angle) > 180)
                    {
                        angle -= 360;
                    }
                }
                else
                {
                    if (Math.Abs(animatedAngle - angle) > 180)
                    {
                        angle += 360;
                    }
                }

                ApplyDoubleAnimation(-10, new TimeSpan(0, 0, 0, 0, 300), xRotation, AxisAngleRotation3D.AngleProperty);
                ApplyDoubleAnimation(angle, new TimeSpan(0, 0, 0, 0, 300), rotation, AxisAngleRotation3D.AngleProperty);
                //DoubleAnimation animRotation =
                //    new DoubleAnimation(angle, new Duration(new TimeSpan(0, 0, 0, 0, 300)));
                //rotation.ApplyAnimationClock(AxisAngleRotation3D.AngleProperty, animRotation.CreateClock());
            }
        }