예제 #1
0
        public override void Update(CanvasContext2D context)
        {
            context.Save();
            context.BeginPath();
            context.Rect(0, 0, 800, 320);
            context.ClosePath();
            context.Clip();

            float speed = -(_level.Curve * _level.Speed * 50);

            if (_level.Left && _level.Speed > 0)
            {
                speed += 1;
            }
            if (_level.Right && _level.Speed > 0)
            {
                speed -= 1;
            }

            UpdateExplosions(context, speed);

            UpdateFlak(context, speed);

            foreach (Cloud cloud in _clouds)
            {
                float scale = (400 - cloud.Y) / 400;

                cloud.X = (cloud.X - (0.3f - speed) * scale + 2400) % 2400;

                context.DrawImage(
                    _cloudImage,
                    cloud.X - 1200,
                    cloud.Y - (_cloudImage.NaturalHeight / 2) * scale,
                    _cloudImage.NaturalWidth * scale,
                    _cloudImage.NaturalHeight * scale);
            }
            context.Restore();
        }
예제 #2
0
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            if (!Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2))
            {
                return(false);
            }

            //double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            //Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), ExpansionInPixels);

            //Vector2d expandedS0 = MiterPoint(x0, y0, x1, y1, x2, y2);
            //Vector2d expandedS1 = MiterPoint(x1, y1, x0, y0, x2, y2);
            //Vector2d expandedS2 = MiterPoint(x2, y2, x1, y1, x0, y0);
            MiterPointOut(expandedS0, x0, y0, x1, y1, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS1, x1, y1, x0, y0, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS2, x2, y2, x1, y1, x0, y0, ExpansionInPixels);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            if (RenderingOn)
            {
                ctx.BeginPath();
                ctx.MoveTo(x0, y0);
                ctx.LineTo(x1, y1);
                ctx.LineTo(x2, y2);
                ctx.ClosePath();
                ctx.Clip();
            }
            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;
            //if (denom == 0)
            //{
            //    ctx.Restore();
            //    return false;
            //}
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            if (RenderingOn)
            {
                ctx.Alpha = Opacity;

                if (lighting < 1.0)
                {
                    ctx.Alpha     = 1;
                    ctx.FillStyle = "Black";
                    ctx.FillRect(0, 0, Width, Height);
                    ctx.Alpha = lighting * Opacity;
                }

                ctx.DrawImage(im, 0, 0);
            }



            ctx.Restore();
            return(true);
        }
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            bool inside;

            if (factor == 1.0)
            {
                inside = Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2);
            }
            else
            {
                hw     = Width / 2;
                qw     = hw * factor;
                hh     = Height / 2;
                qh     = hh * factor;
                inside = Intersects(hw - qw, hw + qw, hh - qh, hh + qh, x0, y0, x1, y1, x2, y2);
            }

            if (!inside)
            {
                return(false);
            }

            double   edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), edgeOffset);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            ctx.BeginPath();
            ctx.MoveTo(x0, y0);
            ctx.LineTo(x1, y1);
            ctx.LineTo(x2, y2);
            ctx.ClosePath();
            ctx.Clip();

            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;

            if (denom == 0)
            {
                ctx.Restore();
                return(false);
            }
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            ctx.DrawImage(im, 0, 0);

            ctx.Restore();

            if (factor != 1.0)
            {
                ctx.BeginPath();
                ctx.MoveTo(hw - qw, hh - qh);
                ctx.LineTo(hw + qw, hh - qh);
                ctx.LineTo(hw + qw, hh + qh);
                ctx.LineTo(hw - qw, hh + qh);
                ctx.ClosePath();
                ctx.StrokeStyle = "yellow";
                ctx.Stroke();
            }

            return(true);
        }