예제 #1
0
    public void UpdateState()
    {
        Debug.Log("CStatePath::UpdateState() called");
        if (nextDest == null)
        {
            newPathing();
            nextDest = m_Pathing.Dequeue();
        }

        if (nextDest == null)
        {
            return;
        }

        m_GO.transform.Translate((nextDest.position - (Vector2)m_GO.transform.position).normalized * m_Owner.GetStats().MoveSpeed *Time.deltaTime);

        if ((nextDest.position - (Vector2)m_GO.transform.position).magnitude <= m_Owner.GetStats().MoveSpeed *Time.deltaTime)
        {
            if (m_Pathing.Count <= 0)
            {
                newPathing();
            }
            nextDest = m_Pathing.Dequeue();
        }
    }
예제 #2
0
    public void UpdateState()
    {
        if (nextDest == null || m_Pathing == null)
        {
            m_Owner.StateMachine.SetNextState("StateIdle");
            return;
        }

        if ((m_GO.transform.position - GameObject.FindGameObjectWithTag("Player").transform.position).magnitude <= 5)
        {
            Debug.Log("Dist to plyer = " + (m_GO.transform.position - GameObject.FindGameObjectWithTag("Player").transform.position).magnitude);
            m_Owner.Target = GameObject.FindGameObjectWithTag("Player");
            m_Owner.StateMachine.SetNextState("StateChase");
        }

        //Move to next point
        Vector2 forwardVec = nextDest.position - (Vector2)m_GO.transform.position;

        //Reaching next point in the this frame
        if (forwardVec.magnitude <= m_Owner.GetStats().MoveSpeed *Time.deltaTime)
        {
            m_GO.transform.Translate(forwardVec.normalized * m_Owner.GetStats().MoveSpeed *Time.deltaTime);
            if (m_Pathing.Count > 0) //still have more point till final point
            {
                nextDest = m_Pathing.Dequeue();
            }
            else //Reached
            {
                m_GO.GetComponent <IEnemy>().StateMachine.SetNextState("StatePatrol");
            }
        }
        else
        {
            m_GO.transform.Translate(forwardVec.normalized * m_Owner.GetStats().MoveSpeed *Time.deltaTime);
        }

        //Make way if it is blocked
        if ((m_lastknowposition - m_GO.gameObject.transform.position).magnitude < 1)
        {
            m_blockedTime += Time.deltaTime;
            if (m_blockedTime >= 1)
            {
                Vector2 makeleft = -Vector3.Cross(forwardVec, Vector3.forward).normalized;
                m_GO.transform.Translate(makeleft * m_Owner.GetStats().MoveSpeed *Time.deltaTime);
            }
        }
        else
        {
            m_lastknowposition = m_GO.gameObject.transform.position;
            m_blockedTime      = 0;
        }
    }
예제 #3
0
    public void EnterState()
    {
        Debug.Log("CStatePath::EnterState() called");

        List <CTRoom> rmList          = CTDungeon.Instance.Floors[CTDungeon.Instance.currentFloor].Rooms;
        int           randomDestIndex = Random.Range(0, rmList.Count - 1);

        m_Pathing = CTDungeon.Instance.BFS_ToRoom(m_Owner.RoomCoordinate, rmList[randomDestIndex].coordinate);
        if (m_Pathing != null)
        {
            nextDest = m_Pathing.Dequeue();
        }
    }
예제 #4
0
        /* --------------------------------------------------------------------------------- *\
        *  Description:
        *   Paint a single isle using DFS to find all relevant pixels
        *
        *  Parameters:
        *   int n_src_x:
        *   int n_src_y:
        *   int n_pixel_ind:
        *   int n_color:
        *   CBoard _board:
        \* --------------------------------------------------------------------------------- */
        private static void paint_isle(int n_src_x, int n_src_y, int n_pixel_ind, int n_color, CBoard _board)
        {
            Stack <CPathNode> _path = new Stack <CPathNode>();

            paint_n_push(n_src_x, n_src_y, n_pixel_ind, n_color, _board, _path);

            while (0 != _path.Count)
            {
                bool b_is_painted = false;

                CPathNode _path_node = _path.Peek();
                int       n_center_x = _path_node.x;
                int       n_center_y = _path_node.y;

                for (int i = _path_node.next_neighbour_ind; i < ma_neighbours.Length; i++)
                {
                    int n_neighbour_x = n_center_x + ma_neighbours[_path_node.next_neighbour_ind].Item1;
                    int n_neighbour_y = n_center_y + ma_neighbours[_path_node.next_neighbour_ind].Item2;

                    _path_node.next_neighbour_ind++;

                    if (0 > n_neighbour_x || _board.width <= n_neighbour_x)
                    {
                        continue;
                    }
                    if (0 > n_neighbour_y || _board.height <= n_neighbour_y)
                    {
                        continue;
                    }

                    int n_neighbour_ind = _board.pixel_ind(n_neighbour_x, n_neighbour_y);

                    if (_board.is_black_pixel(n_neighbour_ind))
                    {
                        paint_n_push(n_neighbour_x, n_neighbour_y, n_neighbour_ind, n_color, _board, _path);
                        b_is_painted = true;
                        break;
                    }
                }

                if (b_is_painted)
                {
                    continue;
                }

                _path.Pop();
            }
        } // paint_isle()
예제 #5
0
    public void EnterState()
    {
        List <CTRoom> rmList          = CTDungeon.Instance.Floors[CTDungeon.Instance.currentFloor].Rooms;
        int           randomDestIndex = Random.Range(0, rmList.Count - 1);

        m_Pathing = CTDungeon.Instance.BFS_ToRoom(m_Owner.RoomCoordinate, rmList[randomDestIndex].coordinate);
        if (m_Pathing != null)
        {
            if (m_Pathing.Count > 0)
            {
                nextDest = m_Pathing.Dequeue();
            }
        }
        else
        {
            m_Owner.StateMachine.SetNextState("StateIdle");
        }

        m_lastknowposition = m_GO.gameObject.transform.position;
    }