예제 #1
0
        private void CastLight(Vector2Int origin, int sightMod, int row, float start, float end, int xx, int xy, int yx, int yy)
        {
            float newStart = 0.0f;

            if (start < end)
            {
                return;
            }

            bool blocked = false;

            for (int distance = row; distance <= sightMod && blocked == false; distance++)
            {
                int deltaY = -distance;
                for (int deltaX = -distance; deltaX <= 0; deltaX++)
                {
                    int   currentX   = origin.x + deltaX * xx + deltaY * xy;
                    int   currentY   = origin.y + deltaX * yx + deltaY * yy;
                    float leftSlope  = (deltaX - 0.5f) / (deltaY + 0.5f);
                    float rightSlope = (deltaX + 0.5f) / (deltaY - 0.5f);

                    if (!(currentX >= 0 && currentY >= 0 && currentX < m_Board.Vision.GetLength(0) && currentY < m_Board.Vision.GetLength(1)) || start < rightSlope)
                    {
                        continue;
                    }
                    else if (end > leftSlope)
                    {
                        break;
                    }

                    if (Math.Sqrt(deltaX * deltaX + deltaY * deltaY) <= sightMod)
                    {
                        m_Board.Visible(currentX, currentY);
                    }

                    if (blocked)
                    {
                        if (m_Board.IsObstacle(currentX, currentY))
                        {
                            newStart = rightSlope;
                            continue;
                        }
                        else
                        {
                            blocked = false;
                            start   = newStart;
                        }
                    }
                    else
                    {
                        if (m_Board.IsObstacle(currentX, currentY) && distance < sightMod)
                        {
                            blocked = true;
                            CastLight(origin, sightMod, distance + 1, start, leftSlope, xx, xy, yx, yy);
                            newStart = rightSlope;
                        }
                    }
                }
            }
        }
예제 #2
0
        protected void DiscoverTile(float x, float y, Vector2Int origin, int perception)
        {
            float oX = origin.x + 0.5f;
            float oY = origin.y + 0.5f;

            for (int i = 0; i <= perception; i++)
            {
                Vector2Int position = new Vector2Int((int)oX, (int)oY);

                if (m_Board.Contains(position.x, position.y) == false)
                {
                    continue;
                }

                m_Board.Visible(position.x, position.y);

                if (m_Board.IsObstacle(position.x, position.y) == true)
                {
                    continue;
                }

                oX += x;
                oY += y;
            }
        }
예제 #3
0
        private void Go(Vector2Int origin, int recursion, int visionDistance, double theta1, double theta2)
        {
            if (recursion > visionDistance)
            {
                return;
            }
            else if (recursion <= 0)
            {
                return;
            }

            List <ArcPoint> circle     = Circles[recursion];
            int             circleSize = circle.Count;

            bool wasObstacle = false;
            bool foundClear  = false;

            for (int i = 0; i < circleSize; i++)
            {
                ArcPoint point = circle[i];
                int      pX    = origin.x + point.X;
                int      pY    = origin.y + point.Y;

                if (!Board.Contains(pX, pY))
                {
                    wasObstacle = true;
                    continue;
                }

                if (point.Lagging < theta1 && point.Theta != theta1 && point.Theta != theta2)
                {
                    continue;
                }

                if (point.Leading > theta2 && point.Theta != theta1 && point.Theta != theta2)
                {
                    continue;
                }

                Board.Visible(pX, pY);

                bool isObstacle = Board.IsObstacle(pX, pY);

                if (isObstacle == true)
                {
                    if (wasObstacle == true)
                    {
                        continue;
                    }
                    else if (foundClear == true)
                    {
                        double runEndTheta   = point.Leading;
                        double runStartTheta = theta1;

                        if (recursion < visionDistance)
                        {
                            Go(origin, recursion + 1, visionDistance, runStartTheta, runEndTheta);
                        }

                        wasObstacle = true;
                    }
                    else
                    {
                        if (point.Theta == 0.0f)
                        {
                            theta1 = 0.0f;
                        }
                        else
                        {
                            theta1 = point.Leading;
                        }
                    }
                }
                else
                {
                    foundClear = true;
                    if (wasObstacle == true)
                    {
                        ArcPoint last = circle[i - 1];
                        theta1 = last.Lagging;

                        wasObstacle = false;
                    }
                    else
                    {
                        wasObstacle = false;
                        continue;
                    }
                }
                wasObstacle = isObstacle;
            }
            if (recursion < visionDistance)
            {
                Go(origin, recursion + 1, visionDistance, theta1, theta2);
            }
        }