#define functions
int main(){
int life=getLocal("life");
int explode=getLocal("explode");
setLocal("life",life+1);
int health = getGlobal("shiphealth");
int animateship=checkTimeStamp("animateship");
int shootrate=checkTimeStamp("shootrate");
int moveship=checkTimeStamp("moveship");
int anglecount=getLocal("anglecount");
int storeangle=getLocal("storeangle");
int animate=getLocal("animate");
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){
//Check for keys.
if(getKeyDownCount()>0){
int key=getNextKeyDown();
if(key==39){
setLocal("animate",1);
createTimeStamp("animateship");
}else if(key==37){
setLocal("animate",2);
createTimeStamp("animateship");
}else if(key==38){
setLocal("storeangle",anglecount);
setLocal("animate",0);
}else if(key==65&&shootrate>300){
int rotatex=intValue(cos(rotangle)*14.42);
int rotatey=intValue(sin((-1)*rotangle)*14.42);
int shootx=intValue(cos(rotangle+33.7)*5.0);
int shooty=intValue(((-1)*sin(rotangle+33.7)*5.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,3,x+rotatex+16-3,y+rotatey+16-4,1);
setLocal(s,"soundplayed",false);
/*setWidth(s,16);
setHeight(s,16);*/
setLocal(s,"movex",shootx);
setLocal(s,"movey",shooty);
setLocal(s,"life",0);
setLocal(s,"explode",0);
setLocal(s,"damage",false);
setLocal(s,"type","bullet");
createTimeStamp("shootrate");
}
}
if(getKeyUpCount()>0){
int key2=getNextKeyUp();
if(key2==39||key2==37){
setLocal("animate",0);
}
}
if(animate>0)
while(animateship>40){
if(animate==1)
anglecount=(anglecount+1)%24;
else{
if(anglecount==0)
anglecount=23;
anglecount=(anglecount-1)%24;
}
int image=8+(anglecount/8);
int frame=anglecount%8;
setZRotation(anglecount*15);
//setImage(image);
//setFrame(frame);
setLocal("anglecount",anglecount);
animateship=animateship-80;
frame_change=frame_change+1;
}
if(frame_change>0){
createTimeStamp("animateship");
frame_change=0;
}
while(getMessageCount()>0&&explode==0){
if(getFlag()=="damage"){
int damage=getMessage();
health=health-damage;
}
if(health<=0){
setLocal("explode",life);
setImage(14);
}
setGlobal("shiphealth",health);
nextMessage();
}
}
//Reset timer and move ship.
//if(moveship>60){
int plx=intValue((cos(angle)*3.0));
int portx=intValue(getViewportX()+(cos(angle)*3.0));
int porty=intValue(getViewportY()+((-1)*sin(angle)*3.0));
int ply=intValue(((-1)*sin(angle)*3.0));
int maxx=getGlobal("maxx");
int maxy=getGlobal("maxy");
if(x+plx<0||x+plx>maxx){
plx=plx*(-1);
storeangle=(storeangle+12)%24;
setLocal("storeangle",storeangle);
}if(y+ply<0||y+ply>maxy){
ply=ply*(-1);
storeangle=(storeangle+12)%24;
setLocal("storeangle",storeangle);
}
setViewportX(x+plx);
setViewportY(y+ply);
setX(x+plx);
setY(y+ply);
setGlobal("playerx",(x+plx+16));
setGlobal("playery",(y+ply+16));
moveship=moveship-50;
frame_change=1;
//}
if(frame_change==1)
createTimeStamp("moveship");
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(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);
}
}
}