Exemple #1
0
        public UIManager(SonicManager sonicManager, CanvasRenderingContext2D mainCanvas)
        {
            Instance = this;
            mainCanvas.Font = TextFont;
            UIAreas = new List<UIArea>();

            this.sonicManager = sonicManager;
            this.mainCanvas = mainCanvas;
            dragger = new Dragger((xsp, ysp) => {
                                      sonicManager.WindowLocation.X += (int) xsp;
                                      sonicManager.WindowLocation.Y += (int) ysp;

                                      sonicManager.BigWindowLocation.X = sonicManager.WindowLocation.X;
                                      sonicManager.BigWindowLocation.Y = sonicManager.WindowLocation.Y;
                                  });

            UIManagerAreas = new UIManagerAreas();

//            new LevelSelectorArea(this);
            new ColorEditorArea(this);
//            new ObjectFrameworkArea(this);
//            new ObjectFrameworkListArea(this);
            var l = new LevelManagerArea(this);
            l.LevelManager.Visible = false;
            sonicManager.OnLevelLoad += (level) => {
                l.LevelManager.Visible = true;
                                          
//                                            new TileChunkArea(this);
                                        };
        }
Exemple #2
0
        public void DrawBase(CanvasRenderingContext2D canvas,
                 Point position,
                 ChunkLayer layer,
                 bool xFlip,
                 bool yFlip)
        {
            var drawOrderIndex = 0;
            drawOrderIndex = xFlip ? (yFlip ? 0 : 1) : (yFlip ? 2 : 3);

            int tilePieceLength = 8;

            var ac = CanvasInformation.Create(tilePieceLength * 2, tilePieceLength * 2, false);
            var i = 0;

            var localPoint = new Point(0, 0);
            foreach (TileInfo tileItem in Tiles.Array())
            {
                var tile = tileItem.GetTile();
                if (tile.Truthy())
                {
                    if (tileItem.Priority == ((int)layer == 1))
                    {
                        var _xf = xFlip ^ tileItem.XFlip;
                        var _yf = yFlip ^ tileItem.YFlip;
                        var df = DrawInfo[DrawOrder[drawOrderIndex][i]];
                        localPoint.X = df[0] * tilePieceLength;
                        localPoint.Y = df[1] * tilePieceLength;
                        tile.DrawBase(ac.Context, localPoint, _xf, _yf, tileItem.Palette);
                    }
                }
                i++;
            }
            canvas.DrawImage(ac.Canvas, position.X, position.Y);
              
        }
Exemple #3
0
        public override void Draw(CanvasRenderingContext2D canv)
        {
            if (!Visible) return;
            UpdatePosition(TotalX, TotalY);

            base.Draw(canv);
        }
       public Bitmap(int w, int h)
       {
           width = w;
           height = h;

           canvas = (CanvasElement) Document.GetElementById("canvas");
           context = (CanvasRenderingContext2D) canvas.GetContext(CanvasContextId.Render2D); // "2d"    
           context.GlobalCompositeOperation = CompositeOperation.Copy;  // ### it was: CompositeOperation         
           imagedata = context.CreateImageData(w,1);  // w,h
       }
