Thread: NPC Baddies...
View Single Post
  #3  
Old 08-01-2001, 03:28 AM
Guest
Posts: n/a


NPC Code:

timereverywhere;
if (created){
showcharacter;
setcharprop #n,Mace Baddy;
setcharprop #1,blankbow.gif;
setcharprop #2,blankbow.gif;
hearts=3;
hurtdx=0;
hurtdy=0;
}
if (playerenters||wasthrown){
dirgo={0,-1,-1,0,0,1,1,0};
maceangle={5,3.5,2,.5};
this.speed=.4;
this.macespeed=1.5;
this.pow=1;
this.macepow=2;
swordpower=0;
shieldpower=0;
timeout=.05;
}
if (timeout&&isleader){
if (hearts>0&&this.hit!=1&&this.attack!=1){
for (i=0;i<5;i++){
hideimg i;
}
if (sprite<8){
sprite++;
}else{
sprite=1;
}
this.distx=abs(playerx-x);
this.disty=abs(playery-y);
if (this.distx<=this.disty){
if (playery<y)dir=0;
if (playery>y)dir=2;
}else{
if (playerx<x)dir=1;
if (playerx>x)dir=3;
}
this.dist=((this.distx^2)+(this.disty^2))^.5;
if (this.dist<=8){
this.attack=1;
this.step=0;
sprite=6;
this.angle=maceangle[dir];
this.flyx = x+.5;
this.flyy = y+1.25;
if (dir==0||dir==2) this.flyx-=0.5;
if (dir==1) this.flyx+=0.5;
}
if (this.distx==0){
this.addy=this.speed;
}else if (this.disty==0){
this.addx=this.speed;
}else if (this.distx>this.disty){
this.ratio=this.disty/this.distx;
this.addx=this.speed;
this.addy=this.speed*this.ratio;
}else if (this.disty>this.distx){
this.ratio=this.distx/this.disty;
this.addy=this.speed;
this.addx=this.speed*this.ratio;
}
if (y<playery&&!onwall(x+1.5,y+3+this.addy)) y+=this.addy;
if (y>playery&&!onwall(x+1.5,y-this.addy)) y-=this.addy;
if (x<playerx&&!onwall(x+3+this.addx,y+1.5)) x+=this.addx;
if (x>playerx&&!onwall(x-this.addx,y+1.5)) x-=this.addx;
timeout=.05;
}
if (this.hit==1){
i+=.5;
if (x>playerx&&!onwall(x+3+i,y+1.5)) x+=.5;
if (x<playerx&&!onwall(x-i,y+1.5)) x-=.5;
if (y>playery&&!onwall(x+1.5,y+i)) y+=.5;
if (y<playery&&!onwall(x-1.5,y-i)) y-=.5;
if (i>=3.5){
this.hit=0;
i=0;
}
timeout=.05;
}
}
if (playertouchsme&&hearts>0){
hurt this.pow;
}
if (hearts>0&&abs((x+1.5)-(playerx+1.5))<=3 &&abs((playery+1.5)-(y+1.5))<=3) {
hurt this.pow;
}
if (this.hit!=1&&(washit||wasshot||exploded||waspelt) &&hearts>0){
if (washit){
hurtdx=x;
hurtdy=y;
hearts-=playerswordpower;
}
if (wasshot){
hearts--;
}
if (exploded){
hearts--;
}
if (waspelt){
if (peltwithbush) hearts-=.5;
if (peltwithsign || peltwithvase || peltwithstone) hearts-=1;
if (peltwithblackstone) hearts -=1.5;
}
sprite=39;
this.hit=1;
this.attack=0;
for (i=0;i<5;i++){
hideimg i;
}
timeout=.05;
}
if (timeout&&this.attack==1){
p=testplayer(this.flyx+1,this.flyy+1);
if (p>=0){
hitplayer p,this.macepow,this.flyx+1,this.flyy+1;
}
if (this.step<5){
this.flyx-=.5*(dirgo[dir*2]);
this.flyy-=.5*(dirgo[dir*2+1]);
}else if (this.step>=5&&this.step<=10){
sprite=11;
this.flyx+=dirgo[dir*2]*this.macespeed;
this.flyy+=dirgo[dir*2+1]*this.macespeed;
this.radius=(((x+.5)-this.flyx)^2+((y+1)-this.flyy)^2)^.5;
}else if (this.step>10&&this.step<=30){
this.flyx=x+cos(this.angle)*this.radius;
this.flyy=y+sin(this.angle)*this.radius;
this.angle+=.314;
}else if (this.step>30&&this.step<=36){
this.flyx-=dirgo[dir*2];
this.flyy-=dirgo[dir*2+1];
}else if (this.step>36){
this.attack=0;
sprite=0;
}
this.step++;
this.mc1x=x+.5-(.2*(x-this.flyx));
this.mc1y=y+1-(.2*(y-this.flyy));
this.mc2x=x+.5-(.4*(x-this.flyx));
this.mc2y=y+1-(.4*(y-this.flyy));
this.mc3x=x+.5-(.6*(x-this.flyx));
this.mc3y=y+1-(.6*(y-this.flyy));
this.mc4x=x+.5-(.8*(x-this.flyx));
this.mc4y=y+1-(.8*(y-this.flyy));
showimg 0,wmace.gif,this.flyx,this.flyy;
showimg 1,wmace0.gif,this.mc1x,this.mc1y;
showimg 2,wmace0.gif,this.mc2x,this.mc2y;
showimg 3,wmace0.gif,this.mc3x,this.mc3y;
showimg 4,wmace0.gif,this.mc4x,this.mc4y;
timeout=.05;
}
if (hurtdx!=0||hurtdy!=0){
sprite=39;
hurtdx=0;
hurtdy=0;
}
if (timeout&&hearts<=0&&isleader){
for (i=0;i<5;i++){
hideimg i;
}
this.attack=0;
this.step=0;
while(d<=8){
dir=(dir+3)%4;
d++;
sleep.1;
}
i = random(0,100);
if (i<10) lay greenrupee;
else if (i<15) lay bluerupee;
else if (i<30) lay heart;
sprite=40;
}


Reply With Quote