private void DrawInputString(int x, int y) { var demo = (DemoReel)RB.Game; RB.CameraSet(new Vector2i(-x, -y)); int width = 612; int height = 32; RB.DrawRect(new Rect2i(0, 0, width, height), DemoUtil.IndexToRGB(25)); RB.DrawRectFill(new Rect2i(1, 1, width - 2, height - 2), DemoUtil.IndexToRGB(27)); RB.ClipSet(new Rect2i(x + 4, y + 4, width - 8, height - 2)); if (RB.Ticks % 30 < 15) { RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(23), RB.NO_ESCAPE_CODES, mInputString); } else { mInputString.Append('|'); RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(23), RB.NO_ESCAPE_CODES, mInputString); mInputString.Truncate(mInputString.Length - 1); } RB.CameraReset(); RB.ClipReset(); }
private void DrawTMX() { var demo = (DemoReel)RB.Game; int spriteFrame = (RB.Ticks % 40) > 20 ? 1 : 0; Rect2i clipRect = new Rect2i(0, 0, 0, 0); int cameraYOffset = 0; int cameraXOffset = 0; int cameraYRange = 16; if (mStyle == RB.PixelStyle.Wide) { clipRect = new Rect2i((RB.DisplaySize.width / 2) - 100, RB.DisplaySize.height - 220, 200, 200); } else if (mStyle == RB.PixelStyle.Tall) { clipRect = new Rect2i((RB.DisplaySize.width / 2) - 200, RB.DisplaySize.height - 110, 400, 100); cameraYOffset = 150; cameraXOffset = -120; cameraYRange = 8; } if (mMap != null) { int scrollPos = -(int)RB.Ticks % (mMapSize.width * RB.SpriteSize().width); Vector2i cameraPos = new Vector2i((int)((Mathf.Sin(RB.Ticks / 100.0f) * 420) + 450 + cameraXOffset), (int)((Mathf.Sin(RB.Ticks / 10.0f) * cameraYRange) + cameraYOffset)); RB.ClipSet(clipRect); RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22)); RB.CameraSet(cameraPos); RB.DrawMapLayer(0, new Vector2i(scrollPos, 0)); RB.DrawMapLayer(0, new Vector2i(scrollPos + (mMapSize.width * RB.SpriteSize().width), 0)); RB.DrawMapLayer(1); RB.DrawMapLayer(2); RB.DrawSprite(0 + spriteFrame, new Vector2i(13 * 16, 16 * 16)); RB.DrawSprite(RB.SpriteIndex(6, 10) + spriteFrame, new Vector2i(67 * 16, 14 * 16)); RB.CameraReset(); } else { RB.Print(new Vector2i(clipRect.x + 2, clipRect.y + 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map\nDemos/DemoReel/Tilemap.tmx in Unity"); } RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21)); RB.ClipReset(); mFormatStr.Set("@C// Use ").Append(mStyle == RB.PixelStyle.Wide ? "wide" : "tall").Append(" pixel format\n"); mFormatStr.Append("@Kpublic @MHardwareSettings @NQueryHardware() {\n"); mFormatStr.Append(" @Kvar @Nhw = @Knew @MHardwareSettings@N();\n"); mFormatStr.Append(" @Nhw.DisplaySize = @Knew @MVector2i@N(@L").Append(RB.DisplaySize.width).Append("@N, @L").Append(RB.DisplaySize.height).Append("@N);\n"); mFormatStr.Append(" @Nhw.PixelStyle = @KRetroBlit@N.@EPixelStyle@N.").Append(mStyle == RB.PixelStyle.Wide ? "Wide" : "Tall").Append(";\n"); mFormatStr.Append(" @Kreturn @Nhw;\n"); mFormatStr.Append("}"); RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
private void DrawTMX(int x, int y) { var demo = (DemoReel)RB.Game; Rect2i clipRect = new Rect2i(x + 16, y + 142, 310, 207); Vector2i cameraPos = new Vector2i((int)(Mathf.Sin(RB.Ticks / 100.0f) * 450) + 200, (int)Mathf.Sin(RB.Ticks / 10.0f) * 16); int spriteFrame = (RB.Ticks % 40) > 20 ? 1 : 0; if (mMap != null && mMap.status == RB.AssetStatus.Ready) { int scrollPos = -(int)RB.Ticks % (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width); RB.ClipSet(clipRect); RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22)); RB.CameraSet(cameraPos); RB.DrawMapLayer(1, new Vector2i(scrollPos, 0)); RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width), 0)); RB.DrawMapLayer(2); RB.DrawMapLayer(3); RB.DrawSprite(0 + spriteFrame, new Vector2i(13 * 16, 16 * 16)); RB.DrawSprite(RB.SpriteIndex(6, 10) + spriteFrame, new Vector2i(67 * 16, 14 * 16)); } else { RB.CameraReset(); RB.ClipReset(); RB.Print(new Vector2i(x + 18, y + 144), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } RB.CameraReset(); RB.ClipReset(); RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21)); mMap.Load("Demos/DemoReel/Tilemap"); mFormatStr.Set("@C// Load a map from a TMX file\n"); mFormatStr.Append("@NmyTMXMap.Load(@S\"Demos/Demo/Tilemap\"@N);\n"); mFormatStr.Append("@NmyTMXMap.LoadLayer(@S\"Clouds\"@N, @L1@N);\n"); mFormatStr.Append("@NmyTMXMap.LoadLayer(@S\"Decoration\"@N, @L2@N);\n"); mFormatStr.Append("@NmyTMXMap.LoadLayer(@S\"Terrain\"@N, @L3@N);\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N));\n"); mFormatStr.Append("@[email protected](@Knew@N @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N), @I22);\n"); mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L").Append(cameraPos.x).Append("@N, @L").Append(cameraPos.y).Append("@N));\n"); mFormatStr.Append("@Kint@N pos = @L").Append(-(int)RB.Ticks).Append("@N % (myMap.size.width * @[email protected]);\n"); mFormatStr.Append("@[email protected](@L1@N, @Knew @MVector2i@N(pos, @L0@N));\n"); mFormatStr.Append("@[email protected](@L1@N, @Knew @MVector2i@N(pos + (myMap.size.width * @[email protected])), @L0@N));\n"); mFormatStr.Append("@[email protected](@L2@N);\n"); mFormatStr.Append("@[email protected](@L3@N);\n"); mFormatStr.Append("@[email protected](@L").Append(0 + spriteFrame).Append("@N, @Knew@N @MVector2i@N(@L").Append(13 * 16).Append("@N, @L").Append(16 * 16).Append("@N));\n"); mFormatStr.Append("@[email protected](@L").Append(RB.SpriteIndex(6, 10) + spriteFrame).Append("@N, @Knew @MVector2i@N(@L").Append(67 * 16).Append("@N, @L").Append(14 * 16).Append("@N));\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N), @I21);\n"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
private void DrawTilemap(int x, int y) { var demo = (DemoReel)RB.Game; RB.Offscreen(spriteSheet1); RB.SpriteSheetSet(spriteSheet2); mWaveOffset = (int)((RB.Ticks / 2) % 16); mFishFrame = (int)((RB.Ticks / 6) % 32); RB.DrawCopy(new Rect2i(mWaveOffset, 0, RB.SpriteSheetGet().grid.cellSize), new Vector2i(48, 192)); RB.Clear(new Color32(0, 0, 0, 0), new Rect2i(80, 192, RB.SpriteSheetGet().grid.cellSize)); if (mFishFrame < 7) { RB.DrawCopy(new Rect2i(mFishFrame * RB.SpriteSheetGet().grid.cellSize.width, RB.SpriteSheetGet().grid.cellSize.height, RB.SpriteSheetGet().grid.cellSize), new Vector2i(80, 192)); } RB.Onscreen(); Rect2i clipRect = new Rect2i(x, y + (RB.DisplaySize.height / 2) - 8, 632, 180); if (mMap != null) { RB.ClipSet(clipRect); RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22)); RB.CameraSet(new Vector2i(0, 0)); RB.DrawMapLayer(2); RB.DrawMapLayer(3); RB.TintColorSet(Color.black); RB.AlphaSet(32); int scrollPos = -(int)RB.Ticks % (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width); RB.DrawMapLayer(1, new Vector2i(scrollPos + 8, 8)); RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width) + 8, 8)); RB.TintColorSet(Color.white); RB.AlphaSet(196); RB.DrawMapLayer(1, new Vector2i(scrollPos, 0)); RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width), 0)); RB.AlphaSet(255); RB.CameraReset(); RB.ClipReset(); RB.SpriteSheetSet(spriteSheet1); } else { RB.Print(new Vector2i(clipRect.x + 2, clipRect.y + 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/TilemapOcean.tmx in Unity"); } RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21)); }
/// <summary> /// Render the effect /// </summary> public override void Render() { var game = (RetroDungeoneerGame)RB.Game; var cameraPos = RB.CameraGet(); var portalClipRect = new Rect2i(mPortal.e.pos.x * game.assets.spriteSheet.grid.cellSize.width, mPortal.e.pos.y * game.assets.spriteSheet.grid.cellSize.height, game.assets.spriteSheet.grid.cellSize.width, game.assets.spriteSheet.grid.cellSize.height); portalClipRect.x -= cameraPos.x; portalClipRect.y -= cameraPos.y; float rise = Ease.Interpolate(Ease.Func.QuadOut, 0.0f, 1.0f, mRiseTime); var portalPos = new Vector2i(mPortal.e.pos.x * game.assets.spriteSheet.grid.cellSize.width, (mPortal.e.pos.y + (1.0f - rise)) * game.assets.spriteSheet.grid.cellSize.height); var portalCenter = new Vector2i(portalPos.x + (game.assets.spriteSheet.grid.cellSize.width / 2), (mPortal.e.pos.y * game.assets.spriteSheet.grid.cellSize.height) + game.assets.spriteSheet.grid.cellSize.height - 2); if (Random.Range(0, 10) == 0) { mShrinkLight = mShrinkLight == 0 ? 1 : 0; } var outerLightSize = new Vector2i((game.assets.spriteSheet.grid.cellSize.width * 2 * 0.8f) - mShrinkLight, (game.assets.spriteSheet.grid.cellSize.height * 0.8f) - mShrinkLight); var innerLightSize = new Vector2i((game.assets.spriteSheet.grid.cellSize.width * 2 * 0.5f) - mShrinkLight, (game.assets.spriteSheet.grid.cellSize.height * 0.5f) - mShrinkLight); outerLightSize *= rise; innerLightSize *= rise; RB.DrawEllipseFill(portalCenter, outerLightSize, new Color32(255, 255, 255, 32)); RB.DrawEllipseFill(portalCenter, innerLightSize, new Color32(255, 255, 255, 32)); if (mRiseTime != 1.0f) { Color32 color = new Color32(0x3c, 0xac, 0xd7, 255); RB.TintColorSet(color); RB.ClipSet(portalClipRect); RB.DrawSprite(S.PORTAL, portalPos); RB.ClipReset(); } }
/// <summary> /// Render /// </summary> public virtual void Render() { int frame = (int)((RB.Ticks % 24) / 8); // Draw frame RB.DrawCopy(new Rect2i(40 + (20 * frame), 20, mRect.width, mRect.height), mRect); RB.TintColorSet(mColorTint); // Draw color fill RB.DrawCopy(new Rect2i(99 + (20 * frame), 20, mRect.width, mRect.height), mRect); int scroll = (int)((RB.Ticks % 100) / 10); RB.ClipSet(mRect); RB.Print(new Rect2i((int)mPos.x, (int)mPos.y - 10 + scroll, mRect.width, mRect.height), Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mLabel); RB.Print(new Rect2i((int)mPos.x, (int)mPos.y + scroll, mRect.width, mRect.height), Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mLabel); RB.ClipReset(); RB.TintColorSet(Color.white); }
private void DrawSetTile(int x, int y) { var demo = (DemoReel)RB.Game; int flags = Random.Range(0, 2) == 0 ? 0 : RB.FLIP_V; Rect2i clipRect = new Rect2i(x + 16, y + 82, 250, 268); Vector2i cameraPos = new Vector2i((int)(Mathf.Sin(RB.Ticks / 50.0f) * 128) + 128, (int)(Mathf.Sin(RB.Ticks / 10.0f) * 16) + 16); string flagsStr = string.Empty; if (flags != 0) { flagsStr = ", @[email protected]_V"; } RB.MapSpriteSet(0, new Vector2i(Random.Range(0, 38), Random.Range(0, 26)), Random.Range(RB.SpriteIndex(0, 4), RB.SpriteIndex(4, 4)), Color.white, flags); RB.ClipSet(clipRect); RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22)); RB.CameraSet(cameraPos); RB.DrawMapLayer(0); RB.CameraReset(); RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21)); RB.ClipReset(); mFormatStr.Set("@C// Set specific tile at specific map layer, sprite flags\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew @MVector2i@N(@L").Append(Random.Range(0, 60)).Append("@N, @L").Append(Random.Range(0, 12)).Append("@N), @L").Append(Random.Range(RB.SpriteIndex(0, 4), RB.SpriteIndex(4, 4))).Append(", 0").Append(flagsStr).Append("@N);\n"); mFormatStr.Append("@[email protected](@Knew@N @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N));\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N),\n @I22);\n"); mFormatStr.Append("@[email protected](@Knew@N @MVector2i@N(@L").Append(cameraPos.x).Append("@N, @L").Append(cameraPos.y).Append("@N));\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N),\n"); mFormatStr.Append(" @I21);"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
private void DrawClip(int x, int y) { var demo = (DemoReel)RB.Game; int clipWidth = (int)((Mathf.Sin(RB.Ticks / 50.0f) * 64) + 64 + 4); int clipHeight = (int)((Mathf.Sin((RB.Ticks / 50.0f) + 1) * 64) + 64 + 4); Rect2i clipRect = new Rect2i(x + 150 - clipWidth + 8, y + 212 - clipHeight + 8, clipWidth * 2, clipHeight * 2); RB.ClipSet(clipRect); RB.DrawRectFill(new Rect2i(0, 0, 500, 500), DemoUtil.IndexToRGB(22)); for (int i = 0; i < 20; i++) { for (int j = 0; j < 8; j++) { int sx = (int)((Mathf.Sin((RB.Ticks / 100.0f) + (j * (Mathf.PI * 2 / 8)) + (RB.Ticks * 0.001f * i)) * i * 8) + 150 + x); int sy = (int)((Mathf.Cos((RB.Ticks / 100.0f) + (j * (Mathf.PI * 2 / 8)) + (RB.Ticks * 0.001f * i)) * i * 8) + 212 + y); RB.DrawSprite(3, new Vector2i(sx, sy)); } } RB.ClipReset(); mFormatStr.Set("@C// Set a clipping region\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N));\n"); mFormatStr.Append("@[email protected]@N(@Knew @MRect2i@N(@L0@N, @L0@N, @L500@N, @L500@N),\n"); mFormatStr.Append(" @I22);\n"); mFormatStr.Append("@Kfor @N(@Kint@N i = @L0@N; i < @L20@N; i++) {\n"); mFormatStr.Append(" @Kfor @N(@Kint@N j = @L0@N; j < @L8@N; j++) {\n"); mFormatStr.Append(" @[email protected](@L3@N, @Knew @MVector2i@N(\n"); mFormatStr.Append(" ((@Kint@N)(@[email protected](@L").Append(RB.Ticks / 100.0f, 2).Append("f@N + j * (@[email protected] * @L2@N / @L8@N) + (@L").Append(RB.Ticks * 0.001f, 3).Append("f@N * i)) * i * @L8@N)@N),\n"); mFormatStr.Append(" ((@Kint@N)(@[email protected](@L").Append(RB.Ticks / 100.0f, 2).Append("f@N + j * (@[email protected] * @L2@N / @L8@N) + (@L").Append(RB.Ticks * 0.001f, 3).Append("f@N * i)) * i * @L8@N)@N)));\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("}"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
private void DrawMouse(int x, int y) { var demo = (DemoReel)RB.Game; RB.CameraSet(new Vector2i(-x, -y)); int color1 = 4; int color2 = 3; int colorOutline = 0; RB.DrawEllipseFill(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(color1)); RB.DrawEllipseFill(new Vector2i(26, 54), new Vector2i(26, 20), DemoUtil.IndexToRGB(color1)); RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline)); RB.DrawEllipse(new Vector2i(26, 54), new Vector2i(26, 20), DemoUtil.IndexToRGB(colorOutline)); RB.DrawRect(new Rect2i(0, 15, 53, 54 - 15), DemoUtil.IndexToRGB(colorOutline)); RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(color1)); RB.DrawLine(new Vector2i(52 / 3, 2), new Vector2i(52 / 3, 30), DemoUtil.IndexToRGB(colorOutline)); RB.DrawLine(new Vector2i(52 / 3 * 2, 2), new Vector2i(52 / 3 * 2, 30), DemoUtil.IndexToRGB(colorOutline)); RB.DrawLine(new Vector2i(0, 30), new Vector2i(52, 30), DemoUtil.IndexToRGB(colorOutline)); if (RB.ButtonDown(RB.BTN_POINTER_A)) { RB.ClipSet(new Rect2i(-RB.CameraGet().x + 1, -RB.CameraGet().y, (52 / 3) - 1, 30)); RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5)); RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline)); RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5)); RB.ClipReset(); } if (RB.ButtonDown(RB.BTN_POINTER_B)) { RB.ClipSet(new Rect2i(-RB.CameraGet().x + 35, -RB.CameraGet().y, 52 / 3, 30)); RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5)); RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline)); RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5)); RB.ClipReset(); } if (RB.ButtonDown(RB.BTN_POINTER_C)) { RB.ClipSet(new Rect2i(-RB.CameraGet().x + 18, -RB.CameraGet().y, (52 / 3) - 1, 30)); RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5)); RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline)); RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5)); RB.ClipReset(); } if (RB.ButtonDown(RB.BTN_POINTER_A)) { RB.Print(new Vector2i(9, 16), DemoUtil.IndexToRGB(colorOutline), "A"); } else { RB.Print(new Vector2i(8, 15), DemoUtil.IndexToRGB(colorOutline), "A"); } if (RB.ButtonDown(RB.BTN_POINTER_C)) { RB.Print(new Vector2i(25, 16), DemoUtil.IndexToRGB(colorOutline), "C"); } else { RB.Print(new Vector2i(24, 15), DemoUtil.IndexToRGB(colorOutline), "C"); } if (RB.ButtonDown(RB.BTN_POINTER_B)) { RB.Print(new Vector2i(41, 16), DemoUtil.IndexToRGB(colorOutline), "B"); } else { RB.Print(new Vector2i(40, 15), DemoUtil.IndexToRGB(colorOutline), "B"); } RB.DrawRectFill(new Rect2i(23, 36, 8, 24), DemoUtil.IndexToRGB(color2)); int barSize = (int)(6 * mScrollDeltaAnim / 2.0f); barSize = Mathf.Clamp(barSize, -12, 12); if (barSize > 0) { RB.DrawRectFill(new Rect2i(23, 48 - barSize, 8, barSize), DemoUtil.IndexToRGB(5)); } else if (barSize < 0) { RB.DrawRectFill(new Rect2i(23, 48, 8, -barSize), DemoUtil.IndexToRGB(5)); } RB.DrawRect(new Rect2i(23, 36, 8, 24), DemoUtil.IndexToRGB(colorOutline)); RB.DrawLine(new Vector2i(24, 48), new Vector2i(29, 48), DemoUtil.IndexToRGB(colorOutline)); RB.CameraReset(); }
private void DrawAll(int x, int y) { var demo = (DemoReel)RB.Game; var gridColor = DemoUtil.IndexToRGB(14); RB.Offscreen(0); RB.SpriteSheetSet(1); mWaveOffset = (int)((RB.Ticks / 2) % 8); RB.DrawCopy(new Rect2i(mWaveOffset, 0, RB.SpriteSize()), new Vector2i(24, 8)); RB.Onscreen(); Rect2i clipRectOverlap = mClipRect; clipRectOverlap.width += 400; if (mMap != null) { RB.DrawRectFill(mClipRect, DemoUtil.IndexToRGB(22)); } RB.ClipSet(clipRectOverlap); DrawTilemap(mClipRect.x, mClipRect.y); RB.ClipReset(); RB.CameraReset(); // Blank out right side RB.AlphaSet(196); RB.DrawRectFill(new Rect2i(mClipRect.x + mClipRect.width, mClipRect.y, 300, mClipRect.height), DemoUtil.IndexToRGB(1)); RB.AlphaSet(255); // Blank out left side RB.DrawRectFill(new Rect2i(0, mClipRect.y, mClipRect.x - 1, mClipRect.height), DemoUtil.IndexToRGB(1)); RB.DrawRect(mClipRect, DemoUtil.IndexToRGB(7)); if (mMap == null) { return; } RB.AlphaSet(128); mFinalStr.Set("Chunk Tile Offset:"); RB.Print(new Vector2i(mClipRect.x, mClipRect.y - 16), gridColor, mFinalStr); RB.CameraSet(mChunkCameraPos - new Vector2i(mClipRect)); int gxStart = 0; int gxEnd = gxStart + (RB.DisplaySize.width * 2); for (int gx = gxStart; gx < gxEnd; gx += RB.MapChunkSize.width * RB.SpriteSize().x) { RB.DrawLine(new Vector2i(gx, -8), new Vector2i(gx, mClipRect.height + 4), gridColor); mFinalStr.Set(gx / RB.SpriteSize().x); RB.Print(new Vector2i(gx + 3, -8), gridColor, mFinalStr); } RB.AlphaSet(255); RB.CameraReset(); RB.SpriteSheetSet(0); }
/// <summary> /// Render /// </summary> public override void Render() { RB.Clear(new Color32(127, 213, 221, 255)); var game = (SuperFlagRun)RB.Game; if (game.GameMap == null) { RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load game TMX map.\nPlease try re-importing the map Demos/SuperFlagRun/GameMap.tmx in Unity"); return; } // Draw Player One view RB.CameraReset(); Vector2i cameraOffset; if (!game.SinglePlayer) { RB.ClipSet(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height / 2)); cameraOffset = GetCameraOffset(mPlayerOne); } else { cameraOffset = GetCameraOffset(mPlayerOne); cameraOffset.y -= RB.DisplaySize.height / 2; } RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_SKY); DrawScrollingClouds((int)cameraOffset.x, (int)cameraOffset.y); RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_BACKGROUND); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TERRAIN); if (mWinningPlayer == 0) { mFlagOneSlot.Render(); } mFlagOne.Render(); mFlagTwo.Render(); mPlayerTwo.Render(); mPlayerOne.Render(); // Draw Castles RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(16, RB.SpriteSheetGet().grid.cellSize.height * 26)); RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i((RB.SpriteSheetGet().grid.cellSize.width *LEVEL_WIDTH) - 64, RB.SpriteSheetGet().grid.cellSize.height * 26), 0); if (!game.SinglePlayer) { // Draw Player Two view RB.ClipSet(new Rect2i(0, RB.DisplaySize.height / 2, RB.DisplaySize.width, RB.DisplaySize.height / 2)); cameraOffset = GetCameraOffset(mPlayerTwo); RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2))); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_SKY); DrawScrollingClouds((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2)); cameraOffset = GetCameraOffset(mPlayerTwo); RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2))); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_BACKGROUND); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TERRAIN); if (mWinningPlayer == 0) { mFlagTwoSlot.Render(); } mFlagOne.Render(); mFlagTwo.Render(); mPlayerOne.Render(); mPlayerTwo.Render(); // Draw Castles RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(16, RB.SpriteSheetGet().grid.cellSize.height * 26)); RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i((RB.SpriteSheetGet().grid.cellSize.width *LEVEL_WIDTH) - 64, RB.SpriteSheetGet().grid.cellSize.height * 26), 0); RB.ClipReset(); RB.CameraReset(); // Draw divider for (int x = 0; x < RB.DisplaySize.width; x += 16) { RB.DrawSprite(RB.SpriteIndex(0, 0), new Vector2i(x, (RB.DisplaySize.height / 2) - 4)); } } RB.ClipReset(); RB.CameraReset(); if (mWinningPlayer != 0) { string playerOneStr = "LOSER"; string playerTwoStr = "WINNER"; if (mWinningPlayer == RB.PLAYER_ONE) { playerOneStr = "WINNER"; playerTwoStr = "LOSER"; } int textOffsetX = (int)(Mathf.Cos(Time.time * 6.0f) * 8); int textOffsetY = (int)(Mathf.Sin(Time.time * 6.0f) * 5); Vector2i textSize; string text = playerOneStr; textSize = RB.PrintMeasure(game.assets.gameFont, text); RB.Print(game.assets.gameFont, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2) + textOffsetX, (RB.DisplaySize.height / 4) - (textSize.height / 2) + textOffsetY), Color.white, text); text = playerTwoStr; textSize = RB.PrintMeasure(game.assets.gameFont, text); RB.Print(game.assets.gameFont, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2) + textOffsetX, (RB.DisplaySize.height / 4 * 3) - (textSize.height / 2) + textOffsetY), Color.white, text); } // Let base render last so it can overlay the scene base.Render(); }
private void DrawTMX(int x, int y) { var demo = (DemoReel)RB.Game; Rect2i clipRect = new Rect2i(x, y, 340, 352); if (mMap != null) { RB.ClipSet(clipRect); RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22)); int scrollPos = -(int)RB.Ticks % (mMap.size.width * RB.SpriteSize().width); RB.CameraSet(new Vector2i(256, 144)); RB.DrawMapLayer(1, new Vector2i(scrollPos, 0)); RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSize().width), 0)); RB.DrawMapLayer(2); RB.DrawMapLayer(3); var objs = mMap.objectGroups["Objects"].objects; for (int i = 0; i < objs.Count; i++) { var obj = objs[i]; switch (obj.shape) { case TMXObject.Shape.Rectangle: RB.DrawRect(obj.rect, Color.red); RB.Print(obj.rect, Color.red, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, obj.properties.GetString("name")); break; case TMXObject.Shape.Polyline: for (int j = 0; j < obj.points.Count - 1; j++) { RB.DrawLine( obj.points[j] + new Vector2i(obj.rect.x, obj.rect.y), obj.points[j + 1] + new Vector2i(obj.rect.x, obj.rect.y), Color.green); } break; case TMXObject.Shape.Ellipse: RB.DrawEllipse(obj.rect.center, new Vector2i(obj.rect.width / 2, obj.rect.height / 2), Color.yellow); RB.Print(obj.rect, Color.yellow, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, obj.properties.GetString("name")); break; } } } else { RB.CameraReset(); RB.ClipReset(); RB.Print(new Vector2i(x + 4, y + 4), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/TilemapProps.tmx in Unity"); } RB.CameraReset(); RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21)); RB.ClipReset(); x += 350; mFormatStr.Set("@C// Read shapes and their custom properties from TMX file\n"); mFormatStr.Append("@NmyMap = @[email protected](@S\"Demos/DemoReel/TilemapProps\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@Kvar@N objs = myMap.objectGroups[@S\"Objects\"@N].objects;\n"); mFormatStr.Append("@Kfor@N (@Kint@N i = @L0@N; i < objs.Count; i++)\n"); mFormatStr.Append("{\n"); mFormatStr.Append(" @Kvar@N obj = obj;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kswitch@N (obj.shape)\n"); mFormatStr.Append(" {\n"); mFormatStr.Append(" @Kcase@N @[email protected]:\n"); mFormatStr.Append(" @[email protected](obj.rect, @[email protected]);\n"); mFormatStr.Append(" @[email protected](obj.rect, @[email protected],\n"); mFormatStr.Append(" @[email protected]_H_CENTER | @[email protected]_V_CENTER,\n"); mFormatStr.Append(" obj.properties.GetString(\"name\"));\n"); mFormatStr.Append(" @Kbreak@N;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kcase@N @[email protected]:\n"); mFormatStr.Append(" @Kfor@N (@Kint@N j = @L0@N; j < obj.points.Count - @L1@N; j++)\n"); mFormatStr.Append(" {\n"); mFormatStr.Append(" @[email protected](\n"); mFormatStr.Append(" obj.points[j] + @Knew@N @MVector2i@N(obj.rect.x, obj.rect.y),\n"); mFormatStr.Append(" obj.points[j + @L1@N] + @Knew@N @MVector2i@N(obj.rect.x, obj.rect.y),\n"); mFormatStr.Append(" @[email protected]);\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" @Kbreak@N;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kcase@N @[email protected]:\n"); mFormatStr.Append(" @[email protected](obj.rect.center,\n"); mFormatStr.Append(" new @MVector2i@N(obj.rect.width / @L2@N, obj.rect.height / @L2@N),\n"); mFormatStr.Append(" @[email protected]);\n"); mFormatStr.Append(" @[email protected](obj.rect, @[email protected],\n"); mFormatStr.Append(" @[email protected]_H_CENTER | RB.ALIGN_V_CENTER,\n"); mFormatStr.Append(" obj.properties.GetString(@S\"name\"@N));\n"); mFormatStr.Append(" @Kbreak@N;\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("}\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Also easily read tile custom properties\n"); mFormatStr.Append("@Kvar@N props = @[email protected]<@MTMXProperties@N>(@L0@N, @Knew@N @MVector2i@N(@L2@N, @L5@N));\n"); mFormatStr.Append("@Kint@N blocking = tileProps.GetInt(@S\"blocking\"@N);"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }