Class MapGraph

  • All Implemented Interfaces:
    com.badlogic.gdx.ai.pfa.Graph<Node>, com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Node>

    public class MapGraph
    extends java.lang.Object
    implements com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Node>
    • Constructor Summary

      Constructors 
      Constructor Description
      MapGraph()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addNode​(Node node)
      Adds a node to the list of nodes in the graph, sets the node index and increases the index by one.
      void connectNodes​(Node fromNode, Node toNode)
      Creates a path from one node to another.
      void dispose()
      Called when this object is deleted.
      com.badlogic.gdx.ai.pfa.GraphPath<Node> findPath​(Node startNode, Node goalNode)
      Calculates a path from one node to another, populates the nodePath variable with the path it finds.
      com.badlogic.gdx.utils.Array<com.badlogic.gdx.ai.pfa.Connection<Node>> getConnections​(Node fromNode)
      Returns the list of paths that start at a particular node.
      int getIndex​(Node node)
      Returns the index of a particular Node instance.
      Node getNode​(float x, float y)
      Returns a node based on the x,y position of the node.
      int getNodeCount()
      Return the count of how many nodes are in our search space.
      com.badlogic.gdx.utils.Array<Node> getNodes()
      The Nodes in this MapGraph.
      com.badlogic.gdx.utils.Array<Path> getPaths()
      The connections in this MapGraph.
      Node getRandomNode()
      Returns a random node from this MapGraph.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MapGraph

        public MapGraph()
    • Method Detail

      • addNode

        public void addNode​(Node node)
        Adds a node to the list of nodes in the graph, sets the node index and increases the index by one.
        Parameters:
        node - the Node to add.
      • getNode

        public Node getNode​(float x,
                            float y)
        Returns a node based on the x,y position of the node.
        Parameters:
        x - X coord of the node to find.
        y - Y coord of the node to find.
        Returns:
        The node at x,y.
      • connectNodes

        public void connectNodes​(Node fromNode,
                                 Node toNode)
        Creates a path from one node to another.
        Parameters:
        fromNode - Node path comes from.
        toNode - Node path goes to.
      • dispose

        public void dispose()
        Called when this object is deleted.
      • findPath

        public com.badlogic.gdx.ai.pfa.GraphPath<Node> findPath​(Node startNode,
                                                                Node goalNode)
        Calculates a path from one node to another, populates the nodePath variable with the path it finds.
        Parameters:
        startNode - Node to start the search from
        goalNode - Node to finish search at
        Returns:
        A path of nodes to follow to get from start to finish
      • getIndex

        public int getIndex​(Node node)
        Returns the index of a particular Node instance.
        Specified by:
        getIndex in interface com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Node>
        Parameters:
        node - Node to get index for
        Returns:
        Int index for the node
      • getNodeCount

        public int getNodeCount()
        Return the count of how many nodes are in our search space.
        Specified by:
        getNodeCount in interface com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Node>
        Returns:
        Number of nodes on map.
      • getConnections

        public com.badlogic.gdx.utils.Array<com.badlogic.gdx.ai.pfa.Connection<Node>> getConnections​(Node fromNode)
        Returns the list of paths that start at a particular node.
        Specified by:
        getConnections in interface com.badlogic.gdx.ai.pfa.Graph<Node>
        Parameters:
        fromNode - Node to get paths from.
        Returns:
        Array of paths from node.
      • getRandomNode

        public Node getRandomNode()
        Returns a random node from this MapGraph.
        Returns:
        A random Node from this MapGraph.
      • getNodes

        public com.badlogic.gdx.utils.Array<Node> getNodes()
        The Nodes in this MapGraph.
        Returns:
        An Array of nodes in this graph.
      • getPaths

        public com.badlogic.gdx.utils.Array<Path> getPaths()
        The connections in this MapGraph.
        Returns:
        An Array of connections in this graph.