NPC Code:
for (i = 0; i < 4; i ++) {
if(keydown(i)) {
this.x += vecx(i);
this.y += vecy(i);
break;
}
}
instead of 900 lines of key detection...you can do the same for playerdir detection.
learn vectorx, vectory. think of it as an array.
vecx = {0,1,0,1}
vecy = {1,0,1,0}
so vecx(0) would = 0;
vecx(1) would = 1;
vecx(2) would = 0;
vecx(3) would = 1;