Example #1
0
    ///////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Creates new vision shape.
    /// </summary>
    /// <param name="fow"></param>
    /// <returns></returns>
    FogShape CreateShape(FogManager fow)
    {
        if (ShapeType == FogShapeType.Circle)
        {
            FogCircle shape = new FogCircle();
            FillShape(fow, shape);
            shape.InnerRadius = InnerRadius;
            shape.Angle       = Angle;
            return(shape);
        }
        else if (ShapeType == FogShapeType.Texture)
        {
            if (Texture == null)
            {
                return(null);
            }

            FogShapeTexture shape = new FogShapeTexture();
            FillShape(fow, shape);
            shape.Texture         = Texture;
            shape.RotateToForward = RotateToForward;
            return(shape);
        }
        return(null);
    }
Example #2
0
    ///////////////////////////////////////////////////////////////////////////

    protected override void DrawCircle(FogCircle shape)
    {
        int      fogradius    = Mathf.RoundToInt(shape.Radius * _Map.PixelSize);
        int      fogradiussqr = fogradius * fogradius;
        DrawInfo info         = new DrawInfo(_Map, shape, fogradius, fogradius);

        // view angle stuff
        float dotangle = 1 - shape.Angle / 90;

        for (int y = info.yMin; y <= info.yMax; ++y)
        {
            for (int x = info.xMin; x <= info.xMax; ++x)
            {
                // is pixel within circle radius
                Vector2 centeroffset = new Vector2(x, y) - info.fogCenterPos;
                if (shape.VisibleCells == null && centeroffset.sqrMagnitude >= fogradiussqr)
                {
                    continue;
                }

                // check if in view angle
                if (dotangle > -0.99f && Vector2.Dot(centeroffset.normalized, info.fogForward) <= dotangle)
                {
                    continue;
                }

                // can see pixel
                Vector2_1 offset = new Vector2_1(x, y) - info.fogEyePos;
                if (!LineOfSightCanSee(shape, offset.vector2, fogradius))
                {
                    continue;
                }

                if (!LineOfSightCanSeeCell(shape, offset))
                {
                    continue;
                }

                Unfog(x, y, shape.GetFallOff(centeroffset.magnitude / (_Map.PixelSize * shape.Radius)));
            }
        }
    }
Example #3
0
 protected abstract void DrawCircle(FogCircle circle);