public SonicEngine() { Instance = this; /*var pl = @""; Window.Instance.Me().Global.Console.Log(new Compressor().CompressText(pl));*/ gameCanvas = CanvasInformation.Create((CanvasElement) Document.GetElementById(gameCanvasName), 0, 0,true); uiCanvas = CanvasInformation.Create((CanvasElement)Document.GetElementById(uiCanvasName), 0, 0, true); //new SpeedTester(gameCanvas);return; canvasWidth = 0; canvasHeight = 0; bindInput(); fullscreenMode = true; Window.AddEventListener("resize", e => resizeCanvas(true)); jQuery.Document.Resize(e => resizeCanvas(true)); sonicManager = new SonicManager(this, gameCanvas, () => resizeCanvas(true)); sonicManager.IndexedPalette = 0; Window.SetInterval(sonicManager.Tick, 1000 / 60); Window.SetInterval(GameDraw, 1000 / 60); Window.SetInterval(UIDraw, 1000 / 10); resizeCanvas(true); }
public static IntersectingRectangle DefaultWindowLocation(GameState state, CanvasInformation canvas, Point scale) { switch (state) { case GameState.Playing: return new IntersectingRectangle(0, 0, 320, 224); case GameState.Editing: var x = 0; var y = 0; if (SonicManager.Instance.SonicLevel.Truthy() && SonicManager.Instance.SonicLevel.StartPositions.Truthy() && SonicManager.Instance.SonicLevel.StartPositions[0].Truthy()) { x = SonicManager.Instance.SonicLevel.StartPositions[0].X - 128 * scale.X; y = SonicManager.Instance.SonicLevel.StartPositions[0].Y - 128 * scale.Y; } return new IntersectingRectangle(x, y, Window.InnerWidth , Window.InnerHeight); } return null; }
public void SetCache(CanvasInformation image, bool showOutline, bool showCollideMap, bool showHurtMap) { Image[(((showOutline ? 1 : 0) + 2) * 7) ^ (((showCollideMap ? 1 : 0) + 2) * 89) ^ (((showHurtMap ? 1 : 0) + 2) * 79)] = image; }
public void DestroyCanvases() { lowChunkCanvas = null; sonicCanvas = null; highChuckCanvas = null; }
public void ResetCanvases() { lowChunkCanvas = lowChunkCanvas ?? CanvasInformation.Create(WindowLocation.Width, WindowLocation.Height, false); sonicCanvas = sonicCanvas ?? CanvasInformation.Create(WindowLocation.Width, WindowLocation.Height, true); highChuckCanvas = highChuckCanvas ?? CanvasInformation.Create(WindowLocation.Width, WindowLocation.Height, false); sonicCanvas.Context.ClearRect(0, 0, WindowLocation.Width, WindowLocation.Height); highChuckCanvas.Context.ClearRect(0, 0, WindowLocation.Width, WindowLocation.Height); lowChunkCanvas.Context.ClearRect(0, 0, WindowLocation.Width, WindowLocation.Height); }
public void MainDraw(CanvasInformation canvas) { var context = canvas.Context; if (InHaltMode) if (drawHaltMode(context)) return; engine.Clear(canvas); if (SonicLevel == null) return; context.Save(); var localPoint = new Point(0, 0); DrawTickCount++; if (SpriteLoader.Truthy() && !SpriteLoader.Tick() || Loading) { drawLoading(context); context.Restore(); return; } updatePositions(context); int w1 = WindowLocation.Width / 128 + 2; int h1 = WindowLocation.Height / 128 + 2; //cleaner with 2 padding on the widthheight if (CurrentGameState == GameState.Editing) { w1 += 1; h1 += 1; w1 /= Scale.X; h1 /= Scale.Y; } var offs = getOffs(w1, h1); TilePaletteAnimationManager.TickAnimatedPalettes(); TileAnimationManager.TickAnimatedTiles(); int fxP = (int)((WindowLocation.X) / 128.0); int fyP = (int)((WindowLocation.Y) / 128.0); ResetCanvases(); var zero = new Point(0, 0); if (Background.Truthy()) { int wOffset = WindowLocation.X; int bw = Background.Width; int movex = (wOffset / bw) * bw; localPoint.X = -WindowLocation.X + movex; localPoint.Y = -WindowLocation.Y / 4; Background.Draw(lowChunkCanvas.Context, localPoint, wOffset); localPoint.X = -WindowLocation.X + movex + Background.Width; localPoint.Y = -WindowLocation.Y / 4; Background.Draw(lowChunkCanvas.Context, localPoint, wOffset); } drawLowChunks(lowChunkCanvas.Context, zero, offs, fyP, fxP); if (ShowHeightMap) drawHighChunks(lowChunkCanvas.Context, fxP, fyP, offs, zero); drawObjects(sonicCanvas.Context, zero); drawAnimations(sonicCanvas.Context); drawRings(sonicCanvas.Context, zero); drawSonic(sonicCanvas.Context); //drawRings(canvas, zero); //editing^ if (!ShowHeightMap) drawHighChunks(highChuckCanvas.Context, fxP, fyP, offs, zero); drawDebugTextChunks(highChuckCanvas.Context, fxP, fyP, offs, zero); lowChunkCanvas.Context.OffsetPixelsForWater(); highChuckCanvas.Context.OffsetPixelsForWater(); drawCanveses(context, localPoint); context.Restore(); if (CurrentGameState == GameState.Playing) SonicToon.DrawUI(context, new Point(ScreenOffset.X, ScreenOffset.Y)); }
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(); }
public void Clear(CanvasInformation canv) { int w; if (canv == gameCanvas) w = gameGoodWidth; else w = uiGoodWidth; canv.DomCanvas[0].Me().width = w; gameCanvas.Context.Me().webkitImageSmoothingEnabled = false; gameCanvas.Context.Me().mozImageSmoothingEnabled = false; gameCanvas.Context.Me().imageSmoothingEnabled = false; }