#define functions
int main(){
//Have we set the path of the ship.
if(isLocalSet("mode")==false){
setLocal("mode",0);
}
int mode=getLocal("mode");
if(isLocalSet("minmove")==false){
setLocal("minmove",0);
}
int minmove=getLocal("minmove");
int lastshoot=getLocal("lastshoot");
setLocal("lastshoot",lastshoot+1);
int playerx=getGlobal("playerx");
int playery=getGlobal("playery");
int life=getLocal("life");
int explode=getLocal("explode");
setLocal("life",life+1);
int health=getLocal("health");
int anglecount=getLocal("anglecount");
int storeangle=getLocal("storeangle");
int animate=getLocal("animate");
setLocal("animate",animate+1);
int frame_change=0;
int x=getX();
int y=getY();
float angle=90.0;
angle=angle-(15*storeangle);
float rotangle=90.0;
rotangle=rotangle-(15*anglecount+33.7);
if(explode==0){
if(lastshoot>20&&mode==1){
int rotatex=intValue(cos(rotangle)*14.42);
int rotatey=intValue(sin((-1)*rotangle)*14.42);
int shootx=intValue(cos(rotangle+33.7)*4.0);
int shooty=intValue(((-1)*sin(rotangle+33.7)*4.0));
int movex=intValue((cos(angle)*3.0));
int movey=intValue(((-1)*sin(angle)*3.0));
shootx=shootx+movex;
shooty=shooty+movey;
int s=createSprite(11,11,x+rotatex+16-3,y+rotatey+16-4,2);
setFrame(s,1);
setLocal(s,"soundplayed",false);
/*setWidth(s,8);
setHeight(s,8);*/
setLocal(s,"movex",shootx);
setLocal(s,"movey",shooty);
setLocal(s,"life",0);
setLocal(s,"explode",0);
setLocal(s,"damage",false);
setLocal(s,"type","bullet");
setLocal("lastshoot",0);
}
//Animate the ship based on its target angle.
if(animate>3){
int add=0;
int addcheck=storeangle-anglecount;
if(storeangle-anglecount<0){
add=1;
}else{
add=(-1);
}
if(storeangle-anglecount>12||storeangle-anglecount<-12){
add=add*(-1);
}
if(storeangle!=anglecount){
storeangle=storeangle+add;
if(storeangle<0){
storeangle=23;
}else if(storeangle>23){
storeangle=storeangle-23;
}
}
setLocal("storeangle",storeangle);
int image=19+((anglecount-1)/8);
int frame=anglecount%8;
setZRotation(anglecount*15);
/*setImage(image);
setFrame(frame);*/
setLocal("animate",0);
}
//Check whether the ship is on a patrol and move it accordingly.
if(mode==0){
int patrol=getLocal("patrol");
setLocal("patrol",patrol+1);
if(patrol%8==0){
setLocal("anglecount",(storeangle+4)%24);
}
if(abs(playerx-x)<150&&abs(playery-y)<150){
setLocal("mode",1);
}
}else if(minmove<=0){
int hyp=sqrt( ((x-(playerx))*(x-(playerx))) + ((y-(playery))*(y-(playery))) + 0.0);
int ang=intValue( asin((y-playery)/hyp+0.0) );
if(x-playerx>0&&y-playery>0){
ang=360-(90-ang);
}else if(x-playerx>0){
ang=270+ang;
}else if(y-playery>0){
ang=90-ang;
}else{
ang=90-ang;
}
setLocal("anglecount",ang/15);
setLocal("minmove",6);
if(abs(playerx-x)>300&&abs(playery-y)>300){
setLocal("mode",0);
}
}
setLocal("minmove",minmove-1);
while(getMessageCount()>0&&explode==0){
if(getFlag()=="damage"){
int damage=getMessage();
health=health-damage;
}
if(health<=0){
setLocal("explode",life);
setImage(14);
setGlobal("score",getGlobal("score")+100);
if(rand()<=0.25){
int s=createSprite(18,14,x,y,2);
setFrame(s,6);
setLocal(s,"animate",0);
setLocal(s,"type","health");
float aangle=rand()*360.0;
aangle=intValue(aangle%24)*15.0;
int ax=intValue((cos(aangle)*2.0));
int ay=intValue(((-1)*sin(aangle)*2.0));
setLocal(s,"addx",ax);
setLocal(s,"addy",ay);
}
}
setLocal("health",health);
nextMessage();
}
}
//Move the shop.
int plx=intValue((cos(angle)*2.0));
int ply=intValue(((-1)*sin(angle)*2.0));
setX(x+plx);
setY(y+ply);
if(explode>0){
int img = getImage();
if(img==14)
explode(life,explode,false);
else
explode(life,explode,true);
}
}
int explode(int life,int explodestart,boolean destroy){
if(destroy==false){
drawTextWorld("100","courier",10,getX()-32,getY()-32-(life-explodestart),255,255,255,255);
}
if(life<explodestart+3){
setFrame(0);
}else if(life<explodestart+6){
setFrame(1);
}else if(life<explodestart+9){
setFrame(2);
}else if(life<explodestart+12){
setFrame(3);
}else if(life<explodestart+15){
setFrame(4);
}else if(life<explodestart+18){
setFrame(5);
}else if(life<explodestart+21){
if(destroy==true){
destroySprite();
}else{
setImage(15);
setLocal("explode",life);
}
}
}