ClosePath() public method

public ClosePath ( ) : void
return void
        public void DrawUI(CanvasRenderingContext2D canvas, bool showImages, int selectedPieceIndex, LevelObject levelObject)
        {
            canvas.Save();

            if (!showImages)
            {
                canvas.StrokeStyle = "#000000";
                canvas.LineWidth = 2;


                canvas.BeginPath();
                canvas.MoveTo(-1000, 0);
                canvas.LineTo(1000, 0);
                canvas.ClosePath();
                canvas.Stroke();

                canvas.BeginPath();
                canvas.MoveTo(0, -1000);
                canvas.LineTo(0, 1000);
                canvas.ClosePath();
                canvas.Stroke();
                for (var i = 1; i < Pieces.Count; i++)
                {
                    var j = Pieces[i];

                    canvas.BeginPath();
                    canvas.MoveTo(j.X, j.Y);
                    canvas.LineTo(Pieces[i - 1].X, Pieces[i - 1].Y);
                    canvas.Stroke();
                }
            }

            foreach (var levelObjectPieceLayoutPiece in Pieces)
            {
                if (showImages)
                {
                    LevelObjectPiece piece = levelObject.Pieces[levelObjectPieceLayoutPiece.PieceIndex];
                    var asset = levelObject.Assets[piece.AssetIndex];
                    if (asset.Frames.Count > 0)
                    {
                        var frm = asset.Frames[0];
                        frm.DrawUI(canvas,
                                   new Point(levelObjectPieceLayoutPiece.X - frm.OffsetX, levelObjectPieceLayoutPiece.Y - frm.OffsetY),
                                   false,
                                   false,
                                   false,
                                   false,
                                   piece.Xflip,
                                   piece.Yflip);
                    }
                }
                else
                {
                    CanvasGradient drawRadial;

                    drawRadial = SonicManager.Instance.mainCanvas.Context.CreateRadialGradient(0, 0, 0, 10, 10, 50);
                    drawRadial.AddColorStop(0, "white");
                    if (selectedPieceIndex == levelObjectPieceLayoutPiece.PieceIndex)
                        drawRadial.AddColorStop(1, "yellow");
                    else
                        drawRadial.AddColorStop(1, "red");

                    canvas.FillStyle = drawRadial;
                    canvas.BeginPath();
                    canvas.Arc(levelObjectPieceLayoutPiece.X, levelObjectPieceLayoutPiece.Y, 10, 0, Math.PI * 2, true);
                    canvas.ClosePath();
                    canvas.Fill();
                }

            }
            canvas.Restore();
        }
Ejemplo n.º 2
0
        public void Draw(CanvasRenderingContext2D canvas, Sonic character, SensorM sensorResult)
        {
            var x = Help.Floor(character.X) - SonicManager.Instance.WindowLocation.X;
            var y = Help.Floor(character.Y) - SonicManager.Instance.WindowLocation.Y;

            canvas.BeginPath();
            if (sensorResult.Truthy() && sensorResult.Chosen) {
                canvas.StrokeStyle = "#FFF76D";
                canvas.LineWidth = 4;
            } else {
                canvas.StrokeStyle = Color;
                canvas.LineWidth = 2;
            }
            switch (character.Mode) {
                case RotationMode.Floor:
                    canvas.MoveTo(( x + X1 ), ( y + Y1 ));
                    canvas.LineTo(( x + X2 ), ( y + Y2 ));
                    break;
                case RotationMode.LeftWall:
                    canvas.MoveTo(( x - Y1 ), ( y + X1 ));
                    canvas.LineTo(( x - Y2 ), ( y + X2 ));
                    break;
                case RotationMode.Ceiling:
                    canvas.MoveTo(( x - X1 ), ( y - Y1 ));
                    canvas.LineTo(( x - X2 ), ( y - Y2 ));
                    break;
                case RotationMode.RightWall:
                    canvas.MoveTo(( x + Y1 ), ( y - X1 ));
                    canvas.LineTo(( x + Y2 ), ( y - X2 ));
                    break;
            }

            canvas.ClosePath();
            canvas.Stroke();
        }
