[code]if (created) {
showcharacter;
setcharprop #1,sword1.png;
setcharprop #2,shield1.png;
setcharprop #3,head0.png;
setcharprop #8,body.png;
setcharprop #C0,orange;
setcharprop #C1,white;
setcharprop #C2,blue;
setcharprop #C3,red;
setcharprop #C4,black;
shieldpower = 1;
swordpower = 1;
hearts = 3;
dir = 2;
dirT = 3;
hurtc = 0;
hit = 0;
t = 0.05;
deadtime = 10;
this.speed = 0.25;
timeout = t;
}
if (washit && mode != 4) {
setcharani hurt,;
hearts -= playerswordpower/2;
if (hearts == 0) mode = 4;
else {
mode = 3;
hurtdx = dx/dist;
hurtdy = dy/dist;
hurtc = 0.35;
}
}
if (timeout) {
dx = playerx - x;
dy = playery - y;
dist = (dx^2 + dy^2)^0.5;
hit = (hit > 0) ? hit-t:0;
if (hurtc > 0) {
mode = 3;
hurtc -= t;
}
if (mode == 0) {
setcharani idle,;
idle += t;
if (idle == 3) {
mode = 1;
idle = 0;
turn();
}
search();
} else if (mode == 1) {
setcharani walk,;
dirS += t;
if (dirS == dirT) turn();
if (!onwall(x+(dir==1?0.25:2.5)+(vecx(dir)*this.speed),y+2)) x += vecx(dir)*this.speed;
else turn();
if (!onwall(x+1.5,y+(dir==0?0.75:3)+(vecy(dir)*this.speed))) y += vecy(dir)*this.speed;
else turn();
search();
} else if (mode == 2) {
setcharani walk,;
idle = 0;
dir = getdir(dx,dy);
if (!onwall(x+(dir==1?0.25:2.5)+vecx(dx>0?3:1)*this.speed,y+2)) x += (dx/dist)*this.speed;
if (!onwall(x+1.5,y+(dir==0?0.75:3)+vecy(dy>0?2:0)*this.speed)) y += (dy/dist)*this.speed;
search();
} else if (mode == 3) {
if (!onwall(x+(dir==1?0.25:2.5)+vecx(hurtdx>0?3:1)*this.speed,y+2)) x -= hurtdx;
if (!onwall(x+1.5,y+(dir==0?0.75:3)+vecy(hurtdy>0?2:0)*this.speed)) y -= hurtdy;
if (hurtc == 0) search();
} else if (mode == 4) {
setcharani dead,;
hearts = 3;
sleep deadtime;
mode = 0;
}
timeout = t;
}
function search() {
if (dist < 3 && hit == 0) {
setcharani sword,;
sleep 0.1;
hit = 0.3;
} else if (dist > 10) mode = (mode == 0) ? 0:1;
else mode = 2;
}
function turn() {
dirS = 0;
dirT = int(random(2,5));
dir = int(random(-0.5,3.49)+0.5);
}
[/code]
Problem is that the NPC can slide through walls while chasing. Example: there is a wall between the player and NPC so the NPC is running at the wall, if there is a wall above it as well it can slide through it while still facing the direction of the player.