11. Archer Horseman
Well... you can't really make a Horsman that is an archer. That's
because when you set the sprite to 33 (the shooting sprite that shows the
player using his bow) the horse disapears. But you can make it look
like the horse is shooting the projectile (good for fireballs and fireblasts).
So I'm gonna explain how to do that.
First off, we need the usual movement, and shoot detection stuff from
the archer, but with sprites for the horseman.
//Movement and shooting
if (timeout&&hearts>0&&this.shoot!=1){
//Prevents the horseman from moving while shooting
if (sprite<36){
sprite++;
}else{
sprite=35;
}
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;
}
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;
if((x-players[this.player].x<1&&players[this.player].x-x<1)||(y-players[this.player].y<1&&players[this.player].y-y<1)){
//this
checks to see if the player is sharing an x or y cord with the baddy (so
he's aligned to shoot).
this.shoot=1; //tells
the NPC to do the shooting stuff
sprite=34; //the horse riding
sprite i chose to show the horse shooting stuff
sleep 1; //done to stop
the horse from shooting instantly
}
timeout=.05;
}
if (timeout&&hearts>0&&this.shoot==1){ //the
actual shooting part of the script
shootfireball dir; //shoots a fireball
the direction the npc is facing, could be change to shoot other projectiles.
sleep .1; //this gives the npc time
in between shots
this.shoot=0; //tells it to go back
to the walking stuff
sprite=35; //the first riding sprite
timeout=.05; //to restart the walking
timeout loop
}
//End of Script
Then of course we still have that old shooting glitch that occurs when
its hit while shooting to fix.
//New if hit stuff
if ((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;
while(this.hit==1){
i+=.5;
if (x>playerx&&!onwall(x+2.5,y+1.5)) x+=.5;
if (x<playerx&&!onwall(x-.5,y+1.5)) x-=.5;
if (y>playery&&!onwall(x+1.5,y+2.5)) y+=.5;
if (y<playery&&!onwall(x-1.5,y-.5)) y-=.5;
if (i>=3.5){
this.hit=0;
i=0;
}
sleep .05;
}
this.shoot=0; //fixes the shooting
glitch
timeout=.05;
}
//End of Script
That's it.
Now we have our basic horseman archer combo.
//Basic Archer Horseman
if (created){
showcharacter;
setcharprop #5,ride.gif;
setcharprop #n,Basic Archer Horseman;
sprite=34;
hearts=3;
hurtdx=0;
hurtdy=0;
}
if (playerenters||wasthrown){
this.speed=.5;
timeout=.05;
}
if (timeout&&this.shoot!=1&&isleader){
if (hearts>0){
if (sprite<36){
sprite++;
}else{
sprite=35;
}
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;
}
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;
if((x-players[this.player].x<1&&players[this.player].x-x<1)||(y-players[this.player].y<1&&players[this.player].y-y<1)){
this.shoot=1;
sprite=34;
sleep 1;
}
timeout=.05;
}
}
if (timeout&&isleader&&hearts>0&&this.shoot==1){
shootfireball dir;
sleep .1;
this.shoot=0;
sprite=35;
timeout=.05;
}
if ((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.shoot=0;
this.hit=1;
while(this.hit==1){
i+=.5;
if (x>playerx&&!onwall(x+2.5,y+1.5)) x+=.5;
if (x<playerx&&!onwall(x-.5,y+1.5)) x-=.5;
if (y>playery&&!onwall(x+1.5,y+2.5)) y+=.5;
if (y<playery&&!onwall(x-1.5,y-.5)) y-=.5;
if (i>=3.5){
this.hit=0;
i=0;
}
sleep .05;
}
timeout=.05;
}
if (hurtdx!=0||hurtdy!=0){
sprite=39;
hurtdx=0;
hurtdy=0;
}
if (timeout&&hearts<=0&&isleader){
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;
}
//End of Script
That NPC has the name of Basic Archer Horseman in the level basicarchers.graal.