Old

This topic is 3710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Old [Edited by - Robert Colton on March 1, 2008 11:11:03 PM]

Share on other sites
If you want to determine "Manhattan" movement (cardinal directions only, make only one turn en-route to a given unmoving target point) on a step-by-step basis, you have to choose whether you prefer to move horizontally first, or vertically first.

if ( cX != dX ) {  if ( cX < dX )    cX += 1;  else    cX -= 1;} else {  if ( cY < dY )    cY += 1;  else    cY -= 1;}

That's for preferring to move across before up and down. Read cX = Current X, dX = Destination X.