コード例 #1
0
        private void RefreshOctant(Point2D point, int octant, int radius)
        {
            ShadowLine line          = new ShadowLine();
            bool       fullShadow    = false;
            int        radiusSquared = radius * radius;

            for (int row = 1; row <= radius; row++)
            {
                int rowSquared = row * row;

                Point2D pos = point + TransformOctant(row, 0, octant);
                if (!_map.InBounds(pos.X, pos.Y))
                {
                    break;
                }

                for (int col = 0; col <= row; col++)
                {
                    Point2D colPos = point + TransformOctant(row, col, octant);

                    if (!_map.InBounds(colPos.X, colPos.Y))
                    {
                        break;
                    }

                    if (rowSquared + col * col > radiusSquared)
                    {
                        break;
                    }

                    if (fullShadow)
                    {
                        _map.SetVisible(colPos.X, colPos.Y, false);
                    }
                    else
                    {
                        Shadow projection = ProjectTile(row, col);

                        bool visible = !line.IsInShadow(projection);
                        _map.SetVisible(colPos.X, colPos.Y, visible);

                        if (visible && _map.IsSolid(colPos.X, colPos.Y))
                        {
                            line.Add(projection);
                            fullShadow = line.IsFullShadow;
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Fov.cs プロジェクト: SchwiftyPython/PizzalikeRL
    public void RefreshOctant(Vinteger start, int octant, int maxRows = 999)
    {
        var line = new ShadowLine();

        var fullShadow = false;

        for (var row = 1; row < maxRows; row++)
        {
            var bounds = start.Add(TransformOctant(row, 0, octant));
            if (!InBoundsAndClose(bounds.X, bounds.Y))
            {
                break;
            }

            for (var col = 0; col <= row; col++)
            {
                var pos = start.Add(TransformOctant(row, col, octant));

                if (!InBoundsAndClose(pos.X, pos.Y))
                {
                    break;
                }

                if (fullShadow)
                {
                    var tile = _grid[pos.X, pos.Y];
                    tile.Visibility = Visibilities.Invisible;
                }
                else
                {
                    var projection = ProjectTile(row, col);

                    var visible = !line.IsInShadow(projection);

                    var tile = _grid[pos.X, pos.Y];

                    var blocksLight = tile.GetBlocksLight();

                    if (!visible)
                    {
                        tile.Visibility = Visibilities.Invisible;
                    }
                    else
                    {
                        if (tile.Visibility != Visibilities.Visible && tile.GetPresentEntity() != null)
                        {
                            tile.GetPresentEntity().PositionRevealed();
                        }

                        tile.Visibility = Visibilities.Visible;
                        tile.Revealed   = true;
                    }

                    if (visible && blocksLight)
                    {
                        line.Add(projection);
                        fullShadow = line.IsFullShadow();
                    }
                }
            }
        }
    }