/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; RB.Clear(DemoUtil.IndexToRGB(22)); if (mMap != null) { int cloudScrollPos = -mCloudTicks % (mMapSize.width * RB.SpriteSheetGet().grid.cellSize.width); RB.CameraSet(new Vector2i(mMapSize.width * RB.SpriteSheetGet().grid.cellSize.width / 4, 0)); RB.DrawMapLayer(0, new Vector2i(cloudScrollPos, 0)); RB.DrawMapLayer(0, new Vector2i(cloudScrollPos + (mMapSize.width * RB.SpriteSheetGet().grid.cellSize.width), 0)); RB.DrawMapLayer(1); RB.DrawMapLayer(2); RB.CameraReset(); } else { RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } var color = DemoUtil.IndexToRGB(2); mFormatStr.Set(mEffectNames[(int)mEffect]).Append("\n@"); mFormatStr.Append(color.r, 2, FastString.FORMAT_HEX_CAPS).Append(color.g, 2, FastString.FORMAT_HEX_CAPS).Append(color.b, 2, FastString.FORMAT_HEX_CAPS); mConvertString.Set(mEffectNames[(int)mEffect]).ToUpperInvariant(); mFormatStr.Append("RB.EffectSet(RB.Effect.").Append(mConvertString).Append(mParamsText).Append(");"); RB.Print(new Vector2i((RB.DisplaySize.width / 2) - 120, (RB.DisplaySize.height / 2) - 10), DemoUtil.IndexToRGB(0), mFormatStr); }
private static void RenderMap(GameMap map) { RB.SpriteSheetSet(Engine.A.TerrainSprites); RB.DrawMapLayer((int)MapLayers.TERRAIN); foreach (var pos in map.Positions()) { if (!map.Explored[pos]) { continue; } var terrain = map.GetTerrain <MapTerrain>(pos); var alpha = map.FOV.BooleanFOV[pos] ? (byte)255 : (byte)127; RB.AlphaSet(alpha); RB.DrawSprite(terrain.SpriteID, new Vector2i(pos.X * C.TILE_SIZE, pos.Y * C.TILE_SIZE)); RB.AlphaSet(255); } RB.SpriteSheetSet(Engine.A.CharacterSprites); foreach (var actor in map.Actors) { if (!map.Explored[actor.Position]) { continue; } var layerID = (actor is Enemy) ? (int)MapLayers.ENEMIES : (int)MapLayers.PLAYER; RB.DrawMapLayer(layerID); RB.DrawSprite(actor.SpriteID, new Vector2i(actor.Position.X * C.TILE_SIZE, actor.Position.Y * C.TILE_SIZE)); } }
public void drawMap(Vector2i mapDrawPos) { foreach (LayerMap m in mapLayers) { RB.DrawMapLayer(m.layer, mapDrawPos); } drawCharacters(); }
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)); }
/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; RB.Clear(DemoUtil.IndexToRGB(22)); int spriteFrame = ((int)RB.Ticks % 40) > 20 ? 1 : 0; if (mMap != null) { RB.DrawMapLayer(0); RB.DrawMapLayer(1); } RB.EffectSet(RB.Effect.Noise, 0.15f); RB.EffectSet(RB.Effect.Scanlines, 1.0f); RB.EffectSet(RB.Effect.Desaturation, (Mathf.Sin(RB.Ticks / 50.0f) * 0.5f) + 0.5f); RB.EffectApplyNow(); RB.EffectReset(); if (mMap != null) { RB.DrawSprite(0 + spriteFrame, new Vector2i(13 * 16, 16 * 16)); } else { RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } mFormatStr.Set("@C// Specify when post-processing effects should be applied\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@MRB@N.@[email protected], @L0.15f@N);\n"); mFormatStr.Append("@[email protected](@MRB@N.@[email protected], @L1.0f@N);\n"); mFormatStr.Append("@[email protected](@MRB@N.@[email protected], @L").Append((Mathf.Sin(RB.Ticks / 50.0f) * 0.5f) + 0.5f, 2).Append("f@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@L").Append(0 + spriteFrame).Append("@N, @Knew@N Vector2i(@L").Append(13 * 16).Append("@N, @L").Append(16 * 16).Append("@N));"); var size = RB.PrintMeasure(DemoUtil.HighlightCode(mFormatStr, mFinalStr)); size.x += 4; size.y += 4; var rect = new Rect2i((RB.DisplaySize.width / 2) - (size.x / 2), (RB.DisplaySize.height / 2) - (size.y / 2), size.x, size.y); rect.y -= 64; RB.DrawRectFill(rect, DemoUtil.IndexToRGB(1)); RB.DrawRect(rect, DemoUtil.IndexToRGB(4)); RB.Print(new Vector2i(rect.x + 2, rect.y + 2), DemoUtil.IndexToRGB(0), mFinalStr); }
/// <summary> /// Render /// </summary> public void Render() { var game = (BrickBustGame)RB.Game; RB.DrawMapLayer(0); // Render in 2 passes, first pass renders shadows for (int renderPass = 0; renderPass < 2; renderPass++) { if (renderPass == 0) { RB.ShaderSet(game.assets.shaderShadow); game.assets.shaderShadow.ColorSet("_ShadowColor", new Color32(0, 0, 0, 96)); RB.CameraSet(new Vector2i(-4, -4)); } else { RB.TintColorSet(Color.white); RB.ShaderReset(); } for (int i = 0; i < mBricks.Count; i++) { mBricks[i].Render(); } mPaddle.Render(); for (int i = 0; i < mBalls.Count; i++) { mBalls[i].Render(); } for (int i = 0; i < mPowerUps.Count; i++) { mPowerUps[i].Render(); } for (int i = 0; i < mLaserShots.Count; i++) { mLaserShots[i].Render(); } mParticles.Render(); if (renderPass == 0) { RB.AlphaSet(255); RB.CameraReset(); } } RB.DrawMapLayer(1, new Vector2i(-2, 0)); mHud.Render(); }
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 DrawTilemap(int x, int y) { if (mMap == null) { RB.Print(new Vector2i(x + 2, y + 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/TilemapInfinite.tmx in Unity"); return; } if (mMap.status != RB.AssetStatus.Ready) { return; } var chunkPixelSize = new Vector2i(RB.MapChunkSize.width * mSpriteSheet1.grid.cellSize.width, RB.MapChunkSize.height * mSpriteSheet1.grid.cellSize.height); // Figure out which map chunk is in the top left corner of the camera view var newTopLeftChunk = new Vector2i(mCameraPos.x / chunkPixelSize.width, mCameraPos.y / chunkPixelSize.height); if (newTopLeftChunk != mTopLeftChunk) { var shift = mTopLeftChunk - newTopLeftChunk; RB.MapShiftChunks(0, shift); for (int cy = 0; cy <= (mClipRect.height / chunkPixelSize.height) + 1; cy++) { for (int cx = 0; cx <= (mClipRect.width / chunkPixelSize.width) + 1; cx++) { var chunkPos = new Vector2i(cx * RB.MapChunkSize.x, cy * RB.MapChunkSize.y); var mapPos = new Vector2i(newTopLeftChunk.x * RB.MapChunkSize.x, newTopLeftChunk.y * RB.MapChunkSize.y) + chunkPos; mapPos.x = mapPos.x % mMap.size.width; if (RB.MapChunkEmpty(0, chunkPos)) { mMap.LoadLayerChunk("Terrain", 0, mapPos, chunkPos); } } } mTopLeftChunk = newTopLeftChunk; } mChunkCameraPos = new Vector2i(mCameraPos.x % chunkPixelSize.width, mCameraPos.y % chunkPixelSize.height); RB.CameraSet(mChunkCameraPos); RB.DrawMapLayer(0, new Vector2i(x + 1, y + 1)); RB.CameraReset(); }
private void DrawScrollingClouds() { SuperFlagRun game = (SuperFlagRun)RB.Game; if (game.GameMap == null) { return; } int totalMapWidth = game.GameMapSize.width * RB.SpriteSize().width; int offset = (int)(Time.time * 25) % totalMapWidth; RB.CameraSet(new Vector2i(offset, 0)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_CLOUDS); RB.CameraSet(new Vector2i(offset - totalMapWidth, 0)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_CLOUDS); }
private void DrawScrollingClouds(int xoffset, int yoffset) { var game = (SuperFlagRun)RB.Game; if (game.GameMap == null) { return; } int totalMapWidth = game.GameMapSize.width * RB.SpriteSheetGet().grid.cellSize.width; int offset = (int)(Time.time * 25) % totalMapWidth; RB.CameraSet(new Vector2i(xoffset + offset, yoffset)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_CLOUDS); RB.CameraSet(new Vector2i(xoffset + offset - totalMapWidth, yoffset)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_CLOUDS); }
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)); }
/// <summary> /// Render the game state /// </summary> /// <param name="gameState">Game state</param> /// <param name="player">Player</param> /// <param name="menu">Current menu</param> /// <param name="console">Console</param> public static void RenderAll(GameState gameState, EntityID player, Menu menu, Console console) { var game = (RetroDungeoneerGame)RB.Game; RB.ShaderSet(C.SHADER_VIGNETTE); // Use a rect fill instead of RB.Clear() so that the shader will apply var cameraPos = RB.CameraGet(); RB.CameraReset(); RB.DrawRectFill(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height), game.map.backgroundColor); RB.CameraSet(cameraPos); RB.DrawMapLayer(C.LAYER_GRID); RB.DrawMapLayer(C.LAYER_TERRAIN); var previousTintColor = RB.TintColorGet(); EffectManager.Instance.Render(RenderOrder.ACTOR_UNDERLAY_EFFECTS); foreach (var renderOrder in renderOrderList) { if (renderOrder == RenderOrder.HIDDEN) { continue; } foreach (var entity in EntityStore.entities) { if (renderOrder == RenderOrder.ACTOR_UNDERLAY_EFFECTS) { if (entity.e.moveTrail != null) { RenderTrail(entity); } } if (entity.e.renderOrder == renderOrder) { RenderEntity(entity); } } } EffectManager.Instance.Render(RenderOrder.ACTOR_OVERLAY_EFFECTS); RB.TintColorSet(previousTintColor); // Draw visibility layer on top, covering tiles as needed RB.DrawMapLayer(C.LAYER_VISIBILITY); RenderMapBorder(); EffectManager.Instance.Render(RenderOrder.TOP_MOST); RB.ShaderReset(); console.Render(); RenderUI(gameState, menu, player); if (menu == null) { RenderMouseHover(); } if (gameState == GameState.TARGETING) { RenderTargeting(); } }
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)); }
/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; if (mMap != null) { RB.Clear(DemoUtil.IndexToRGB(22)); RB.DrawMapLayer(0); RB.DrawMapLayer(1); } else { RB.Print(new Vector2i(2, 210), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } RB.EffectShader(0); RB.ShaderFloatSet(0, "Wave", RB.Ticks / 25.0f); RB.DrawRectFill(new Rect2i(0, 0, RB.DisplaySize.width, 200), DemoUtil.IndexToRGB(1)); string shaderName = "PresentRippleShader"; mFormatStr.Set("@C// Custom post-processing shader\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Demos/DemoReel/").Append(shaderName).Append("\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Wave\"@N, @L").Append(RB.Ticks / 25.0f, 2).Append("f@N);\n"); mFormatStr.Append("@[email protected](@MRB@N.@[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected]();\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(" @Kfloat@N Wave;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Nfrag_in vert(appdata v) {\n"); mFormatStr.Append(" @C...@N\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kfloat4@N frag(v2f i) : @MSV_Target@N {\n"); mFormatStr.Append(" @C/*** Insert custom fragment shader code here ***/@N\n"); mFormatStr.Append(" @Kfloat2@N centerOffset = @L-1.0@N + @L2.0@N * i.uv.xy;\n"); mFormatStr.Append(" @Kfloat@N len = @Klength@N(centerOffset);\n"); mFormatStr.Append(" i.uv.xy += (centerOffset / len) * cos(len * @L10.0@N - Wave) * @L0.005@N;\n"); mFormatStr.Append(" @C...@N\n"); mFormatStr.Append(" @Kreturn@N color;\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("}\n"); DemoUtil.HighlightCode(mFormatStr, mShaderStr); RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(0), mCodeStr); RB.Print(new Vector2i(304, 4), DemoUtil.IndexToRGB(0), mShaderStr); }
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); }
/// <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(); }
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)); }
/// <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(); }