private void DrawOffscreen(int x, int y) { var demo = (DemoReel)RB.Game; Vector2i textSize = RB.PrintMeasure(mText); RB.Offscreen(2); RB.Clear(new Color32(0, 0, 0, 0)); RB.DrawNineSlice(new Rect2i(0, 0, textSize.width + 12, textSize.height + 12), new Rect2i(80, 0, 8, 8), new Rect2i(88, 0, 8, 8), new Rect2i(96, 0, 16, 16)); RB.Print(new Vector2i(6, 6), DemoUtil.IndexToRGB(23), mText); RB.Onscreen(); RB.SpriteSheetSet(2); RB.DrawCopy(new Rect2i(0, 0, textSize.width + 12, textSize.height + 12), new Rect2i(x, y + 165, textSize.width + 12, textSize.height + 12), new Vector2i((textSize.width + 12) / 2, (textSize.height + 12) / 2), RB.Ticks); RB.SpriteSheetSet(0); mFormatStr.Set("@C// Draw to offscreen surface and copy to screen\n"); mFormatStr.Append("@MVector2i @Nsize = @[email protected](textStr);\n"); mFormatStr.Append("@[email protected](0);\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N, size.width + @L12@N, size.height + @L12@N),\n"); mFormatStr.Append(" @Knew @MRect2i@N(@L80@N, @L0@N, @L8@N, @L8@N), @Knew @MRect2i@N(@L88@N, @L0@N, @L8@N, @L8@N),\n"); mFormatStr.Append(" @Knew @MRect2i@N(@L96@N, @L0@N, @L16@N, @L16@N));\n"); mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L4@N, @L4@N), @I22@N, textStr);\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected](0, \n"); mFormatStr.Append(" @Knew@M Rect2i@N(@L0@N, @L0@N, size.width + @L7@N, size.height + @L8@N),\n"); mFormatStr.Append(" @Knew@M Rect2i@N(@L").Append(x).Append("@N, @L").Append(y + 165).Append("@N, size.width + @L8@N, size.height + @L8@N),\n"); mFormatStr.Append(" @Knew@M Vector2i@N(size.width / @L2@N, size.height / @L2@N), @L").Append(RB.Ticks % 360).Append("@N);\n"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
/// <summary> /// Render /// </summary> public void Render() { for (int i = 0; i < mBlobs.Count; i++) { mBlobs[i].Render(); } Rect2i titleRect = new Rect2i(0, 50, 93, 17); int bob = (int)(Math.Sin(RB.Ticks / 10.0f) * 6); RB.ShaderSet(C.SHADER_SHADOW); RB.ShaderColorSet(C.SHADER_SHADOW, "_ShadowColor", new Color32(0, 0, 0, 196)); RB.DrawCopy(titleRect, new Rect2i((RB.DisplaySize.width / 2) - (titleRect.width / 2) + 3, 32 + bob + 3, titleRect.width, titleRect.height)); RB.ShaderReset(); RB.DrawCopy(titleRect, new Rect2i((RB.DisplaySize.width / 2) - (titleRect.width / 2), 32 + bob, titleRect.width, titleRect.height)); RB.DrawCopy(new Rect2i(38, 68, 199, 188), new Rect2i(11, 96, 199, 188)); RB.ShaderSet(C.SHADER_SHADOW); RB.ShaderColorSet(C.SHADER_SHADOW, "_ShadowColor", new Color32(255, 255, 255, 128)); int highlightOffset = (int)((Math.Sin(RB.Ticks / 50.0f) * RB.DisplaySize.width) + (RB.DisplaySize.width / 2)); int highlightWidth = 20; RB.DrawCopy(new Rect2i(38 + (highlightOffset - 11), 68, highlightWidth, 188), new Rect2i(highlightOffset, 96, highlightWidth, 188)); RB.ShaderReset(); mString.Set("@w244").Append(C.ACTION_VERB).Append(" TO PLAY!"); RB.Print(new Rect2i(0, RB.DisplaySize.height - 80 + 1, RB.DisplaySize.width, 100 + 1), Color.black, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); RB.Print(new Rect2i(0, RB.DisplaySize.height - 80, RB.DisplaySize.width, 100), Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); }
/// <summary> /// Render /// </summary> public void Render() { if (mAlpha <= 0) { return; } RB.TintColorSet(ColorTint); byte prevAlpha = RB.AlphaGet(); RB.AlphaSet((byte)(mAlpha * prevAlpha)); int LifeFrame = 5 - (int)(((float)Life / (float)MaxLife) * 5); if (Type != BrickType.Block) { LastSpriteRect = new Rect2i(Global.BRICK_WIDTH * LifeFrame, 0, Rect.width, Rect.height); } else { LastSpriteRect = new Rect2i(120, 0, 20, 10); } RB.DrawCopy(LastSpriteRect, Rect); for (int i = 0; i < FlashFrame; i++) { RB.DrawRect(new Rect2i(Rect.x + i, Rect.y + i, Rect.width - (i * 2), Rect.height - (i * 2)), Color.white); } RB.TintColorSet(Color.white); RB.AlphaSet(prevAlpha); }
/// <summary> /// Render /// </summary> public void Render() { Rect2i blobRect = new Rect2i(191, 0, 65, 65); RB.TintColorSet(mColorTint); RB.DrawCopy(blobRect, new Rect2i((int)mPos.x - (blobRect.width / 2), (int)mPos.y - (blobRect.height / 2), blobRect.width, blobRect.height)); RB.TintColorSet(Color.white); }
/// <summary> /// Render /// </summary> public void Render() { byte prevAlpha = RB.AlphaGet(); // Be sure to account for shadow render pass here RB.AlphaSet((byte)((mAlpha / 255.0f) * prevAlpha)); RB.DrawCopy(new Rect2i(127, 10, 5, 8), new Rect2i((int)mPos.x, (int)mPos.y, 5, 8)); RB.AlphaSet(prevAlpha); }
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)); }
private void DrawSpinner(int x, int y, int spinnerSize) { var demo = (DemoReel)RB.Game; RB.DrawEllipseFill(new Vector2i(x + spinnerSize, y + spinnerSize), new Vector2i(spinnerSize, spinnerSize), DemoUtil.IndexToRGB(1)); RB.DrawEllipseFill(new Vector2i(x + spinnerSize, y + spinnerSize), new Vector2i(spinnerSize - 6, spinnerSize - 6), DemoUtil.IndexToRGB(4)); RB.DrawEllipseFill(new Vector2i(x + spinnerSize, y + spinnerSize), new Vector2i(8, 8), DemoUtil.IndexToRGB(1)); RB.DrawEllipse(new Vector2i(x + spinnerSize, y + spinnerSize), new Vector2i(spinnerSize, spinnerSize), DemoUtil.IndexToRGB(4)); RB.SpriteSheetSet(mSpriteSheet2); RB.DrawCopy(new Rect2i(0, 0, (spinnerSize * 2) + 1, (spinnerSize * 2) + 1), new Rect2i(x, y, (spinnerSize * 2) + 1, (spinnerSize * 2) + 1), new Vector2i(spinnerSize, spinnerSize), mMusicTicks / 50); RB.SpriteSheetSet(mSpriteSheet1); }
/// <summary> /// Render /// </summary> public void Render() { RB.DrawNineSlice(Rect, mNSFrame[FlashFrame]); if (mLaserOffset < 1.0f) { Vector2i offset = Vector2i.zero; offset.x = (int)(16 * mLaserOffset); offset.y = (int)(8 * mLaserOffset); byte prevAlpha = RB.AlphaGet(); RB.AlphaSet((byte)((1 - mLaserOffset) * prevAlpha)); RB.DrawCopy(new Rect2i(120, 10, 7, 10), new Rect2i(Rect.x - 3 - offset.x, Rect.y - 2 - offset.y, 7, 10)); RB.DrawCopy(new Rect2i(120, 10, 7, 10), new Rect2i(Rect.x + Rect.width - 4 + offset.x, Rect.y - 2 - offset.y, 7, 10)); RB.AlphaSet(prevAlpha); } }
private void DrawCopy(int x, int y, int spriteIndex) { var demo = (DemoReel)RB.Game; RB.CameraSet(new Vector2i(-x, -y - 17)); DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 16, 16), -1, mOutputFrame, mOutputBackground); int copySize = (int)((Mathf.Sin(RB.Ticks / 20.0f) * 8) + 9); RB.DrawCopy(new Rect2i(0, 0, copySize, copySize), new Vector2i(0, 0)); RB.CameraReset(); mFormatStr.Set("@C// Draw rectangular areas from sprite sheet\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i(@L0@N, @L0@N, @L").Append(copySize).Append("@N, @L").Append(copySize).Append("@N), @Knew @MVector2i@N(@L0@N, @L0@N));"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
/// <summary> /// Run the stress test /// </summary> protected override void StressTest() { Random.InitState(0); RB.Offscreen(3); RB.Clear(new Color32(0, 0, 0, 0)); RB.Offscreen(2); RB.Clear(new Color32(0, 0, 0, 0)); // Generate texture on first offscreen surface for (int i = 0; i < 64; i++) { int radius = Random.Range(2, 5); RB.DrawEllipseFill( new Vector2i(Random.Range(-4, 36), Random.Range(-4, 36)), new Vector2i(radius, radius), mRandomColor[i]); } // Copy the generate texture mirrored on second offscreen surface RB.Offscreen(3); RB.SpriteSheetSet(2); RB.DrawCopy(new Rect2i(0, 0, 32, 32), Vector2i.zero, RB.FLIP_H | RB.FLIP_V); RB.Onscreen(); for (int i = 0; i < mStressLevel; i++) { var randPos = mRandomPos[i]; randPos += GetWiggle(); // Draw half the sprites from offscreen 0 and half from 1. int offscreen = 2; if (i >= mStressLevel / 2) { offscreen = 3; } RB.SpriteSheetSet(offscreen); RB.DrawCopy(new Rect2i(0, 0, 32, 32), randPos); } }
/// <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); }
/// <summary> /// Render /// </summary> public void Render() { var game = (BrickBustGame)RB.Game; var level = game.Level; for (int i = 0; i < level.Lives; i++) { RB.DrawCopy(new Rect2i(0, 40, 15, 7), new Rect2i(10 + (i * 17), RB.DisplaySize.height - 10, 15, 7)); } Rect2i titleRect = new Rect2i(0, 50, 93, 17); RB.DrawCopy(titleRect, new Rect2i((RB.DisplaySize.width / 2) - (titleRect.width / 2), 2, titleRect.width, titleRect.height)); mString.Set("@64C132SCORE@-\n").Append(level.Score); RB.Print(new Rect2i(0, 0, RB.DisplaySize.width / 4, RB.SpriteSize(0).height * 2), Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); mString.Set("@64C132HISCORE@-\n").Append(level.HiScore); RB.Print(new Rect2i(RB.DisplaySize.width - (RB.DisplaySize.width / 4), 0, RB.DisplaySize.width / 4, RB.SpriteSize(0).height * 2), Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); mString.Set("DRAG TO MOVE PADDLE\n\nDOUBLE ").Append(C.ACTION_VERB).Append(" TO RELEASE THE BALL!"); if (mShowGameOver) { mString.Set("GAME OVER!\n\nDOUBLE ").Append(C.ACTION_VERB).Append(" TO EXIT!"); } else if (mShowWin) { mString.Set("LEVEL CLEARED!\n\nDOUBLE ").Append(C.ACTION_VERB).Append(" TO PROCEED!"); } if (mInfoFade > 0) { int bob = (int)(Math.Sin(RB.Ticks / 10.0f) * 5); RB.AlphaSet((byte)mInfoFade); RB.Print(new Rect2i(0 + 2, 260 + 2 + bob, RB.DisplaySize.width, 40), Color.black, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); RB.Print(new Rect2i(0, 260 + bob, RB.DisplaySize.width, 40), Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); RB.AlphaSet(255); } }
private void DrawPositional(int x, int y) { RB.CameraSet(new Vector2i(-x, -y)); mFormatStr.Set("@C// RetroBlit supports positional sounds. Simply\n"); mFormatStr.Append("@C// set the position of your sound, and the\n"); mFormatStr.Append("@C// position of the listener!\n"); mFormatStr.Append("@N\n"); mFormatStr.Append("@Kvoid@N Init() {\n"); mFormatStr.Append(" sndRef = @[email protected](waterfallSnd);\n"); mFormatStr.Append(" @[email protected](sndRef, @Ltrue@N);\n"); mFormatStr.Append("}\n"); mFormatStr.Append("\n"); mFormatStr.Append("@Kvoid@N Update() {\n"); mFormatStr.Append(" @[email protected](sndRef, @Knew@N @MVector2i@N(@L" + mSoundPos.x + "@N, @L" + mSoundPos.y + "@N));\n"); mFormatStr.Append(" @[email protected](@Knew@N @MVector2i@N(@L" + mListenerPos.x + "@N, @L" + mListenerPos.y + "@N));\n"); mFormatStr.Append("}\n"); RB.Print(new Vector2i(0, 0), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); mPositionalButton.Render(); for (int i = 0; i < (int)(10 * RB.SoundVolumeGet(mPosSoundRef)); i++) { int radius = 3; RB.DrawEllipse(new Vector2i((i * 23) + 4, mListenerPos.y - 3), new Vector2i(radius, radius), DemoUtil.IndexToRGB(2)); } // Use absolute coordinates for drawing ear/rain drop RB.CameraReset(); var volAlpha = (byte)(RB.SoundVolumeGet(mPosSoundRef) * 255); RB.AlphaSet(volAlpha); RB.DrawLine(mListenerPos, mSoundPos, DemoUtil.IndexToRGB(17)); RB.DrawCopy(new Rect2i(0, 224, 14, 24), mListenerPos - new Vector2i(14 / 2, 24 / 2)); RB.DrawCopy(new Rect2i(14, 224, 14, 24), mSoundPos - new Vector2i(14 / 2, 24 / 2)); RB.AlphaSet(255); }
/// <summary> /// Render /// </summary> public void Render() { for (int i = 0; i < mParticles.Count; i++) { RB.TintColorSet(mParticles[i].ColorTint); float alpha = 1.0f; if (mParticles[i].Life < 0.5f) { alpha = mParticles[i].Life / 0.5f; } byte prevAlpha = RB.AlphaGet(); RB.AlphaSet((byte)(prevAlpha * alpha)); RB.DrawCopy(mParticles[i].Rect, new Vector2i((int)mParticles[i].Pos.x, (int)mParticles[i].Pos.y)); RB.AlphaSet(prevAlpha); RB.TintColorSet(Color.white); } }
private void DrawTMX(int x, int y) { var demo = (DemoReel)RB.Game; RB.SpriteSheetSet(0); mFormatStr.Set("@C// Load sprite packs at runtime just like any other spritesheet!\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"DemoReel/DemoSpritePack\"@N, @Knew@N @MVector2i@N(@L16@N, @L16@N));\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Now you can draw sprites using their sprite path and name, there is\n"); mFormatStr.Append("@C// no need to specify source rectangle, RetroBlit sprite packing\n"); mFormatStr.Append("@C// creates an internal lookup table that takes care of that for you!\n"); var outputFrameRect = new Rect2i(x + 130, y + 60, 20, 20); DemoUtil.DrawOutputFrame(outputFrameRect, -1, 21, 22); if (RB.Ticks % 40 < 20) { mFormatStr.Append("@[email protected](@S\"Characters/Hero1\"@N, @Knew@N @MVector2i@N(@L32@N, @L48@N));\n"); RB.DrawSprite("Characters/Hero1", new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 2)); } else { mFormatStr.Append("@[email protected](@S\"Characters/Hero2\"@N, @Knew@N @MVector2i@N(@L32@N, @L48@N));\n"); RB.DrawSprite("Characters/Hero2", new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 2)); } RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); y += 90; mFormatStr.Set("@C// You can also use sprite packs with tile maps\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L0@N, @L0@N), @S\"Terrain/GrassTopRight\"@N, @[email protected]_H);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L1@N, @L0@N), @S\"Terrain/GrassTop\"@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L2@N, @L0@N), @S\"Terrain/GrassTop\"@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L3@N, @L0@N), @S\"Terrain/GrassTopRight\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L0@N, @L1@N), @S\"Terrain/DirtSide\"@N, @[email protected]_H);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L1@N, @L1@N), @S\"Terrain/DirtCenter\"@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L2@N, @L1@N), @S\"Terrain/DirtCenter\"@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L3@N, @L1@N), @S\"Terrain/DirtSide\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](0);"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); RB.MapSpriteSet(0, new Vector2i(0, 0), mSpriteGrassTopRight, RB.FLIP_H); RB.MapSpriteSet(0, new Vector2i(1, 0), mSpriteGrassTop); RB.MapSpriteSet(0, new Vector2i(2, 0), mSpriteGrassTop); RB.MapSpriteSet(0, new Vector2i(3, 0), mSpriteGrassTopRight); RB.MapSpriteSet(0, new Vector2i(0, 1), mSpriteDirtSide, RB.FLIP_H); RB.MapSpriteSet(0, new Vector2i(1, 1), mSpriteDirtCenter); RB.MapSpriteSet(0, new Vector2i(2, 1), mSpriteDirtCenter); RB.MapSpriteSet(0, new Vector2i(3, 1), mSpriteDirtSide); outputFrameRect = new Rect2i(x + 105, y + 95, (16 * 4) + 4, (16 * 2) + 4); DemoUtil.DrawOutputFrame(outputFrameRect, -1, 21, 22); RB.DrawMapLayer(0, new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 4)); y += 140; mFormatStr.Set("@C// Sometimes it can be useful to get the sprite source rectangle\n"); mFormatStr.Append("@Kvar@N sprite = @[email protected](@S\"Terrain/Water\"@N);\n"); mFormatStr.Append("@Kvar@N sourceRect = sprite.SourceRect;\n"); mFormatStr.Append("sourceRect.x += @L").Append((int)((RB.Ticks / 2) % 16)).Append("@N;\n"); mFormatStr.Append("@[email protected](sourceRect, @Knew@N @MVector2i@N(@L32@N, @L48@N));\n"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); outputFrameRect = new Rect2i(x + 130, y + 44, 16 + 4, 16 + 4); DemoUtil.DrawOutputFrame(outputFrameRect, -1, 21, 22); var sprite = RB.PackedSpriteGet("Terrain/Water"); var sourceRect = sprite.SourceRect; sourceRect.x += (int)((RB.Ticks / 2) % 16); sourceRect.width = 16; RB.DrawCopy(sourceRect, new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 2)); y += 72; mFormatStr.Set("@C// You can also use sprite packs for custom fonts, nine-slice images,\n"); mFormatStr.Append("@C// and when loading map layers from TMX files!\n"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); y += 20; mFormatStr.Set("@w444"); int count = mCounter; int ms = count % 60; count /= 60; int s = count % 60; count /= 60; int m = count; mFormatStr.Append(m, 2).Append(':').Append(s, 2).Append(':').Append(ms, 2); mCounter++; if (mCounter >= 60 * 60 * 60) { mCounter = 0; } RB.Print(0, new Vector2i(x + 15, y + 8), Color.white, mFormatStr); int xGrow = (int)(Mathf.Sin(RB.Ticks / 40.0f) * 20.0f) + 20 + 20; int yGrow = (int)(Mathf.Sin(RB.Ticks / 20.0f) * 18.0f) + 18 + 16; RB.DrawNineSlice(new Rect2i(x + 130 - (xGrow / 2), y + 18 - (yGrow / 2), xGrow, yGrow), mNineSlice); RB.DrawMapLayer(1, new Vector2i(x + 190, y - 1)); }
private void DrawSpritePacking(int x, int y) { var demo = (DemoReel)RB.Game; mFormatStr.Set( "@DRetroBlit features a sprite packer that can cram your folders\n" + "full of sprites into optimal sprite sheets! To use it simply\n" + "create a sprite pack file (.sp) and point it to your sprite folder."); RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(25), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); y += 16; int indent = 16; int row = 0; int rowSpacing = 9; int imageSpacing = 3; int fileColor = 5; int folderColor = 3; int alphaSprite = 7; // Draw sprite pack file RB.CameraSet(new Vector2i(-170, -16)); RB.DrawRectFill(new Rect2i(x - 4, y - 4, 108, 112), DemoUtil.IndexToRGB(2)); mFormatStr.Set("@C// Source folder(s)\n"); mFormatStr.Append("@C// relative to project\n"); mFormatStr.Append("@C// root\n"); mFormatStr.Append("@MSOURCE_FOLDER@N=@LSprites@N\n\n"); mFormatStr.Append("@C// Output size\n"); mFormatStr.Append("@MOUTPUT_WIDTH@N=@L96@N\n"); mFormatStr.Append("@MOUTPUT_HEIGHT@N=@L96@N\n\n"); mFormatStr.Append("@C// Trim empty space\n"); mFormatStr.Append("@MTRIM@N=@Ltrue@N"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(fileColor), "DemoSpritePack.sp"); RB.DrawLine(new Vector2i(x, y + rowSpacing + 2), new Vector2i(x + 100, y + rowSpacing + 2), DemoUtil.IndexToRGB(3)); RB.Print(new Vector2i(x, y + rowSpacing + rowSpacing), DemoUtil.IndexToRGB(fileColor), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); RB.DrawRectFill(new Rect2i(-32, 60, 6 * 3, 6), DemoUtil.IndexToRGB(5)); RB.DrawRectFill(new Rect2i(-26, 54, 6, 6 * 3), DemoUtil.IndexToRGB(5)); // Draw file listing RB.CameraSet(new Vector2i(-4, -16)); RB.SpriteSheetSet(0); RB.DrawRectFill(new Rect2i(x - 4, y - 4, 120, 266), DemoUtil.IndexToRGB(2)); mFormatStr.Set( "@DYour sprite source folders can be anywhere, but it's best to keep\n" + "them out of your @NAssets@D folder so that Unity does not put your\n" + "source sprites into the game @NAsset Resources@D!\n" + "\n" + "When you change your source sprites be sure to manually re-import\n" + "your sprite pack because Unity can't detect sprite changes outside\n" + "of the @NAssets@D folder!"); RB.Print(new Vector2i(x - 4, y - 4 + 270), DemoUtil.IndexToRGB(25), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); RB.Print(new Vector2i(x, y + row), DemoUtil.IndexToRGB(folderColor), "Sprites/"); row += rowSpacing; RB.Print(new Vector2i(x + indent, y + row), DemoUtil.IndexToRGB(folderColor), "Characters/"); row += rowSpacing; RB.SpriteSheetSet(1); RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row)); RB.SpriteSheetSet(0); RB.DrawSprite(mSpriteHero1, new Vector2i(x + (indent * 2), y + row)); row += mSpriteHero1.Size.height + imageSpacing; RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "Hero1.png"); row += rowSpacing; RB.SpriteSheetSet(1); RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row)); RB.SpriteSheetSet(0); RB.DrawSprite(mSpriteHero2, new Vector2i(x + (indent * 2), y + row)); row += mSpriteHero2.Size.height + imageSpacing; RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "Hero2.png"); row += rowSpacing; RB.Print(new Vector2i(x + indent, y + row), DemoUtil.IndexToRGB(folderColor), "Terrain/"); row += rowSpacing; RB.SpriteSheetSet(1); RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row)); RB.SpriteSheetSet(0); RB.DrawSprite(mSpriteDirtCenter, new Vector2i(x + (indent * 2), y + row)); row += mSpriteDirtCenter.Size.height + imageSpacing; RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "DirtCenter.png"); row += rowSpacing; RB.SpriteSheetSet(1); RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row)); RB.SpriteSheetSet(0); RB.DrawSprite(mSpriteDirtSide, new Vector2i(x + (indent * 2), y + row)); row += mSpriteDirtSide.Size.height + imageSpacing; RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "DirtSide.png"); row += rowSpacing; RB.SpriteSheetSet(1); RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row)); RB.SpriteSheetSet(0); RB.DrawSprite(mSpriteGrassTop, new Vector2i(x + (indent * 2), y + row)); row += mSpriteGrassTop.Size.height + imageSpacing; RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "GrassTop.png"); row += rowSpacing; RB.SpriteSheetSet(1); RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row)); RB.SpriteSheetSet(0); RB.DrawSprite(mSpriteGrassTopRight, new Vector2i(x + (indent * 2), y + row)); row += mSpriteGrassTopRight.Size.height + imageSpacing; RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "GrassTopRight.png"); row += rowSpacing; RB.SpriteSheetSet(0); RB.DrawSprite(mSpriteWater, new Vector2i(x + (indent * 2), y + row)); row += mSpriteWater.Size.height + imageSpacing; RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "Water.png"); row += rowSpacing; RB.Print(new Vector2i(x + indent, y + row), DemoUtil.IndexToRGB(folderColor), "Other/"); row += rowSpacing; RB.Print(new Vector2i(x + (indent * 3), y + row), DemoUtil.IndexToRGB(folderColor), "...\n...\n..."); // Draw packed sprite sheet RB.CameraSet(new Vector2i(-168, -172)); RB.DrawRectFill(new Rect2i(x, y, RB.SpriteSheetSize().width + 4, RB.SpriteSheetSize().height + 4), DemoUtil.IndexToRGB(2)); RB.SpriteSheetSet(1); for (int gx = 0; gx < 6; gx++) { for (int gy = 0; gy < 6; gy++) { RB.DrawSprite(alphaSprite, new Vector2i(x + 2 + (gx * 16), y + 2 + (gy * 16))); } } RB.SpriteSheetSet(0); RB.DrawCopy(new Rect2i(0, 0, RB.SpriteSheetSize().width, RB.SpriteSheetSize().height), new Vector2i(x + 2, y + 2)); Vector2i p0 = new Vector2i((RB.SpriteSheetSize().width / 2) + 6, 8); Vector2i p1 = new Vector2i(p0.x - 10, p0.y - 10); Vector2i p2 = new Vector2i(p0.x + 10, p0.y - 10); RB.DrawTriangleFill(p0, p1, p2, DemoUtil.IndexToRGB(5)); RB.DrawRectFill(new Rect2i(p0.x - 6, p1.y - 10, 11, 10), DemoUtil.IndexToRGB(5)); RB.CameraReset(); }
private void DrawTMX(int x, int y) { var demo = (DemoReel)RB.Game; if (mMap != null) { RB.Offscreen(2); RB.DrawRectFill(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height), DemoUtil.IndexToRGB(22)); RB.DrawMapLayer(0); RB.DrawMapLayer(1); RB.Offscreen(3); RB.Clear(new Color32(0, 0, 0, 0)); RB.SpriteSheetSet(1); RB.DrawSprite(0, new Vector2i((int)mBouncePos.x, (int)mBouncePos.y), mVelocity.x > 0 ? RB.FLIP_H : 0); RB.Onscreen(); RB.ShaderSet(0); RB.ShaderSpriteSheetTextureSet(0, "Mask", 3); RB.ShaderFloatSet(0, "Wave", RB.Ticks / 10.0f); RB.ShaderSpriteSheetFilterSet(0, 3, RB.Filter.Linear); RB.SpriteSheetSet(2); RB.DrawCopy(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height), Vector2i.zero); RB.ShaderReset(); RB.SpriteSheetSet(0); } else { RB.Print(new Vector2i(x, y + 250), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } string shaderName = "WavyMaskShader"; mFormatStr.Set("@C// Custom shaders can be used for many things, like masking!\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Demos/DemoReel/").Append(shaderName).Append("\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Draw a tilemap to one offscreen surface\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N,\n"); mFormatStr.Append(" @[email protected], @[email protected]),\n"); mFormatStr.Append(" @I22@N);\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Draw a mask to the other offscreen surface\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("@[email protected](@Knew @MColor32@N(@L0@N, @L0@N, @L0@N, @L0@N));\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew @MVector2i@N(@L").Append((int)mBouncePos.x).Append("@N, @L").Append((int)mBouncePos.y).Append("@N)").Append(mVelocity.x > 0 ? ", RB.FLIP_H" : string.Empty).Append(");\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Use a custom shader to combine the two!\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Mask\"@N, @L1@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Wave\"@N, @L").Append(RB.Ticks / 10.0f, 2).Append("f@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @L3@N, @MRB@N.@[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N,\n @[email protected], @[email protected]),\n @[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected]();\n"); DemoUtil.HighlightCode(mFormatStr, mCodeStr); mFormatStr.Set("@C// This shader multiplies in a mask and applies a wavy effect!\n"); mFormatStr.Append("@KShader@N \"Unlit/").Append(shaderName).Append("\" {\n"); mFormatStr.Append(" @KSubShader@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @KPass@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @C/*** Insert custom shader variables here ***/\n"); mFormatStr.Append(" @Ksampler2D@N Mask;\n"); mFormatStr.Append(" @Kfloat@N Wave;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Nfrag_in vert(vert_in v, @Kout float4@N screen_pos : @MSV_POSITION@N) {\n"); mFormatStr.Append(" @C...@N\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kfloat4@N frag(frag_in i, @MUNITY_VPOS_TYPE@N screen_pos : @MVPOS@N) : @MSV_Target@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @C/*** Insert custom fragment shader code here ***/@N\n"); mFormatStr.Append(" @C// Sample the mask texture@N\n"); mFormatStr.Append(" i.uv.x += sin(Wave + i.uv.y * @L8@N) * @L0.025@N;\n"); mFormatStr.Append(" i.uv.y += cos(Wave - i.uv.x * @L8@N) * @L0.015@N;\n"); mFormatStr.Append(" @Kfloat4@N mask_color = @Mtex2D@N(Mask, i.uv).rgba;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @C// Multiply the sprite pixel by mask color@N\n"); mFormatStr.Append(" @Kreturn@N sprite_pixel_color * mask_color;\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("}\n"); DemoUtil.HighlightCode(mFormatStr, mShaderStr); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), mCodeStr); RB.Print(new Vector2i(x + 300, y), DemoUtil.IndexToRGB(5), mShaderStr); }
private void DrawSpriteSheet(int x, int y) { var demo = (DemoReel)RB.Game; Rect2i ss0Rect = new Rect2i(0, 0, 16 * 7, 16 * 6); Rect2i ss1Rect = new Rect2i(0, ss0Rect.y + ss0Rect.height + 16, 16 * 7, 16 * 2); Rect2i copyRectWater = new Rect2i(mWaveOffset + ss1Rect.x - 1, ss1Rect.y - 1, 16 + 2, 16 + 2); Rect2i destRectWater = new Rect2i(ss0Rect.x + (3 * 16), ss0Rect.y + (4 * 16), 16, 16); Rect2i copyRectFish = new Rect2i((mFishFrame * 16) + ss1Rect.x - 1, ss1Rect.y - 1 + 16, 16 + 2, 16 + 2); Rect2i destRectFish = new Rect2i(ss0Rect.x + (5 * 16), ss0Rect.y + (4 * 16), 16, 16); RB.CameraSet(new Vector2i(-x, -y)); RB.Print(new Vector2i(ss0Rect.x, ss0Rect.y + ss0Rect.height + 2), Color.gray, "myTilemapSpriteSheet"); RB.Print(new Vector2i(ss0Rect.x, ss1Rect.y + ss1Rect.height + 2), Color.gray, "myAnimationSpriteSheet"); RB.SpriteSheetSet(spriteSheet1); // Draw alpha grid for sprite sheet 0 for (int gx = 0; gx < ss0Rect.width; gx += 16) { for (int gy = 0; gy < ss0Rect.height; gy += 16) { RB.DrawSprite(RB.SpriteIndex(7, 0), new Vector2i(gx + ss0Rect.x, gy + ss0Rect.y)); } } // Draw alpha grid for sprite sheet 1 for (int gx = 0; gx < ss1Rect.width; gx += 16) { for (int gy = 0; gy < ss1Rect.height; gy += 16) { RB.DrawSprite(RB.SpriteIndex(7, 0), new Vector2i(gx + ss1Rect.x, gy + ss1Rect.y)); } } RB.SpriteSheetSet(spriteSheet2); RB.DrawCopy(new Rect2i(0, 0, RB.SpriteSheetGet().sheetSize), new Vector2i(ss1Rect.x, ss1Rect.y)); RB.SpriteSheetSet(spriteSheet1); int color = 7; RB.DrawCopy(new Rect2i(0, 16 * 8, ss0Rect.width, ss0Rect.height), new Vector2i(ss0Rect.x, ss0Rect.y)); // Water copy rects RB.DrawRect(copyRectWater, DemoUtil.IndexToRGB(color)); destRectWater.Expand(1); RB.DrawRect(destRectWater, DemoUtil.IndexToRGB(color)); RB.DrawLine( new Vector2i(copyRectWater.x + (copyRectWater.width / 2), copyRectWater.y), new Vector2i(destRectWater.x + 8, destRectWater.y + 18), DemoUtil.IndexToRGB(color)); // Fish copy rects if (mFishFrame < 7) { RB.DrawRect(copyRectFish, DemoUtil.IndexToRGB(color)); destRectFish.Expand(1); RB.DrawRect(destRectFish, DemoUtil.IndexToRGB(color)); RB.DrawLine( new Vector2i(copyRectFish.x + (copyRectFish.width / 2), copyRectFish.y), new Vector2i(destRectFish.x + 8, destRectFish.y + 18), DemoUtil.IndexToRGB(color)); } 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)); RB.CameraReset(); SuperFlagRun game = (SuperFlagRun)RB.Game; if (game.TitleMap == null) { RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load title TMX map.\nPlease try re-importing the map Demos/SuperFlagRun/TitleMap.tmx in Unity"); return; } RB.CameraSet(new Vector2i(RB.SpriteSize().width, 0)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_SKY); DrawScrollingClouds(); RB.CameraSet(new Vector2i(RB.SpriteSize().width, RB.SpriteSize().height * 12)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_DECO); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_TERRAIN); RB.CameraSet(new Vector2i(RB.SpriteSize().width, -RB.SpriteSize().height * 7)); // Draw Flags mFlagOne.Render(); mFlagTwo.Render(); // Draw Players int x = (RB.SpriteSize().width * 3) + 8; int y = RB.SpriteSize().height * 3; RB.DrawSprite(RB.SpriteIndex(0, 2), new Vector2i(x, y), 0); RB.DrawSprite(RB.SpriteIndex(0, 3), new Vector2i(x, y + RB.SpriteSize().height), 0); x = RB.DisplaySize.width - (RB.SpriteSize().width * 2) - 8; RB.DrawSprite(RB.SpriteIndex(5, 2), new Vector2i(x, y), RB.FLIP_H); RB.DrawSprite(RB.SpriteIndex(5, 3), new Vector2i(x, y + RB.SpriteSize().height), RB.FLIP_H); // Draw Castles RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(RB.SpriteSize().width * 2, RB.SpriteSize().height * 4)); RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i(RB.DisplaySize.width - (RB.SpriteSize().width * 3), RB.SpriteSize().height * 4), 0); // Draw Title RB.CameraReset(); RB.SpriteSheetSet(SuperFlagRun.SPRITESHEET_TITLE); byte tint = (byte)((Mathf.Sin(Time.time * 2) * 60) + 196); RB.TintColorSet(new Color32(tint, tint, tint, 255)); RB.DrawCopy(new Rect2i(0, 0, 323, 103), new Vector2i((RB.DisplaySize.width / 2) - (323 / 2), (int)(Mathf.Sin(Time.time * 2) * 6) + 15)); RB.TintColorSet(Color.white); RB.SpriteSheetSet(SuperFlagRun.SPRITESHEET_SPRITES); // Draw Press Any Button string str = "PRESS ANY BUTTON"; Vector2i textSize = RB.PrintMeasure(SuperFlagRun.GAME_FONT, str); RB.Print(SuperFlagRun.GAME_FONT, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2), (int)(RB.DisplaySize.height * 0.55f)), Color.white, str); RB.Print(new Vector2i(2, RB.DisplaySize.height - 9), Color.black, "RetroBlit technical demo game"); // Let base render last so it can overlay the scene base.Render(); }
/// <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(); }