Hope this can be useful...
NPC Code:
if (playerenters) {
timeout = 0.05;
}
if (playerenters&&isleader) {
i = random(0,2);
if (i<2) {this.mode = 0;}
if (i>1&&i<3) {this.mode = 1;}
timeout = 0.05;
}
if (timeout) {
timeout = 0.05;
}
if (timeout&&this.mode=0) {
x -= 0.2;
timeout = 0.05;
}
if (timeout&&this.mode=1) {
x += 0.2;
timeout = 0.05;
}
if (timeout&&onwall(x,y+1)&&this.mode=0) {
this.mode = 1;
}
if (timeout&&onwall(x+2,y+1)&&this.mode=1) {
this.mode = 0;
}
if (wasshot) {
message BINGO!;
sleep 2;
message ;
timeout = 0.05;
}
Note: this was made for a 32x32 image