Jump to content

Region positions


Ayylmao420

Recommended Posts

Untested but it seems like it could work

/**
 * 
 * @param position to check if it is within the region
 * @param player the current position of the player (myPosition())
 * @return true if the position is within the region with respect to our players position
 */
public boolean isReachable(Position position, Position player) {
    int HOW_BIG_IS_REGION = 20;//idk how big a region is
    Position insidePos = new Position(position);
    int distance = insidePos.distance(player);
    
    //If the distance from the region is less than our current position, it is reachable
    return distance < HOW_BIG_IS_REGION;
}
Just noticed there's already a function for this:

map.canReach(position);
Edited by Hayase
Link to comment
Share on other sites

not sure why you want to do it

 

but something like this is probably the most efficient, performance-wise

	private boolean isLoaded(Position pos) {
		return pos.getX() > getMap().getBaseX() && pos.getX() < (getMap().getBaseX() + 104)
				&& pos.getY() > getMap().getBaseY() && pos.getY() < getMap().getBaseY() + 104;
	}

Regions are 104x104

 

EDIT: Didn't test above method, btw

Edited by FrostBug
  • Like 2
Link to comment
Share on other sites

not sure why you want to do it

 

but something like this is probably the most efficient, performance-wise

	private boolean isLoaded(Position pos) {
		return pos.getX() > getMap().getBaseX() && pos.getX() < (getMap().getBaseX() + 104)
				&& pos.getY() > getMap().getBaseY() && pos.getY() < getMap().getBaseY() + 104;
	}

Regions are 104x104

 

EDIT: Didn't test above method, btw

Should works, thanks boge.png

 

EDIT; For custom walker.

Edited by Ayylmao420
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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