Ejemplo n.º 3
0
        public void Draw(CanvasRenderingContext2D canvas)
        {
            var fx = ( X );
            var fy = ( Y );

            if (Invulnerable()) return;
            var cur = SonicManager.Instance.SpriteCache.SonicSprites[SpriteState];
            if (cur == null) {}

            if (cur.Loaded()) {
                canvas.Save();
                var offset = GetOffsetFromImage();
                canvas.Translate(( fx - SonicManager.Instance.WindowLocation.X + offset.X ),
                                 ( ( fy - SonicManager.Instance.WindowLocation.Y + offset.Y ) ));
                if (SonicManager.Instance.ShowHeightMap) {
                    canvas.Save();
                    var mul = 6;
                    var xj = Xsp * mul;
                    var yj = Ysp * mul;
                    canvas.BeginPath();
                    canvas.MoveTo(0, 0);
                    canvas.LineTo(xj, yj);
                    canvas.FillStyle = "rgba(163,241,255,0.8)";
                    canvas.Arc(xj, yj, 5, 0, 2 * Math.PI, true);
                    canvas.ClosePath();

                    canvas.LineWidth = 6;
                    canvas.StrokeStyle = "white"; //6C6CFC
                    canvas.Stroke();
                    canvas.LineWidth = 3;
                    canvas.StrokeStyle = "#2448D8"; //6C6CFC
                    canvas.Fill();
                    canvas.Stroke();
                    canvas.Restore();
                }

                if (!Facing) {
                    //canvas.translate(cur.width, 0);
                    canvas.Scale(-1, 1);
                    if (!CurrentlyBall && !SpinDash)
                        canvas.Rotate(-Help.FixAngle(Angle));

                    canvas.DrawImage(cur, -cur.Width / 2, -cur.Height / 2);

                    if (SpinDash) {
                        canvas.DrawImage(
                                SonicManager.Instance.SpriteCache.SonicSprites[
                                        ( "spinsmoke" + ( SonicManager.Instance.DrawTickCount % 14 ) / 2 )],
                                ( -cur.Width / 2 ) - 25,
                                -cur.Height / 2 + ( offset.Y ) - 14,
                                cur.Width,
                                cur.Height);
                    }
                } else {
                    if (!CurrentlyBall && !SpinDash)
                        canvas.Rotate(Help.FixAngle(Angle));
                    canvas.DrawImage(cur, -cur.Width / 2, -cur.Height / 2);

                    if (SpinDash) {
                        canvas.DrawImage(
                                SonicManager.Instance.SpriteCache.SonicSprites[
                                        ( "spinsmoke" + ( SonicManager.Instance.DrawTickCount % 14 ) / 2 )],
                                ( -cur.Width / 2 ) - 25,
                                -cur.Height / 2 + ( offset.Y ) - 14,
                                cur.Width,
                                cur.Height);
                    }
                }

                /*
               canvas.moveTo(-10 * scale.x, 4 * scale.y);
               canvas.lineTo(10 * scale.x, 4 * scale.y);
               canvas.lineWidth = 3;
               canvas.strokeStyle = "#FFF";
               canvas.stroke();

               canvas.moveTo(-9 * scale.x, 0 * scale.y);
               canvas.lineTo(-9 * scale.x, 20 * scale.y);
               canvas.lineWidth = 3;
               canvas.strokeStyle = "#FFF";
               canvas.stroke();

               canvas.moveTo(9 * scale.x, 0 * scale.y);
               canvas.lineTo(9 * scale.x, 20 * scale.y);
               canvas.lineWidth = 3;
               canvas.strokeStyle = "#FFF";
               canvas.stroke();*/

                /*
                canvas.strokeStyle = "#FFF";
                canvas.lineWidth = 4;
                canvas.strokeRect(-cur.width / 2, -cur.height / 2, cur.width, cur.height);
                */
                canvas.Restore();
                if (SonicManager.Instance.ShowHeightMap)
                    SensorManager.Draw(canvas, this);
                for (var i = 0; i < HaltSmoke.Count; i++) {
                    var lo = HaltSmoke[i];
                    canvas.DrawImage(
                            SonicManager.Instance.SpriteCache.SonicSprites[
                                    ( "haltsmoke" + ( SonicManager.Instance.DrawTickCount % ( 4 * 6 ) ) / 6 )],
                            ( ( lo.X - SonicManager.Instance.WindowLocation.X - 25 ) ),
                            ( ( lo.Y + 12 - SonicManager.Instance.WindowLocation.Y + offset.Y ) ));
                    if (( ( SonicManager.Instance.DrawTickCount + 6 ) % ( 4 * 6 ) ) / 6 == 0)
                        HaltSmoke = HaltSmoke.Extract(i, 1);
                }
            }
        }