Exemple #5
0
        public void DrawBase(CanvasRenderingContext2D canvas, Point pos, bool xflip, bool yflip, int palette, bool isAnimatedTile = false)
        {

            //we dont predraw animated tiles
            if (AnimatedTileIndexes != null && (!isAnimatedTile && AnimatedTileIndexes.Count > 0)) return;

            var baseCacheIndex = getBaseCacheIndex(xflip, yflip, palette);

            CanvasInformation baseCache = baseCaches[baseCacheIndex];

            if (baseCache == null)
            {

                var squareSize = Colors.Length;
                CanvasInformation j;
                j = CanvasInformation.Create(squareSize, squareSize, false);

                if (pos.X < 0 || pos.Y < 0)
                    return;
                var oPos = new Point(0, 0);
                if (xflip)
                {
                    oPos.X = -squareSize;
                    j.Context.Scale(-1, 1);
                }
                if (yflip)
                {
                    oPos.Y = -squareSize;
                    j.Context.Scale(1, -1);
                }
                var palette_ = SonicManager.Instance.SonicLevel.Palette;

                int colorPaletteIndex = (palette + SonicManager.Instance.IndexedPalette) % palette_.Length;
                var x = oPos.X;
                var y = oPos.Y;

                for (int _x = 0; _x < squareSize; _x++)
                {
                    for (int _y = 0; _y < squareSize; _y++)
                    {
                        var colorIndex = Colors[_x][_y];
                        if (colorIndex == 0) continue;

                        j.Context.FillStyle = palette_[colorPaletteIndex][colorIndex];
                        j.Context.FillRect(x + _x, y + _y,1,1);
                    }
                }
                baseCaches[baseCacheIndex] = baseCache = j;
            }


            canvas.DrawImage(baseCache.Canvas, pos.X, pos.Y);


        }
        public override void Draw(CanvasRenderingContext2D canv)
        {
            base.Draw(canv);

            if (!Visible) return;
            if (Palette == null) return;

            canv.Save();

            canv.StrokeStyle = "#000";
            canv.LineWidth = 2;
            var pos = new Point(TotalX, TotalY);
            var f = (int)Math.Round(Palette.Length / 2.0);

            if (Wide) {
                for (var h = 0; h < 2; h++) {
                    for (var w = 0; w < f; w++) {
                        canv.FillStyle = Palette[w + h * f];
                        canv.FillRect(pos.X + w * Scale.X, pos.Y + h * Scale.Y, Scale.X, Scale.Y);
                        canv.StrokeRect(pos.X + w * Scale.X, pos.Y + h * Scale.Y, Scale.X, Scale.Y);
                    }
                }
                if (ShowCurrent) {
                    canv.FillStyle = Palette[SelectedIndex];
                    canv.FillRect(pos.X + f * Scale.X , pos.Y, Scale.X * 2, Scale.Y * 2);
                    canv.StrokeRect(pos.X + f * Scale.X , pos.Y, Scale.X * 2, Scale.Y * 2);
                }
            } else {
                for (var h = 0; h < f; h++) {
                    for (var w = 0; w < 2; w++) {
                        canv.FillStyle = Palette[w + h * 2];
                        canv.FillRect(pos.X + w * Scale.X, pos.Y + h * Scale.Y, Scale.X, Scale.Y);
                        canv.StrokeRect(pos.X + w * Scale.X, pos.Y + h * Scale.Y, Scale.X, Scale.Y);
                    }
                }
                if (ShowCurrent) {
                    canv.FillStyle = Palette[SelectedIndex];
                    canv.FillRect(pos.X, pos.Y + f * Scale.Y , Scale.X * 2, Scale.Y * 2);
                    canv.StrokeRect(pos.X, pos.Y + f * Scale.Y , Scale.X * 2, Scale.Y * 2);
                }
            }

            canv.Restore();
        }
Exemple #7
0
        public override void Draw(CanvasRenderingContext2D canv)
        {
            if (!Visible) return;
            string txt = Text;

            if (canv.Font != Font)
                canv.Font = Font;

            //var w = canv.MeasureText(txt).Width;
            //var h = int.Parse(canv.Font.Split("pt")[0]);

            //   canv.fillStyle = "rgba(255,255,255,0.78)";
            // var pad = 3;
            //     canv.fillRect(this.parent.x + this.x - pad, this.parent.y + this.y - h - pad, w + (pad * 2), h + (pad * 2));

            canv.FillStyle = Color;

            canv.FillText(txt, TotalX, TotalY);
        }
