Skip to content

Instantly share code, notes, and snippets.

@seebs
Created August 27, 2021 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seebs/b13371b5560a45c29389fb546a47a23a to your computer and use it in GitHub Desktop.
Save seebs/b13371b5560a45c29389fb546a47a23a to your computer and use it in GitHub Desktop.
/* I wrote this in 1990. I was at the time very proud of replacing two
* pages of Pascal code with an inner loop that was basically three lines.
*
* Today, I would... not do it this way.
* -seebs
*
* For meditation: http://thecodelesscode.com/case/13
*/
void
moveto(int *x, int *y, int tx, int ty) {
int dev,sx,sy;
int *g,*l,li,gi,sl,sg;
gi=abs(tx-*x); li=abs(ty-*y);
sx=sign(tx-*x); sy=sign(ty-*y);
if(gi > li) {
g=x; l=y; sl=sy; sg=sx;
} else {
g=y; l=x; dev=li; li=gi; gi=dev; sl=sx; sg=sy;
}
dev=0;
do { dev+=(li << 1); *g+=sg;
if(dev>gi) { dev-=(gi << 1); *l += sl; }
} while(!(*x==tx && *y==ty) && !loc_solid(*x,*y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment