/// <summary> /// Draws a simple rect /// </summary> public static void DrawRect(TCODConsole console, int x, int y, int width, TCODColor color) { TCODColor fadedCol; Vector2 pos; for (int i = 0; i < width; i++) { pos = new Vector2(x + i, y); fadedCol = GetFadedColor(pos, color); console.setCharBackground(pos.X, pos.Y, fadedCol); console.setChar(pos.X, pos.Y, ' '); } }
/// <summary> /// Custom string drawing method that vignets out the text using the renderer /// </summary> public static void DrawText(TCODConsole console, int x, int y, string text, TCODColor color) { TCODColor fadedCol; Vector2 pos; for (int i = 0; i < text.Length; i++) { pos = new Vector2(x + i, y); fadedCol = GetFadedColor(pos, color); console.setCharForeground(pos.X, pos.Y, fadedCol); console.setChar(pos.X, pos.Y, text[i]); } }
/// <summary> /// Renders the current map as the background of the level /// </summary> private void RenderGameBackground(TCODConsole targetConsole, Camera camera, AreaMap currentMap, Vector2 screenCenter) { int left = camera.GetBound(Camera.EBound.Left); int right = camera.GetBound(Camera.EBound.Right); int top = camera.GetBound(Camera.EBound.Top); int bottom = camera.GetBound(Camera.EBound.Bottom); if (left < 0) { left = 0; right = camera.width; } if (top < 0) { top = 0; bottom = camera.height; } if (right > currentMap.width) { left = currentMap.width - camera.width; right = currentMap.width; } if (bottom > currentMap.height) { top = currentMap.height - camera.height; bottom = currentMap.height; } TCODColor fg, bg; for (int y = top; y < bottom; y++) { for (int x = left; x < right; x++) { // Translate the world coords into screen coords int screenX = camera.screenX + x - left; int screenY = camera.screenY + y - top; var tile = currentMap.GetTile(x, y); fg = tile.terrain.fg; bg = tile.terrain.bg; char ch = tile.terrain.Ch; if (!tile.explored && showOnlyExplored) { bg = AreaMap.unexplored.bg; fg = AreaMap.unexplored.fg; ch = AreaMap.unexplored.Ch; } // If the tile is not in the current LOS, fade its color if (!tile.cachedLOS && showOnlyLOS) { bg = FadeColor(bg, blockedBrightness); fg = FadeColor(fg, blockedBrightness); } if (doCircularFade) { bg = GetFadedColor(new Vector2(screenX, screenY), screenCenter, bg); fg = GetFadedColor(new Vector2(screenX, screenY), screenCenter, fg); } targetConsole.setCharBackground(screenX, screenY, bg); targetConsole.setCharForeground(screenX, screenY, fg); targetConsole.setChar(screenX, screenY, ch); } } }
/// <summary> /// Renders all game objects that have a draw component attached onto the target console, at their world positions /// Also obeys current visibility rules /// </summary> private void RenderEntities(TCODConsole targetConsole, Camera camera, AreaMap currentMap, Vector2 screenCenter) { int left = camera.GetBound(Camera.EBound.Left); int right = camera.GetBound(Camera.EBound.Right); int top = camera.GetBound(Camera.EBound.Top); int bottom = camera.GetBound(Camera.EBound.Bottom); if (left < 0) { left = 0; right = camera.width; } if (top < 0) { top = 0; bottom = camera.height; } if (right > currentMap.width) { left = currentMap.width - camera.width; right = currentMap.width; } if (bottom > currentMap.height) { top = currentMap.height - camera.height; bottom = currentMap.height; } Vector2 pos; TCODColor col; for (int i = drawList.Count - 1; i >= 0; i--) { pos = drawList[i].owner.position; bool los = currentMap.GetTile(pos.X, pos.Y).cachedLOS; bool explored = currentMap.GetTile(pos.X, pos.Y).explored; bool isVisible = true; // Do not draw object if it is not in los and is not static, or if it is static, then only if it hasn't been explored yet if (!explored) { continue; } else if (!los) { // check if the entity wants to be rendered anyways if (!drawList[i].owner.Has(typeof(StaticComponent))) { continue; } isVisible = false; } col = drawList[i].color; TCODColor fadedColor = new TCODColor(col.Red, col.Green, col.Blue); // Fade the color based on how far from the center it is if (doCircularFade) { fadedColor = GetFadedColor(pos, screenCenter, col); } if (!isVisible) { fadedColor = FadeColor(fadedColor, 0.5f); } int screenX = camera.screenX + pos.X - left; int screenY = camera.screenY + pos.Y - top; // Draw the char to the forground layer targetConsole.setCharForeground(screenX, screenY, fadedColor); targetConsole.setChar(screenX, screenY, drawList[i].ch); } }
public void DrawRectBorderAt(int x, int y, int left, int top, int right, int bottom, EBorderStyle style, TCODColor borderCol) { // border cases if (x == left && (style == EBorderStyle.WEST || style == EBorderStyle.ALL)) { console.setCharForeground(x, y, borderCol); console.setChar(x, y, CharConstants.VERT_LINE); } if (x == right - 1 && (style == EBorderStyle.EAST || style == EBorderStyle.ALL)) { console.setCharForeground(x, y, borderCol); console.setChar(x, y, CharConstants.VERT_LINE); } if (y == top && (style == EBorderStyle.NORTH || style == EBorderStyle.ALL)) { console.setCharForeground(x, y, borderCol); console.setChar(x, y, CharConstants.HORZ_LINE); } if (y == bottom - 1 && (style == EBorderStyle.SOUTH || style == EBorderStyle.ALL)) { console.setCharForeground(x, y, borderCol); console.setChar(x, y, CharConstants.HORZ_LINE); } // Corner cases: char color has been set by the prev two cases: only if its all sides if (style == EBorderStyle.ALL) { if (x == left && y == top) { console.setChar(x, y, CharConstants.NW_LINE); } if (x == right - 1 && y == top) { console.setChar(x, y, CharConstants.NE_LINE); } if (x == left && y == bottom - 1) { console.setChar(x, y, CharConstants.SW_LINE); } if (x == right - 1 && y == bottom - 1) { console.setChar(x, y, CharConstants.SE_LINE); } } }