Exemple #8
0
        public void Draw(CanvasRenderingContext2D canvas, Point pos)
        {
            if (Active) {
                Ysp += 0.09375;
                X += (int) Xsp;
                Y += (int) Ysp;

                var wl = SonicManager.Instance.WindowLocation;
                if (X < wl.X || Y < wl.Y || X > wl.X + wl.Width || Y > wl.Y + wl.Height) {
                    TickCount = 0xfffffff;
                    return;
                }
                /*       if (SonicManager.Instance.SonicToon.CheckCollisionLine((this.X) + 8, (this.Y) + 8, 16, 1) != -1)
                {
                this.Ysp *= -0.75;
            }

            if (SonicManager.Instance.SonicToon.CheckCollisionLine((this.X) - 8, (this.Y) + 8, 26, 0) != -1) {
                this.Xsp *= -0.75;
            } */

                if (SonicManager.Instance.DrawTickCount > SonicManager.Instance.SonicToon.sonicLastHitTick + 64 &&
                    IntersectingRectangle.IntersectsRect(SonicManager.Instance.SonicToon.myRec,
                                                         new Rectangle(X - 8, Y - 8, 8 * 2, 2 * 8))) {
                    TickCount = 0xfffffff;
                    SonicManager.Instance.SonicToon.Rings++;
                    return;
                }

                TickCount++;
            }
            if (SonicManager.Instance.CurrentGameState == GameState.Playing)
                AnimationIndex = ( SonicManager.Instance.DrawTickCount % ( ( Active ? 4 : 8 ) * 4 ) ) / ( Active ? 4 : 8 );
            else AnimationIndex = 0;
            List<CanvasInformation> sprites = null;
            if (SonicManager.Instance.SpriteCache.Rings.Truthy())
                sprites = SonicManager.Instance.SpriteCache.Rings;
            else throw new Exception("bad ring animation");
            var sps = sprites[AnimationIndex];

            canvas.DrawImage(sps.Canvas, ( pos.X - 8 ), ( pos.Y - 8 ));
        }
Exemple #9
0
        private static void start()
        {
            canvas = (CanvasElement)Document.GetElementById("canvas");
            context = (CanvasRenderingContext2D)canvas.GetContext(CanvasContextId.Render2D);

            Offset = new Vector2(0, 0);

            Vector2 draggingPos = null;
            canvas.OnMousedown = @event =>
            {
                int mouseX = ((dynamic)@event).pageX;
                int mouseY = ((dynamic)@event).pageY;
                draggingPos = new Vector2(mouseX, mouseY);
            };
            canvas.OnMouseup = @event =>
            {
                /*
                                if (draggingPos == null) return;

                                int mouseX = ((dynamic)@event).pageX;
                                int mouseY = ((dynamic)@event).pageY;

                                draggingPos = new Vector2(draggingPos.X - mouseX, draggingPos.Y - mouseY);

                                Offset = new Vector2(Offset.X + draggingPos.X, Offset.Y + draggingPos.Y);
                                draw();


                */
                draggingPos = null;
            };
            Document.OnMousemove = @event =>
            {
                if (draggingPos == null) return;

                int mouseX = ((dynamic)@event).pageX;
                int mouseY = ((dynamic)@event).pageY;

                Offset = new Vector2(Offset.X + (draggingPos.X - mouseX) * 6, Offset.Y + (draggingPos.Y - mouseY) * 6);

                draggingPos = new Vector2(mouseX, mouseY);
                Draw();
            };



            canvas.Width = Document.Body.ClientWidth - 100;
            canvas.Height = Document.Body.ClientHeight - 100;
            context.Save();
            context.Font = "50px Arial";
            context.FillText("Loading...", canvas.Width / 2, canvas.Height / 2);
            context.Restore();


            Window.OnKeydown = @event =>
            {
                if (((dynamic)@event).keyCode == 17)
                {
                    drawLines = !drawLines;
                }
                Draw();
            };


        
             


            Window.SetTimeout(() =>
            {
                Console.WriteLine("Started");
                Console.Profile();

                Stopwatch sw = new Stopwatch();
                sw.Start();
                tree = new RTree<Player>();
                players = new List<Player>();
                for (int j = 0; j < numberOfPlayers; j++)
                {
                    var player = new Player(nextId());
                    player.X = rand.Next(0, gameSize);
                    player.Y = rand.Next(0, gameSize);
                    players.Add(player);
                    tree.Add(new Rectangle(player.X, player.Y), player);
                }

                buildClusters(viewRadius);

                sw.Stop();
                Console.ProfileEnd();
                Console.WriteLine(string.Format("Time {0}", sw.ElapsedMilliseconds));
                Console.WriteLine("Done");
                Draw();
            });
        }
        public override void Draw(CanvasRenderingContext2D canv)
        {
            base.Draw(canv);

            if (!Visible) return;
            if (Editor == null) return;
            var pos = new Point(TotalX, y: TotalY);

            Editor.Draw(canv, pos, new Point(Width, Height), ShowCollideMap, ShowHurtMap);
        }
