Beispiel #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();
        }
Beispiel #2
0
 public DoublePoint Negate(DoublePoint windowLocation)
 {
     return new DoublePoint(X - windowLocation.X, Y - windowLocation.Y);
 }
Beispiel #3
0
 public DoublePoint(DoublePoint pos)
 {
     X = pos.X;
     Y = pos.Y;
 }
Beispiel #4
0
 public DoublePoint Offset(DoublePoint windowLocation)
 {
     return new DoublePoint(X + windowLocation.X, Y + windowLocation.Y);
 }
Beispiel #5
0
        public void resizeCanvas(bool resetOverride)
        {
            canvasWidth = jQuery.Window.GetWidth();
            canvasHeight = jQuery.Window.GetHeight();

            uiCanvas.DomCanvas.Attribute("width", canvasWidth.ToString());
            uiCanvas.DomCanvas.Attribute("height", canvasHeight.ToString());

            sonicManager.WindowLocation = Constants.DefaultWindowLocation(sonicManager.CurrentGameState,
                                                                          uiCanvas,
                                                                          sonicManager.Scale);

            var wide = new DoublePoint(( canvasWidth / 320d / sonicManager.Scale.X ), ( canvasHeight / 224d / sonicManager.Scale.Y ));
            var even = new DoublePoint(Math.Min(( canvasWidth / 320d / sonicManager.Scale.X ), ( canvasHeight / 224d / sonicManager.Scale.Y )), Math.Min(( canvasWidth / 320d / sonicManager.Scale.X ), ( canvasHeight / 224d / sonicManager.Scale.Y )));

            sonicManager.RealScale = !fullscreenMode
                                             ? new DoublePoint(1, 1)
                                             : ( WideScreen ? wide : even );

            if (resetOverride || sonicManager.overrideRealScale == null)
                sonicManager.overrideRealScale = new DoublePoint(sonicManager.RealScale);
            else sonicManager.RealScale = new DoublePoint(sonicManager.overrideRealScale);

            gameCanvas.DomCanvas.Attribute("width",
                                           ( sonicManager.WindowLocation.Width *
                                             ( sonicManager.CurrentGameState == GameState.Playing
                                                       ? sonicManager.Scale.X * sonicManager.RealScale.X
                                                       : 1 ) ).ToString());
            gameCanvas.DomCanvas.Attribute("height",
                                           ( sonicManager.WindowLocation.Height 
*
                                             ( sonicManager.CurrentGameState == GameState.Playing
                                                       ? sonicManager.Scale.Y * sonicManager.RealScale.Y
                                                       : 1 ) ).ToString());

            uiGoodWidth = canvasWidth;
            gameGoodWidth = (int) ( sonicManager.WindowLocation.Width * ( sonicManager.CurrentGameState == GameState.Playing ? sonicManager.Scale.X * sonicManager.RealScale.X : 1 ) );

            var screenOffset = sonicManager.CurrentGameState == GameState.Playing
                                       ? new DoublePoint(( ( canvasWidth / 2d -
                                                             sonicManager.WindowLocation.Width * sonicManager.Scale.X *
                                                             sonicManager.RealScale.X / 2 ) ),
                                                         ( canvasHeight / 2d -
                                                           sonicManager.WindowLocation.Height * sonicManager.Scale.Y *
                                                           sonicManager.RealScale.Y / 2 ))
                                       : new DoublePoint(0, 0);
            gameCanvas.DomCanvas.CSS("left", screenOffset.X.ToPx());
            gameCanvas.DomCanvas.CSS("top", screenOffset.Y.ToPx());
            sonicManager.DestroyCanvases();
            sonicManager.ResetCanvases();

        }