/// <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); } }