I need to work out the distance between each of the soldiers but I cant work out how to because they all have come from the same xPos and yPos and everything i find online is for x1, y1, x2, y2 sort of situations.
the idea is that they spawn randomly and then can move to attack eachother but i need to know the distance between them before i can go on
public class Soldier {
double xPos;
double yPos;
public Soldier(/*double distance, double speed*/) {
double lower = 0;
double upper = 100; //setting the upper and lower limits for the soldiers
xPos = Math.random() * (upper - lower) + lower;
yPos = Math.random() * (upper - lower) + lower; //creating x and y values
xPos = Math.round(xPos * 10) / 10.0d;
yPos = Math.round(yPos * 10) / 10.0d; //making sure the x and y value is to 1dp
System.out.println("(" + xPos + ", " + yPos + ")"); //printing the location
}
}
and my main class is,
public class Main {
public static void main(String[] args) {
Soldier Cavalier = new Soldier(/*5.9, 1*/);
Soldier Pikeman = new Soldier(/*10.3, 12.6*/);
Soldier Crossbowman = new Soldier(/*4.9, 3*/);
System.out.println();
}
}