Exemple #11
0
 public CanvasInformation(CanvasRenderingContext2D context, jQueryObject domCanvas)
 {
     Context = context;
     DomCanvas = domCanvas;
     Canvas = (CanvasElement) domCanvas[0];
 }
 private void drawAnimations(CanvasRenderingContext2D canvas)
 {
     foreach (AnimationInstance ano in AnimationInstances)
     {
         ano.Draw(canvas, -WindowLocation.X, -WindowLocation.Y);
     }
 }
 private void drawObjects(CanvasRenderingContext2D canvas, Point localPoint)
 {
     List<LevelObjectInfo> levelObjectInfos = SonicLevel.Objects;
     foreach (LevelObjectInfo o in levelObjectInfos)
     {
         localPoint.X = Script.Reinterpret<int>(o.X);
         localPoint.Y = Script.Reinterpret<int>(o.Y);
         if (o.Dead || BigWindowLocation.Intersects(localPoint))
         {
             o.Draw(canvas,
                    ((localPoint.X - WindowLocation.X)),
                    ((localPoint.Y - WindowLocation.Y)),
                    ShowHeightMap);
         }
     }
 }
        public void Draw(CanvasRenderingContext2D canvas, Point pos, Point scale)
        {
//            PieceLayout.DrawUI(canvas, pos, ShowImages, SelectedPieceIndex, ZeroPosition, largeScale);
        }
