Created
August 27, 2021 17:43
-
-
Save seebs/b13371b5560a45c29389fb546a47a23a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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