Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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);
            }
        }