Package com.mygdx.auber.Pathfinding
Class MapGraph
- java.lang.Object
-
- com.mygdx.auber.Pathfinding.MapGraph
-
-
Constructor Summary
Constructors Constructor Description MapGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddNode(Node node)Adds a node to the list of nodes in the graph, sets the node index and increases the index by one.voidconnectNodes(Node fromNode, Node toNode)Creates a path from one node to another.voiddispose()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.intgetIndex(Node node)Returns the index of a particular Node instance.NodegetNode(float x, float y)Returns a node based on the x,y position of the node.intgetNodeCount()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.NodegetRandomNode()Returns a random node from this 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 fromgoalNode- 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:
getIndexin interfacecom.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:
getNodeCountin interfacecom.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:
getConnectionsin interfacecom.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.
-
-