public void DrawCurrentGridSquare() { // Draw Currently Slotted Item & Highlighted Grid Square (if not overlapping a UI component) if (UIComponent.ComponentWithFocus == null) { // Draw Temporary Function Tool (if active) if (EditorTools.tempTool != null) { EditorTools.tempTool.DrawFuncTool(); } // Draw Function Tool (if active) else if (EditorTools.funcTool != null) { EditorTools.funcTool.DrawFuncTool(); } // Draw AutoTile Tool (if active) else if (EditorTools.autoTool.IsActive) { EditorTools.autoTool.DrawAutoTiles(); } // Draw Tile Tool (if active) else if (EditorTools.tileTool != null) { EditorPlaceholder ph = EditorTools.tileTool.CurrentPlaceholder; // Draw Tile if (ph.tileId > 0) { if (Systems.mapper.TileDict.ContainsKey(ph.tileId)) { TileObject tgo = Systems.mapper.TileDict[ph.tileId]; tgo.Draw(null, ph.subType, Cursor.TileGridX * (byte)TilemapEnum.TileWidth - Systems.camera.posX, Cursor.TileGridY * (byte)TilemapEnum.TileHeight - Systems.camera.posY); } } // Draw Object else if (ph.objectId > 0) { ShadowTile.Draw(ph.objectId, ph.subType, null, Cursor.TileGridX * (byte)TilemapEnum.TileWidth - Systems.camera.posX, Cursor.TileGridY * (byte)TilemapEnum.TileHeight - Systems.camera.posY); } Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(Cursor.TileGridX * (byte)TilemapEnum.TileWidth - Systems.camera.posX, Cursor.TileGridY * (byte)TilemapEnum.TileHeight - Systems.camera.posY, (byte)TilemapEnum.TileWidth, (byte)TilemapEnum.TileHeight), Color.White * 0.25f); } } }
public void DrawBlueprintByLayer(LayerEnum layerEnum, short x, short y, short xStart, short yStart) { // Get the value stored in this blueprint at correct tile position: ArrayList bpData = this.gridTrack[(byte)layerEnum, y, x]; if (bpData == null) { return; } // Verify that a TileID (or ObjectID) is present byte objOrTileID = byte.Parse(bpData[0].ToString()); if (objOrTileID == 0) { return; } // Drawing Objects if (layerEnum == LayerEnum.obj) { ShadowTile.Draw(objOrTileID, byte.Parse(bpData[1].ToString()), null, (xStart + x) * (byte)TilemapEnum.TileWidth - Systems.camera.posX, (yStart + y) * (byte)TilemapEnum.TileHeight - Systems.camera.posY); } // Drawing Tiles else { var tileDict = Systems.mapper.TileDict; if (tileDict.ContainsKey(objOrTileID)) { TileObject tgo = tileDict[objOrTileID]; tgo.Draw(null, byte.Parse(bpData[1].ToString()), (xStart + x) * (byte)TilemapEnum.TileWidth - Systems.camera.posX, (yStart + y) * (byte)TilemapEnum.TileHeight - Systems.camera.posY); } } }
public void Draw() { if (EditorTools.tileTool is TileTool == false) { return; } byte tileHeight = (byte)TilemapEnum.TileHeight + 2; // Draw Editor Scroller Background Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x, this.y, this.width, this.height), Color.DarkSlateGray); Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x + 2, this.y + 2, (byte)TilemapEnum.TileWidth, this.height - 6), Color.White); // Grid Outline for (byte i = 1; i < (byte)EScrollerEnum.NumTiles; i++) { Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x, this.y + i * tileHeight, this.width, 2), Color.DarkSlateGray); } // Draw TileTool Subtype Buttons List <EditorPlaceholder[]> placeholders = EditorTools.tileTool.placeholders; // Placeholder Loop byte len = (byte)placeholders.Count; EditorPlaceholder[] pData = placeholders[EditorTools.tileTool.index]; byte phSubLen = (byte)pData.Length; for (byte s = 0; s < phSubLen; s++) { EditorPlaceholder ph = pData[s]; byte subType = ph.subType; byte tileId = ph.tileId; // Draw Tiles if (tileId > 0) { if (Systems.mapper.TileDict.ContainsKey(tileId)) { TileObject tgo = Systems.mapper.TileDict[tileId]; tgo.Draw(null, subType, this.x + 2, this.y + 50 * s + 2); } } // Draw Objects else if (ph.objectId > 0) { ShadowTile.Draw(ph.objectId, ph.subType, null, this.x + 2, this.y + 50 * s + 2); } } // Highlight the active color short my = (short)Snap.GridFloor(tileHeight, EditorTools.tileTool.subIndex * tileHeight - this.y); Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(this.x, this.y + my * tileHeight, this.width, tileHeight), Color.White * 0.5f); // Hovering Visual if (UIComponent.ComponentWithFocus is EditorScroller) { short my2 = (short)Snap.GridFloor(tileHeight, Cursor.MouseY - this.y); Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(this.x, this.y + my2 * tileHeight, this.width, tileHeight), Color.White * 0.5f); } }
public override void Draw() { //Systems.timer.stopwatch.Start(); Camera cam = Systems.camera; cam.StayBounded((byte)TilemapEnum.GapLeftPixel, this.Width + (byte)TilemapEnum.GapLeftPixel, (byte)TilemapEnum.GapUpPixel, this.Height + (byte)TilemapEnum.GapUpPixel); short startX = Math.Max((short)0, cam.GridX); short startY = Math.Max((short)0, cam.GridY); // Must adjust for the World Gaps (Resistance Barrier) if (startX < (byte)TilemapEnum.GapLeft) { startX = (byte)TilemapEnum.GapLeft; } if (startY < (byte)TilemapEnum.GapUp) { startY = (byte)TilemapEnum.GapUp; } short gridX = (short)(startX + (byte)TilemapEnum.MinWidth + 1); // 30 is view size. +1 is to render the edge. short gridY = (short)(startY + (byte)TilemapEnum.MinHeight + 1); // 18 is view size. +1 is to render the edge. if (gridX > this.tilemap.XCount) { gridX = (short)(this.tilemap.XCount + (byte)TilemapEnum.GapLeft); } // Must limit to room size. if (gridY > this.tilemap.YCount) { gridY = (short)(this.tilemap.YCount + (byte)TilemapEnum.GapUp); } // Must limit to room size. // Camera Position bool isShaking = cam.IsShaking(); int camX = cam.posX + (isShaking ? cam.GetCameraShakeOffsetX() : 0); int camY = cam.posY + (isShaking ? cam.GetCameraShakeOffsetY() : 0); int camRight = camX + cam.width; int camBottom = camY + cam.height + (byte)TilemapEnum.TileHeight; // Run Parallax Handler this.parallax.Draw(); var tileMap = Systems.mapper.TileDict; // Loop through the tilemap data: for (short y = gridY; y-- > startY;) { short tileYPos = (short)(y * (byte)TilemapEnum.TileHeight - camY); for (short x = gridX; x-- > startX;) { // Scan the Tiles Data at this grid square: byte[] tileData = tilemap.GetTileDataAtGrid(x, y); // This occurs when there is no data on the tile (removed, etc). if (tileData == null) { continue; } // Draw Background Layer if (tileData[2] != 0) { TileObject tileObj = tileMap[tileData[2]]; // Render the tile with its designated Class Object: if (tileObj is TileObject) { tileObj.Draw(this, tileData[3], x * (byte)TilemapEnum.TileWidth - camX, tileYPos); } ; } // Draw Main Layer if (tileData[0] != 0) { TileObject tileObj = tileMap[tileData[0]]; // Render the tile with its designated Class Object: if (tileObj is TileObject) { tileObj.Draw(this, tileData[1], x * (byte)TilemapEnum.TileWidth - camX, tileYPos); } ; } // Draw Foreground Layer if (tileData[4] != 0) { TileObject tileObj = tileMap[tileData[4]]; // Render the tile with its designated Class Object: if (tileObj is TileObject) { tileObj.Draw(this, tileData[5], x * (byte)TilemapEnum.TileWidth - camX, tileYPos); } ; } } ; } // Draw object data: this.DrawObjectGroup(this.objects[(byte)LoadOrder.Platform], camX, camY, camRight, camBottom); this.DrawObjectGroup(this.objects[(byte)LoadOrder.Enemy], camX, camY, camRight, camBottom); this.DrawObjectGroup(this.objects[(byte)LoadOrder.Item], camX, camY, camRight, camBottom); this.DrawObjectGroup(this.objects[(byte)LoadOrder.TrailingItem], camX, camY, camRight, camBottom); this.DrawObjectGroup(this.objects[(byte)LoadOrder.Character], camX, camY, camRight, camBottom); this.DrawObjectGroup(this.objects[(byte)LoadOrder.Projectile], camX, camY, camRight, camBottom); // Draw Particles this.particleHandler.Draw(); // Draw Frame Debugging Aid if (DebugConfig.DrawDebugFrames) { this.DrawDebug(camX, camY, camRight, camBottom); } // Debugging //Systems.timer.stopwatch.Stop(); //System.Console.WriteLine("Benchmark: " + Systems.timer.stopwatch.ElapsedTicks + ", " + Systems.timer.stopwatch.ElapsedMilliseconds); }
private void DrawLayer(Dictionary <string, Dictionary <string, ArrayList> > layerData) { Camera cam = Systems.camera; short startX = Math.Max((short)0, cam.GridX); short startY = Math.Max((short)0, cam.GridY); short gridX = (short)(startX + (byte)TilemapEnum.MinWidth + 1); // +1 is to render the edge. short gridY = (short)(startY + (byte)TilemapEnum.MinHeight + 1); // +1 is to render the edge. if (gridX > this.xCount) { gridX = this.xCount; } // Must limit to room size. if (gridY > this.yCount) { gridY = this.yCount; } // Must limit to room size. // Camera Position bool isShaking = cam.IsShaking(); int camX = cam.posX + (isShaking ? cam.GetCameraShakeOffsetX() : 0); int camY = cam.posY + (isShaking ? cam.GetCameraShakeOffsetY() : 0); var tileDict = Systems.mapper.TileDict; // Loop through the tilemap data: for (short y = gridY; y-- > startY;) { short tileYPos = (short)(y * (byte)TilemapEnum.TileHeight - camY); string yStr = y.ToString(); // Make sure this Y-line exists, or skip further review: if (!layerData.ContainsKey(yStr)) { continue; } var yData = layerData[yStr]; for (short x = gridX; x-- > startX;) { // Verify Tile Data exists at this Grid Square: if (!yData.ContainsKey(x.ToString())) { continue; } var xData = yData[x.ToString()]; byte index = byte.Parse(xData[0].ToString()); byte subType = byte.Parse(xData[1].ToString()); // Draw Layer TileObject tileObj = tileDict[index]; // Render the tile with its designated Class Object: if (tileObj is TileObject) { tileObj.Draw(null, subType, x * (byte)TilemapEnum.TileWidth - camX, tileYPos); } ; } ; } }