Exemplo n.º 1
0
        public SonicManager(SonicEngine engine, CanvasInformation gameCanvas, Action resize)
        {
            Instance = this;
            //            SonicToon = new Sonic();

            this.engine = engine;
            this.engine.canvasWidth = jQuery.Window.GetWidth();
            this.engine.canvasHeight = jQuery.Window.GetHeight();

            gameCanvas.DomCanvas[0].SetAttribute("width", this.engine.canvasWidth.ToString());
            gameCanvas.DomCanvas[0].SetAttribute("height", this.engine.canvasHeight.ToString());

            jQuery.GetJsonData<JsDictionary<string, SonicImage>>("Content/sprites/sonic.js", data => { sonicSprites = data; });

            objectManager = new ObjectManager(this);
            objectManager.Init();
            int scl = 2;
            Scale = new Point(scl, scl);
            RealScale = new DoublePoint(1, 1);
            mainCanvas = gameCanvas;

            WindowLocation = Constants.DefaultWindowLocation(GameState.Editing, mainCanvas, Scale);
            BigWindowLocation = Constants.DefaultWindowLocation(GameState.Editing, mainCanvas, Scale);
            BigWindowLocation.Width = (int)(BigWindowLocation.Width * 1.8);
            BigWindowLocation.Height = (int)(BigWindowLocation.Height * 1.8);

            TileAnimations = new List<TileAnimationData>();
            AnimationInstances = new List<AnimationInstance>();
            //jQuery.GetJson("Content/sprites/explosion.js", data => Animations.Add(new Animation("explosion", data)));

            ShowHeightMap = false;
            GoodRing = new Ring(false);
            ActiveRings = new List<Ring>();
            ForceResize = resize;
            Background = null;
            CurrentGameState = GameState.Editing;

            ScreenOffset = new Point(mainCanvas.DomCanvas.GetWidth() / 2 - WindowLocation.Width / 2,
                                     mainCanvas.DomCanvas.GetHeight() / 2 - WindowLocation.Height / 2);

            UIManager = new UIManager.UIManager(this, mainCanvas.Context); ;

            ClickState = ClickState.PlaceChunk;
            tickCount = 0;
            DrawTickCount = 0;
            InHaltMode = false;
            waitingForTickContinue = false;
            waitingForDrawContinue = false;
            TileChunkDebugDrawOptions = new TileChunkDebugDrawOptions();
        }
Exemplo n.º 2
0
        public void DrawAnimationDebug(CanvasRenderingContext2D canvas, Point position, ChunkLayer layer, TileChunkDebugDrawOptions debugDrawOptions )
        {
            if (debugDrawOptions == null) return;
            canvas.Save();
            canvas.FillStyle = "White";
            canvas.TextBaseline = TextBaseline.Top;
            {
                int yOffset = layer == ChunkLayer.Low ? 0 : 64;
                if (debugDrawOptions.ShowBaseData)
                {
                    canvas.FillText("Base", position.X + 0, position.Y + yOffset);
                }

                if (debugDrawOptions.ShowPaletteAnimationData)
                {
                    if (HasPixelAnimations())
                    {
                        var paletteAnimationCanvases = PaletteAnimationCanvasesCache[layer];
                        foreach (var paletteAnimationIndex in GetAllPaletteAnimationIndexes())
                        {
                            var paletteAnimationCanvasFrames = paletteAnimationCanvases[paletteAnimationIndex];
                            if (paletteAnimationCanvasFrames == null) continue;

                            var currentFrame = SonicManager.Instance.TilePaletteAnimationManager.GetCurrentFrame(paletteAnimationIndex);

                            canvas.FillText("Palette " + paletteAnimationIndex + "-" + currentFrame.FrameIndex, position.X + 25, position.Y + yOffset + (paletteAnimationIndex*13));
                        }
                    }
                }
                if (debugDrawOptions.ShowTileAnimationData)
                {
                    if (HasTileAnimations())
                    {
                        var tileAnimationCanvases = TileAnimationCanvasesCache[layer];
                        foreach (var tileAnimationIndex in GetAllTileAnimationIndexes())
                        {
                            var tileAnimationCanvasFrames = tileAnimationCanvases[tileAnimationIndex];
                            if (tileAnimationCanvasFrames == null) continue;

                            var currentFrame = SonicManager.Instance.TileAnimationManager.GetCurrentFrame(tileAnimationIndex);
                            canvas.FillText("Tile " + tileAnimationIndex + "-" + currentFrame.FrameIndex, position.X + 75, position.Y + yOffset + (tileAnimationIndex*13));
                        }
                    }
                }
            }
            if (debugDrawOptions.OutlineChunk)
            {
                canvas.StrokeStyle = "black";
                canvas.StrokeRect(position.X, position.Y, 128, 128);
            }

            if (debugDrawOptions.OutlineTiles)
            {
                canvas.StrokeStyle = "green";
                for (int x = 0; x < TileSideLength; x++)
                {
                    for (int y = 0; y < TileSideLength; y++)
                    {
                        canvas.StrokeRect(position.X + (x * TileSquareSize), position.Y + (y * TileSquareSize), TileSquareSize, TileSquareSize);
                    }
                }
            }
            if (debugDrawOptions.OutlineTilePieces)
            {
                canvas.StrokeStyle = "purple";
                for (int x = 0; x < TilePieceSideLength; x++)
                {
                    for (int y = 0; y < TilePieceSideLength; y++)
                    {
                        canvas.StrokeRect(position.X + (x * TilePiecesSquareSize), position.Y + (y * TilePiecesSquareSize), TilePiecesSquareSize, TilePiecesSquareSize);
                    }
                }
            }
            if (debugDrawOptions.OutlineTile != null)
            {
                /*
                                canvas.StrokeStyle = "yellow";
                                for (int x = 0; x < TileSideLength; x++)
                                {
                                    for (int y = 0; y < TileSideLength; y++)
                                    {
                                        var tilePieceInfo = this.GetTilePiece(x, y);
                                        if (tilePieceInfo == null) continue;
                                        var tilePiece = tilePieceInfo.GetTilePiece();
                                        if (tilePiece == null) continue;

                        

                                        if (tilePiece == debugDrawOptions.OutlineTilePiece)
                                        {
                                            canvas.StrokeRect(position.X + (x * TileSquareSize), position.Y + (y * TileSquareSize), TileSquareSize, TileSquareSize);
                                        }
                                    }
                                }
                */
            }
            
            if (debugDrawOptions.OutlineTilePiece != null)
            {
                canvas.StrokeStyle = "yellow";
                for (int x = 0; x < TilePieceSideLength; x++)
                {
                    for (int y = 0; y < TilePieceSideLength; y++)
                    {
                        var tilePieceInfo = this.GetTilePieceInfo(x, y,false);
                        if (tilePieceInfo == null) continue;
                        var tilePiece = tilePieceInfo.GetTilePiece();
                        if (tilePiece == null) continue;
                        if (tilePiece.Index == debugDrawOptions.OutlineTilePiece.Block)
                        {
                            canvas.StrokeRect(position.X + (x * TilePiecesSquareSize), position.Y + (y * TilePiecesSquareSize), TilePiecesSquareSize, TilePiecesSquareSize);
                        }
                    }
                }
            }
            canvas.Restore();
        }