Exemple #15
0
        public override void Draw(CanvasRenderingContext2D canv)
        {
            if (!Visible) return;

            canv.Save();

            canv.FillStyle = BackColor;

            var width = VisibleItems * ( ItemWidth + JWidth ) - 2;

            canv.FillStyle = BackColor;
            canv.LineWidth = 1;
            canv.StrokeStyle = "#333";
            Help.RoundRect(canv, TotalX, TotalY, VisibleItems * ( ItemWidth + JWidth ) + 2, ItemHeight + ScrollWidth + 6, 3, true, true);

            canv.FillStyle = "grey";
            canv.LineWidth = 1;
            canv.StrokeStyle = "#444";
            canv.FillRect(TotalX + 2, TotalY + ItemHeight + 6, VisibleItems * ( ItemWidth + JWidth ), ScrollWidth);

            canv.FillStyle = "FFDDFF";
            canv.LineWidth = 1;
            canv.StrokeStyle = "#FFDDFF";
            ScrollPosition = width * ScrollOffset / ( Controls.Count - VisibleItems );

            canv.FillRect(TotalX + ( ScrollPosition ) + 2, TotalY + ItemHeight + 6, 5, ScrollWidth - 2);

            var curX = 3;
            for (var i = ScrollOffset; i < Math.Min(Controls.Count, ScrollOffset + VisibleItems); i++) {
                Controls[i].Parent = this;
                Controls[i].X = curX;
                Controls[i].Y = 2;
                Controls[i].Height = ItemHeight;
                Controls[i].Width = ItemWidth;

                curX += ItemWidth + JWidth;
                Controls[i].Draw(canv);
            }

            canv.Restore();
            base.Draw(canv);
        }
        /* this.uploadImage = function (sprite) {
        this.width = sprite.width;
        this.height = sprite.height;
        this.offsetX = _H.floor(sprite.width / 2);
        this.offsetY = _H.floor(sprite.height / 2);

        var ca = _H.defaultCanvas(this.width, this.height);

        ca.context.drawImage(sprite, 0, 0);
        var imgd = ca.context.getImageData(0, 0, this.width, this.height);
        var pix = imgd.data;

        var palette = {};
        var paletteLength = 0;

        for (var x = 0; x < this.width; x++) {
            this.colorMap[x] = [];
            for (var y = 0; y < this.height; y++) {
                var pl = _H.colorFromData(pix, (x * 4) + y * this.width * 4);
                var ind = 0;
                if (palette[pl] != undefined) {
                    ind = palette[pl];
                } else {
                    ind = paletteLength;
                    palette[pl] = paletteLength;
                    paletteLength++;
                }
                this.colorMap[x][y] = ind;
            }
        }
        this.palette = [];
        var ind = 0;
        for (var p in palette) {
            this.palette[ind++] = p.replace("#", "");
        }

    };*/

        public void DrawSimple(CanvasRenderingContext2D mainCanvas, Point pos, int width, int height, bool xflip, bool yflip)
        {
            var c = GetCache(false, false, false);

            mainCanvas.Save();
            mainCanvas.Translate(pos.X, pos.Y);
            mainCanvas.Scale(((double)width / Width), ((double)height / Height));

            mainCanvas.DrawImage(c.Canvas, 0, 0);
            mainCanvas.Restore();
        }
 public void Draw(CanvasRenderingContext2D canvas, int i, int i1) {}
 private static void drawLoading(CanvasRenderingContext2D canvas)
 {
     canvas.FillStyle = "white";
     canvas.FillText("Loading...   " /*+ (this.inds.tc + this.inds.tp + this.inds.t) + " / " + (this.inds.total)*/, 95, 95);
     canvas.Restore();
     return;
 }
        private bool drawHaltMode(CanvasRenderingContext2D canvas)
        {
            canvas.FillStyle = "white";
            canvas.Font = "21pt arial bold";
            canvas.FillText("HALT MODE\r\n Press: P to step\r\n        O to resume", 10, 120);

            if (waitingForDrawContinue)
                return true;
            else
                waitingForDrawContinue = true;
            return false;
        }
        private void updatePositionsForPlaying(CanvasRenderingContext2D canvas)
        {
            canvas.Scale(RealScale.X, RealScale.Y);
            if (SonicToon.Ticking)
            {
                while (true)
                {
                    if (SonicToon.Ticking)
                        break;
                }
            }
            canvas.Translate(ScreenOffset.X, ScreenOffset.Y);
            //canvas.FillStyle = "#000000";
            //canvas.FillRect(0, 0, WindowLocation.Width * Scale.X, WindowLocation.Height * Scale.Y);

            WindowLocation.X = (int)(SonicToon.X) - WindowLocation.Width / 2;
            WindowLocation.Y = (int)(SonicToon.Y) - WindowLocation.Height / 2;

            BigWindowLocation.X = (int)(SonicToon.X) - BigWindowLocation.Width / 2;
            BigWindowLocation.Y = (int)(SonicToon.Y) - BigWindowLocation.Height / 2;

            BigWindowLocation.X = (int)(BigWindowLocation.X - WindowLocation.Width * 0.2);
            BigWindowLocation.Y = (int)(BigWindowLocation.Y - WindowLocation.Height * 0.2);

            BigWindowLocation.Width = (int)(WindowLocation.Width * 1.8);
            BigWindowLocation.Height = (int)(WindowLocation.Height * 1.8);


        }
        private void updatePositions(CanvasRenderingContext2D canvas)
        {
            ScreenOffset.X = 0;
            ScreenOffset.Y = 0;

            if (CurrentGameState == GameState.Playing) updatePositionsForPlaying(canvas);

            /*    if (WindowLocation.X < 0) WindowLocation.X = 0;
            if (WindowLocation.X > 128 * SonicLevel.LevelWidth - WindowLocation.Width)
                WindowLocation.X = 128 * SonicLevel.LevelWidth - WindowLocation.Width;*/
        }
 private void drawCanveses(CanvasRenderingContext2D canvas, Point localPoint)
 {
     canvas.Scale(Scale.X, Scale.Y);
     canvas.DrawImage(lowChunkCanvas.Canvas, localPoint.X, localPoint.Y);
     canvas.DrawImage(sonicCanvas.Canvas, localPoint.X, localPoint.Y);
     canvas.DrawImage(highChuckCanvas.Canvas, localPoint.X, localPoint.Y);
 }
