コード例 #1
0
ファイル: FOVCalculator.cs プロジェクト: Jeffersah/FP1
        private static void RecursiveFOVHelper(Point source, I_Seeable[,] World, SimpleFraction minAngle, SimpleFraction maxAngle, int quad, int distance, int range, params object [] args)
        {
            if (minAngle.Compair(maxAngle) == 0 || distance >= range)
            {
                return;
            }

            bool           hasHitOpen    = false;
            SimpleFraction NewMin        = minAngle;
            int            numberOfTiles = (int)Math.Abs(Math.Floor(maxAngle.Subtract(minAngle).Multiply(distance)));
            //Console.Out.WriteLine("Quad {0}, Distance {1}: {2}->{3}", quad, distance, minAngle, maxAngle);
            Point firstTile = new Point((MainXMovement[quad] * distance + (int)Math.Ceiling(minAngle.MultiplyInverted(SubXMovement[quad] * distance)) + source.X),
                                        (MainYMovement[quad] * distance + (int)Math.Ceiling(minAngle.Multiply(SubYMovement[quad] * distance))) + source.Y);

            //Console.Out.WriteLine("First Tile : {0},{1} tot",firstTile, numberOfTiles);
            for (int i = 0; i < numberOfTiles; i++)
            {
                Point currentPoint = new Point(firstTile.X + SubXMovement[quad] * i, firstTile.Y + SubYMovement[quad] * i);
                if (currentPoint.X >= World.GetLength(0) || currentPoint.X < 0 || currentPoint.Y >= World.GetLength(1) || currentPoint.Y < 0)
                {
                    if (hasHitOpen)
                    {
                        RecursiveFOVHelper(source, World, NewMin, maxAngle, quad, distance + 1, range, args);
                    }
                    return;
                }

                I_Seeable current = World[currentPoint.X, currentPoint.Y];
                //current.debug("" + i);
                current.See(args);

                if (current.isSightBlocking())
                {
                    if (hasHitOpen)
                    {
                        // current.debug("M" + new SimpleFraction(currentPoint.Y, currentPoint.X - SubXMovement[quad]).toString());
                        RecursiveFOVHelper(source, World, NewMin, new SimpleFraction(currentPoint.Y, currentPoint.X - SubXMovement[quad]), quad, distance + 1, range, args);
                        hasHitOpen = false;
                    }
                    else
                    {
                        // current.debug("m" + new SimpleFraction(currentPoint.Y + SubYMovement[quad], currentPoint.X + SubXMovement[quad]).toString());
                        NewMin = new SimpleFraction(currentPoint.Y + SubYMovement[quad], currentPoint.X + SubXMovement[quad]);
                    }
                }
                else
                {
                    if (!hasHitOpen)
                    {
                        // current.debug("" + i + "H");
                    }
                    hasHitOpen = true;
                }
            }

            if (hasHitOpen)
            {
                RecursiveFOVHelper(source, World, NewMin, maxAngle, quad, distance + 1, range, args);
            }
        }
コード例 #2
0
ファイル: FOVCalculator.cs プロジェクト: Jeffersah/FP1
 public int Compair(SimpleFraction s2)
 {
     return((Numerator * s2.Denominator) - (s2.Numerator * Denominator));
 }