Jump to content

Generating straight path


Recommended Posts

Posted (edited)

if you're ignoring obstacles, you could just do something like this

Position source = myPosition();
Position dest = new Position(x, y, z);

List<Position> path = new ArrayList<>();
Position tmp = source;
while (!tmp.equals(dest)) {
    int xOff = Integer.compare(dest.getX(), tmp.getX());
    int yOff = Integer.compare(dest.getY(), tmp.getY());
    tmp = tmp.translate(xOff, yOff);
    path.add(tmp);
}

Written in hand, so watch for errors. Not sure why you want to use a region in the form of a list of positions

Edited by FrostBug

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...