Making an enemy follow a path made by pathfinder java

OK, so I been searching and searching for pathfinder stuff in java and finally found how to make a pathfinder that can avoid walls. But my trouble is how to make the enemy follow the path. I been looking it up but been getting results from unity, gamemaker and a few other nonjava junk. I tried finding tutorials but been in wrong language, so does anyone know how to make my enemy follow the path my pathmaker made? Here the code I’m using to make my path I can’t find the next step.

// here is the main script

import pathfinder.*;
Path p;
Control con = new Control();
int w = 25;
ArrayList<Wall> wall = new ArrayList<Wall>(); 
// PathFinding_01
Graph graph;
// These next 2 are only needed to display 
// the nodes and edges.
GraphEdge[] edges;
GraphNode[] nodes;
GraphNode[] route;
// Pathfinder algorithm
IGraphSearch pathFinder;

// Used to indicate the start and end nodes as selected by the user.
GraphNode startNode, endNode;

void setup() {
  size(650, 650);
  textSize(8);
  p = new Path();
  // Create graph
  p.createGraph();
  // Get nodes and edges
  nodes = graph.getNodeArray();
  edges = graph.getAllEdgeArray();
  // Now get a path finder object
  pathFinder = new GraphSearch_Astar(graph);
  // Now get a route between 2 nodes
  // You can change the parameter values but they must be valid IDs
  pathFinder.search(2, 550);
  route = pathFinder.getRoute();
}

void draw() {
  background(0);
  p.drawGraph();
  p.drawPath();
  for (Wall w: wall){
    w.show();
  }
  noLoop();
}

// here control where I would be placing the walls up

class Control{
  void update(){
    graph.removeNode(25);
    wall.add(new Wall(0,1));
  }
}

// here the pathmaker

class Path{
  void drawGraph() {
    // Edges first
    strokeWeight(2);
    stroke(180, 180, 200);
    for (int i = 0; i < edges.length; i++) {
      GraphNode from = edges[i].from();
      GraphNode to = edges[i].to();
      line(from.xf(), from.yf(), to.xf(), to.yf());
    }
    // Nodes next
    noStroke();
    fill(240, 255, 240);
    for (int i = 0; i < nodes.length; i++) {
      GraphNode node = nodes[i];
      ellipse(node.xf(), node.yf(), 6, 6);
      text(node.id(), node.xf() + 4, node.yf() - 2);
    }
  }
  void drawPath() {
    strokeWeight(10);
    stroke(200, 255, 200, 160);
    for (int i = 1; i < route.length; i++) {
      GraphNode from = route[i-1];
      GraphNode to = route[i];
      line(from.xf(), from.yf(), to.xf(), to.yf());
    }
  }
  void createGraph() {
    graph = new Graph();
    // Create and add node
    GraphNode node;
    int node_id = 0;
    for (int v = 0; v < w; v++) {
      for (int h = 0; h < w; h++) {
        node = new GraphNode(node_id, h * (w + 1), w + v * w);
        graph.addNode(node);
        node_id++;
      }
    }
    con.update();
    // Create horizontal edges
    for (int v = 0; v < w; v++) {
      for (int h = 1; h < w; h++) {
        graph.addEdge(v * w + h-1, v * w + h, 0, 0);
      }
    }
    // Create vertical edges
    for (int h = 0; h < w; h++) {
      for (int v = 1; v < w; v++) {
        graph.addEdge(v * w - w + h, v * w + h, 0, 0);
      }
    }
  }
}

// here the wall

class Wall{
  int x, y;
  Wall(int x, int y){
    this.x = x * w;
    this.y = y * w;
  }
  
  void show(){
    noStroke();
    fill(255,0,0);
    rect(x,y,w,w);
  }
}

the enemy haven’t been made because I found no code to make it do what I want. So does anyone know how to make the enemy follow the path made by this pathfinder. I’ll be happy with tutorials as long as they are in java

It is clear you cannot find the code as you have tried, from what one get from your previous posts. Please, don’t create duplicate posts. Keep working in the same post if you are addressing the same question.

Now, when you want to do something, you need to understand what your code does before you attempt to modify or include new features. What does your code do? I had a look at it and I am not sure what you mean with implementing an enemy.

What is the purpose of your project? It will help if you provide more details about what you are trying to do.

Kf

that code there draws a point from A to B now I want my enemy to go from A to B. I don’t even know if it is even possible to make an enemy follow the path.
I made a spaceship game that has a bunch of different paths on it & thought it be easier to just make the enemies use a pathfinding ability. So basically the enemy appears uses path finding and walks to the end point. There are like 12 maps in my gam and over 70 paths. So I’m trying to find the shortest way to make my enemies move from a to b.
map

I want to place a map like this up & then copy the path for my enemy to follow. The way I’m doing it now takes forever.

I am not familiar with this library. You should look up the documentation. If you want an enemy to follow this path, I am guessing is doable as you can have access to the path:

ellipse(node.xf(), node.yf(), 6, 6);

If you are able to draw points, then you are able to store them. The enemy could simply follow this stored points.

Kf

ty & I been trying to look them up. So I can assign the enemy the node points? But then that would be like what I’m already doing if I gotta assign it each point. ATM I’m giving it a sx and sy to move to, it making the code long so I thought maybe pathfinding could make it simple. ty for respond.