#define functions
int main(){
int movex=getLocal("movex");
int movey=getLocal("movey");
int frame = getLocal("frame");
int drawCircle = getLocal("drawCircle");
setLocal("frame",frame+1);
int explode=getLocal("explode");
int earthx = getGlobal("Earthx")-(28);
int earthy = getGlobal("Earthy")-(26);
while(getMessageCount()>0){
if(getFlag()=="damage"){
int damage=getMessage("damage");
int earthHealth=getGlobal("earthhealth");
if(earthHealth>0){
setLocal("drawCircle",frame);
}
earthHealth=earthHealth-damage;
setGlobal("earthhealth",earthHealth-damage);
if(earthHealth<=0&&explode==0){
int earthstart=getGlobal("earthstart");
int earthstop=getGlobal("earthstop");
while(earthstart<=earthstop){
messageSprite(earthstart,"explode",0);
earthstart=earthstart+1;
}
}
}
if(getFlag()=="explode"){
setLocal("explode",frame);
setGlobal("objective",1);
if(isGlobalSet("earthdead")==false){
setGlobal("score",getGlobal("score")+300);
setGlobal("earthdead",1);
}
setImage(14);
}
nextMessage();
}
if(drawCircle>0)
drawCircle(frame,drawCircle);
if(explode>0){
explode();
}
setX(getX()+movex);
setY(getY()+movey);
}
int explode(){
playSound(61);
int s=0;
int ii=0;
int x=getX();
int y=getY();
while(ii<3){
int x1=intValue(rand()*24);
int y1=intValue(rand()*24);
s=createSprite(11,7,x+x1,y+y1,2);
setFrame(s,2);
setWidth(s,8);
setHeight(s,8);
setLocal(s,"movey",0);
setLocal(s,"movex",0);
setLocal(s,"life",0);
setLocal(s,"damage",1);
setLocal(s,"explode",0);
setLocal(s,"parent",getID());
ii=ii+1;
}
setGlobal("Me",0.0);
float create=rand();
if(create<=0.3){
s=createSprite(13,5,x+16,y+16,1);
setWidth(s,(int)(rand()*15)+10);
setHeight(s,(int)(rand()*15)+10);
setRenderType(s,1);
setLocal(s,"type","asteroid");
setLocal(s,"explode",0);
setLocal(s,"damaging",0);
setLocal(s,"frames",0);
setLocal(s,"show",0);
setLocal(s,"health",30);
setLocal(s,"radius",3.84*pow(10.0,8.0));
setLocal(s,"direction",1);
setLocal(s,"dealdamage",0);
}
destroySprite();
}
void drawCircle(int frame,int framestart){
int earthSize=getGlobal("EarthSize");
int earthx = getGlobal("Earthx")-(28)-((earthSize-116)/2);
int earthy = getGlobal("Earthy")-(26)-((earthSize-116)/2);
int viewx = getViewportX();
int viewy = getViewportY();
if(frame-framestart<5)
setMask(255,0,0,128);
else
setLocal("drawCircle",0);
}