Ejemplo n.º 1
0
    /**
     * Add the passed node as this node's successor
     */
    public void AddSuccessor(Node n, ref GraphOfMap graph)
    {
        Node succesor = graph.nodeWith(n);

        _successors.Add(succesor);
        //Debug.Log("succesor is: " + succesor.GetX() + ", " + succesor.GetY());
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Add neighbouring nodes only if they are perpendicular to this one
 /// i.e. if they are withing 1 square reach + are not diagonals
 /// </summary>
 /// <param name="graph"></param>
 public void AddNeighbours(ref GraphOfMap graph)
 {        
     for (int i = 0; i < graph.map.Count; i++)
     {
         Node node = graph.map[i];
         if (!node.Equals(this) && ((Mathf.Abs(x - node.x) <= 1) && (Mathf.Abs(y - node.y) <= 1)) &&
             ((Mathf.Abs(x - node.x)) + (Mathf.Abs(y - node.y)) < 2))
         {
             AddSuccessor(node, ref graph);
         }
     }
 }
Ejemplo n.º 3
0
    /**
     * Adds this node horizontal neighbour as it successors
     */
    public void AddNeighbour(float direction, ref GraphOfMap graph)
    {
        for (int i = 0; i < graph.ReturnGraph().Count; i++)
        {
            Node node = graph.ReturnGraph().ElementAt(i);

            if (node.GetX() == GetX() - direction && node.GetY() == GetY())
            {
                AddSuccessor(node, ref graph);
                //Debug.Log("successor " + node.GetX() +", " + node.GetY());
            }
        }
    }
Ejemplo n.º 4
0
    /*
     * Creates a jumping route
     * Neighbours of the current node become sucessor of the passed node (which should have higher Y coordinates)
     * Also add successors the other way
     */
    private void AddSuccessorForRising(Node platformNode, ref GraphOfMap graph, float nodeDistance)
    {
        for (int j = 0; j < graph.ReturnGraph().Count; j++)
        {
            Node node = graph.ReturnGraph().ElementAt(j);

            if ((node.GetX() == this.GetX() - nodeDistance || node.GetX() == this.GetX() + nodeDistance) && node.GetY() == this.GetY() && !node.gameObject.GetComponent <Collider2D>().IsTouchingLayers(_enviLayer))
            {
                node.AddSuccessor(platformNode, ref graph);
                platformNode.AddSuccessor(node, ref graph);

                DeleteSuccessor(node, ref graph);
                node.DeleteSuccessor(this, ref graph);
            }
        }
    }
    void Awake()
    {
        _detectLiving = 1 << LayerLiving;
        _detectEnvi   = 1 << LayerEnvi;
        _detectItem   = 1 << LayerItem;

        LayerMask _detectLayerMask0 = _detectLiving | _detectEnvi;

        _detectLayerMask = _detectLayerMask0 | _detectItem;

        _sightDistance = 4;

        _patrolBehav = GetComponentInParent <Patrol>();

        _gameMap = GameObject.FindGameObjectWithTag("Map");
        _graph   = _gameMap.GetComponent <NodeGenerator>().ReturnGeneratedGraph();
    }
Ejemplo n.º 6
0
    /**
     * Finds the node that is above the current node
     */
    private Node FindPlatformNode(float nodeDistance, ref GraphOfMap graph)
    {
        Node platformNode = null;

        for (int i = 0; i < graph.ReturnGraph().Count; i++)
        {
            Node node = graph.ReturnGraph().ElementAt(i);

            if (node.GetX() == this.GetX() &&
                node.GetY() == this.GetY() + nodeDistance)
            {
                platformNode = node;
                return(platformNode);
            }
        }

        return(platformNode);
    }
Ejemplo n.º 7
0
    /**
     * If this node is the position of a rising platform, add the node above it as its horizontal sucecssor's successor
     * If the node is in the position of a platform, add the successors to noed above to allow movement across it.
     */
    void OnTriggerStay2D(Collider2D col)
    {
        float      nodeDistance = GetComponentInParent <NodeGenerator>().NodeDistance;
        GraphOfMap graph        = _gameMap.GetComponent <NodeGenerator>().ReturnGeneratedGraph();

        if (col.gameObject.layer == 10 && col.gameObject.tag == "RisingPlatform" && !_addedRising)
        {
            //Debug.Log("node is " + GetX() + ", " + GetY());
            Node risingNode = FindPlatformNode(nodeDistance, ref graph);

            AddSuccessorForRising(risingNode, ref graph, nodeDistance);

            _addedRising = false;
        }

        if (col.gameObject.layer == 10 && col.gameObject.tag == "Platform")
        {
            Node platformNode = FindPlatformNode(nodeDistance, ref graph);

            platformNode.AddNeighbour(nodeDistance, ref graph);
            platformNode.AddNeighbour(-nodeDistance, ref graph);
        }
    }
    /*
     * creates a map, consisting of nodes which can be use for determining coordinates/location
     * Once map has been generated, add neighbours (horizontal only) to each node, add null pointer otherwise
     */
    void Awake()
    {
        _nodeSize = Node.GetComponent <CircleCollider2D>().radius * 2;
        const float nodeGap = 0.5f;

        NodeDistance = _nodeSize + nodeGap;

        //was trying to delete node game objects

        /*GameObject[] guards = GameObject.FindGameObjectsWithTag("Guard");
         * _guardsPatrol = new Patrol[guards.Length];
         * for (int i = 0; i < guards.Length; i++)
         * {
         *  _guardsPatrol[i] = guards[i].GetComponent<Patrol>();
         * }
         *
         * _playerMap = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMapRelation>();*/


        _graph             = new GraphOfMap(); // where map is
        _graph.AbstractMap = new List <Node>();

        GenerateNodes();
    }
Ejemplo n.º 9
0
	void Start ()
	{	    

        graph = new GraphOfMap();
        graph.map = new List<Node>();

	    for (int i = 0; i < mapSize; i++)
	    {
	        for (int j = 0; j < mapSize; j++)
	        {
	            GameObject newTile = (GameObject) Instantiate(Tile, new Vector3(i * tileSize, 1, j * tileSize), Tile.transform.rotation);
                newTile.transform.SetParent(transform);
	            Node tileNode = new Node {x = i, y = j, Successors = new List<Node>()};
	            newTile.GetComponent<TileBehaviour>().assignNode(tileNode);
	            graph.nodeWith(tileNode);
	        }
	    }

	    for (int i = 0; i < graph.map.Count; i++)
	    {
	        graph.map[i].AddNeighbours(ref graph);
	    }

	}
Ejemplo n.º 10
0
 /*
  * Sets up script dependencies
  */
 void Awake()
 {
     _playerDetection = gameObject.GetComponentInChildren <PlayerDetection>();
     _pathfinding     = gameObject.GetComponent <Pathfinding>();
     map = GameObject.FindGameObjectWithTag("Map").GetComponent <NodeGenerator>().ReturnGeneratedGraph();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Add successor to this node, indicating the successor can be reached from this node in 1 step
 /// </summary>
 /// <param name="node"></param>
 /// <param name="graph"></param>
 private void AddSuccessor(Node node, ref GraphOfMap graph)
 {
     Node successor = graph.nodeWith(node);
     Successors.Add(successor);        
 }
Ejemplo n.º 12
0
 /**
  * Adds the node to the passed graph
  */
 public void SetUpNode(ref GraphOfMap graph)
 {
     _successors = new List <Node>();
     Node newNode = graph.nodeWith(this);
 }
Ejemplo n.º 13
0
    private void DeleteSuccessor(Node successor, ref GraphOfMap graph)
    {
        Node node = graph.nodeWith(successor);

        _successors.Remove(node);
    }