Hi, I am trying to make a pathfinding system, and the pathfinding part is done however I don’t know how to change the start or end point. Down below is some of my code. Would be nice if i could get some inspiration how to move the end og start point.
int rows=99;
int cols=99;
int startx=0;
int starty=0;
float bred=10;
float hoj=10;
boolean run=false;
Cell start;
Cell end;
Cell[][] grid=new Cell[cols][rows];
void setup(){
frameRate(200);
size(1000,1000,P2D);
//fullScreen(P2D);
for(int i=0;i<cols;i++){
for(int j=0;j<rows;j++){
grid[i][j]=new Cell(startx+i*bred,starty+j*hoj,bred,hoj);
}
}
start=grid[0][0]; //start
end=grid[rows-1][cols-1]; //end
start.wall=false;
end.wall=false;
}
void draw(){
for (int i=0; i<cols;i++){
for(int j=0; j<rows;j++){
grid[i][j].display(255,255,255);
}
}
start.display(0,255,0);
end.display(225,125,0);
}
void mouseDragged(){
// if inside preset start or end move it
}
class Cell{
// til pathfinding
float f=0;
float g=0;
float h=0;
// til kontruktion
float i;
float j;
float bredde;
float hojde;
boolean wall=false;
//farve
int rod=255;
int gron=255;
int bla=255;
//previous
Cell previous = null;
//neighbors
Cell[] neighbors = new Cell[0];
//ArrayList<Cell> neighbors = new ArrayList<Cell>();
Cell(float x, float y,float b, float h){
i=x;
j=y;
bredde=b;
hojde=h;
//wall or not
if (random(0,1)<0.40){
wall=true;
}
}
void display(int x, int y, int z){
if (wall){
fill(0);
rect(i,j,bredde,hojde);
}else{
fill(x,y,z);
rect(i,j,bredde,hojde);
}
}
}
Sorry for some of the variable-names. I am danish but i hope you don’t mind. The code shouldn’t be that complicated