Exemple #23
0
        public void Draw(CanvasRenderingContext2D canvas, Point pos, bool xflip, bool yflip, int solid, int angle)
        {
            if (Items == null) return;
            canvas.Save();

            var oPos = new Point(pos);
            if (xflip) {
                pos.X = -pos.X - 16;
                canvas.Scale(-1, 1);
            }
            if (yflip) {
                pos.Y = -pos.Y - 16;
                canvas.Scale(1, -1);
            }
            var fd = SonicManager.Instance.SpriteCache.HeightMaps[Index + ( solid << 20 )];
            if (Index != -1 && fd.Truthy())
                canvas.DrawImage(fd.Canvas, pos.X, pos.Y);
            else {
                var ntcanvas = CanvasInformation.Create(16, 16, false);
                var ncanvas = ntcanvas.Context;

                if (solid > 0) {
                    for (int x = 0; x < 16; x++) {
                        for (int y = 0; y < 16; y++) {
                            var jx = 0;
                            var jy = 0;
                            if (ItemsGood(Items, x, y)) {
                                jx = x;
                                jy = y;
                                var _x = jx;
                                var _y = jy;
                                ncanvas.LineWidth = 1;
                                ncanvas.FillStyle = colors[solid];
                                ncanvas.FillRect(_x, _y, 1, 1);
                                if (angle != 255) {
                                    ncanvas.BeginPath();
                                    ncanvas.LineWidth = 1;
                                    ncanvas.StrokeStyle = "rgba(163,241,255,0.8)";
                                    ncanvas.MoveTo(16 / 2, 16 / 2);
                                    ncanvas.LineTo(16 / 2 - Help.Sin(angle) * 8, 16 / 2 - Help.Cos(angle) * 8);
                                    ncanvas.Stroke();
                                    /*ncanvas.BeginPath();
                                    ncanvas.FillStyle = "rgba(163,241,255,0.8)";
                                    ncanvas.Arc(16 / 2 - Help.Sin(angle) * 8,16 / 2 - Help.Cos(angle) * 8,5,0,2 * Math.PI,true);
                                    ncanvas.Fill();*/
                                }
/*
                                canvas.LineWidth = 1;
                                canvas.StrokeStyle = "#000000";
                                canvas.StrokeRect(pos.X, pos.Y, scale.X * 16, scale.Y * 16);
*/
                            }
                        }
                    }
                }
                SonicManager.Instance.SpriteCache.HeightMaps[Index + ( solid << 20 )] = ntcanvas;

                canvas.DrawImage(ntcanvas.Canvas, pos.X, pos.Y);
            }
            canvas.Restore();
            pos.X = oPos.X;
            pos.Y = oPos.Y;
        }
        public void Draw(CanvasRenderingContext2D canvas, int x, int y, bool showHeightMap)
        {
            if (Dead || ObjectData.Falsey()) return;

            if (ObjectData.PieceLayouts.Count == 0) {
                canvas.DrawImage(ObjectManager.broken,
                                 ( x - ObjectManager.broken.Width / 2 ),
                                 ( y - ObjectManager.broken.Height / 2 ),
                                 ObjectManager.broken.Width,
                                 ObjectManager.broken.Height);
                return;
            }

            MainPieceLayout().Draw(canvas, x, y, ObjectData, this, showHeightMap);
            if (ConsoleLog != null) {
                var gr = GetRect();
                canvas.Save();
                canvas.FillStyle = "rgba(228,228,12,0.4)";
                var wd = 1;
                canvas.FillRect(gr.X - X + x - ( gr.Width / 2 ) - wd,
                                gr.Y - Y + y - ( gr.Height / 2 ) - wd,
                                gr.Width - ( gr.X - X ) + wd * 2,
                                gr.Height - ( gr.Y - Y ) + wd * 2);
                canvas.Restore();
            }
        }
        public void DrawUI(CanvasRenderingContext2D _canvas,
                           Point pos,
                           bool showOutline,
                           bool showCollideMap,
                           bool showHurtMap,
                           bool showOffset,
                           bool xflip,
                           bool yflip)
        {
            var fd = GetCache(showOutline, showCollideMap, showHurtMap);



            _canvas.Save();

            _canvas.Translate(pos.X, pos.Y);
            if (xflip)
            {
                if (yflip)
                {
                    _canvas.Translate(fd.Canvas.Width / 2d, fd.Canvas.Height / 2d);
                    _canvas.Rotate(-90 * Math.PI / 180);
                    _canvas.Translate(-fd.Canvas.Width / 2d, -fd.Canvas.Height / 2d);

                    _canvas.Translate(0, Height);
                    _canvas.Scale(1, -1);
                }
                else
                {
                    _canvas.Translate(fd.Canvas.Width / 2d, fd.Canvas.Height / 2d);
                    _canvas.Rotate(-90 * Math.PI / 180);
                    _canvas.Translate(-fd.Canvas.Width / 2d, -fd.Canvas.Height / 2d);
                }
            }
            else
            {
                if (yflip)
                {
                    _canvas.Translate(0, Height);
                    _canvas.Scale(1, -1);
                }
                else { }
            }
            _canvas.DrawImage(fd.Canvas, 0, 0);
            if (showOffset)
            {
                _canvas.BeginPath();
                _canvas.MoveTo(OffsetX, 0);
                _canvas.LineTo(OffsetX, Height);
                _canvas.LineWidth = 1;
                _canvas.StrokeStyle = "#000000";
                _canvas.Stroke();

                _canvas.BeginPath();
                _canvas.MoveTo(0, OffsetY);
                _canvas.LineTo(Width, OffsetY);
                _canvas.LineWidth = 1;
                _canvas.StrokeStyle = "#000000";
                _canvas.Stroke();
            }

            _canvas.Restore();
        }
        private void drawDebugTextChunks(CanvasRenderingContext2D canvas, int fxP, int fyP, Point[] offs, Point localPoint)
        {
            foreach (Point off in offs)
            {
                int _xP = fxP + off.X;
                int _yP = fyP + off.Y;
                int _xPreal = fxP + off.X;
                int _yPreal = fyP + off.Y;
                //if (_xP < 0 || _xP >= SonicLevel.LevelWidth) continue;
                _xP = Help.Mod(_xP, SonicLevel.LevelWidth);
                _yP = Help.Mod(_yP, SonicLevel.LevelHeight);
                TileChunk chunk = SonicLevel.GetChunkAt(_xP, _yP);
                if (chunk == null) continue;

                localPoint.X = (_xPreal * 128) - WindowLocation.X;
                localPoint.Y = (_yPreal * 128) - WindowLocation.Y;

                if (!chunk.IsEmpty() && !chunk.OnlyForeground())
                    chunk.DrawAnimationDebug(canvas, localPoint, ChunkLayer.Low, TileChunkDebugDrawOptions);

                if (!chunk.IsEmpty() && !chunk.OnlyBackground())
                    chunk.DrawAnimationDebug(canvas, localPoint, ChunkLayer.High, TileChunkDebugDrawOptions);
            }
        }
        public override void Draw(CanvasRenderingContext2D canv)
        {
            if (!Visible) return;
            if (PieceLayoutMaker == null) return;
            var pos = new Point(TotalX, TotalY);

            PieceLayoutMaker.Draw(canv, pos, Size);

            base.Draw(canv);
        }
        private void drawSonic(CanvasRenderingContext2D canvas)
        {
            if (CurrentGameState == GameState.Playing)
            {
                SonicToon.Draw(canvas);
                //if (WindowLocation.X < 0) WindowLocation.X = 0;

                //if (WindowLocation.X > 128 * SonicLevel.LevelWidth - WindowLocation.Width)
                //    WindowLocation.X = 128 * SonicLevel.LevelWidth - WindowLocation.Width;
                //if (WindowLocation.Y > 128 * SonicLevel.LevelHeight - WindowLocation.Height)
                //    WindowLocation.Y = 128 * SonicLevel.LevelHeight - WindowLocation.Height;
            }
        }
        private void drawHighChunks(CanvasRenderingContext2D canvas, int fxP, int fyP, Point[] offs, Point localPoint)
        {
            foreach (Point off in offs)
            {
                int _xP = fxP + off.X;
                int _yP = fyP + off.Y;
                int _xPreal = fxP + off.X;
                int _yPreal = fyP + off.Y;
                //if (_xP < 0 || _xP >= SonicLevel.LevelWidth) continue;
                _xP = Help.Mod(_xP, SonicLevel.LevelWidth);
                _yP = Help.Mod(_yP, SonicLevel.LevelHeight);
                TileChunk chunk = SonicLevel.GetChunkAt(_xP, _yP);
                if (chunk == null) continue;

                localPoint.X = (_xPreal * 128) - WindowLocation.X;
                localPoint.Y = (_yPreal * 128) - WindowLocation.Y;

                if (!chunk.IsEmpty() && !chunk.OnlyBackground())
                    chunk.Draw(canvas, localPoint, ChunkLayer.High);

                if (ShowHeightMap)
                {
                    var fd = SpriteCache.HeightMapChunks[(SonicLevel.CurHeightMap ? 1 : 2) + " " + chunk.Index];

                    if (fd == null)
                    {
                        fd = cacheHeightMapForChunk(chunk);
                    }
                    canvas.DrawImage(fd.Canvas, localPoint.X, localPoint.Y);
                }
                if (CurrentGameState == GameState.Editing)
                {
                    canvas.StrokeStyle = "#DD0033";
                    canvas.LineWidth = 3;
                    canvas.StrokeRect(localPoint.X, localPoint.Y, 128, 128);
                }
            }
        }
        private void drawRings(CanvasRenderingContext2D canvas, Point localPoint)
        {
            for (int index = 0; index < SonicLevel.Rings.Count; index++)
            {
                var r = SonicLevel.Rings[index];

                switch (CurrentGameState)
                {
                    case GameState.Playing:
                        if (!SonicToon.obtainedRing[index])
                        {
                            if (BigWindowLocation.Intersects(r))
                                GoodRing.Draw(canvas, r.Negate(WindowLocation.X, WindowLocation.Y));
                        }
                        break;
                    case GameState.Editing:
                        if (BigWindowLocation.Intersects(r))
                            GoodRing.Draw(canvas, r.Negate(WindowLocation.X, WindowLocation.Y));
                        break;
                }

                /*
                 for (var ring in this.SonicLevel.Rings) {
                        var r = this.SonicLevel.Rings[ring];
                        if (this.sonicToon) {
                            if (!this.sonicToon.obtainedRing[ring])
                                if (this.bigWindowLocation.intersects(r))
                                    this.goodRing.draw(canvas, { x: (r.x) - this.windowLocation.x, y: (r.y) - this.windowLocation.y }, scale, true);
                        } else {
                            if (this.bigWindowLocation.intersects(r))
                                this.goodRing.draw(canvas, { x: (r.x) - this.windowLocation.x, y: (r.y) - this.windowLocation.y }, scale, false);
                        }
                    }
                 */
            }

            switch (CurrentGameState)
            {
                case GameState.Playing:

                    for (int i = ActiveRings.Count - 1; i >= 0; i--)
                    {
                        Ring ac = ActiveRings[i];

                        localPoint.X = ac.X - WindowLocation.X;
                        localPoint.Y = ac.Y - WindowLocation.Y;
                        ac.Draw(canvas, localPoint);
                        if (ac.TickCount > 256)
                            ActiveRings.Remove(ac);
                    }
                    break;
                case GameState.Editing:
                    break;
            }
        }