Galaxium III ASTERIOD!!!

From Hack Wars Wiki

Jump to: navigation, search
#define functions
int main(){
	int frame = getLocal("frames");
	int explode = getLocal("explode");
	int show = getLocal("show");
	int health = getLocal("health");
	int direction = getLocal("direction");
	int x = getX();
	int y = getY();
	int dealdamage=getLocal("dealdamage");
	int xe = getGlobal("Earthx");
	int ye = getGlobal("Earthy");
	int xs = getGlobal("Sunx");
	int ys = getGlobal("Suny");
	float xt = x-xe+0.0;
	float yt = y-ye+0.0;
	float angle=0.0;
	float hyp = sqrt(pow(xt,2.0)+pow(yt,2.0));
	angle = acos(xt/hyp);
	float mangle = 0.0;
	if(y>ye)
		mangle=90-angle;
	else
		mangle=angle-90;
	setLocal("frames",frame+1);
	float radius = hyp*pow(10.0,6.0);
	float G = getGlobal("G");
	float Me = getGlobal("Me");
	float velocity = sqrt(G*Me/radius)/500;
	//float velocity = getLocal("velocity");
	int movexEarth = direction*intValue(velocity*cos(mangle));
	int moveyEarth = direction*intValue(velocity*sin(mangle))*(-1);
	if(y>ye){
		//debug("altered for below axis");
		movexEarth=movexEarth*(-1);
		moveyEarth=moveyEarth*(-1);
		//movey=movey+1;
	}
	xt = x-xs+0.0;
	yt = y-ys+0.0;
	angle=0.0;
	hyp = sqrt(pow(xt,2.0)+pow(yt,2.0));
	angle = acos(xt/hyp);
	mangle = 0.0;
	if(y>ys)
		mangle=90-angle;
	else
		mangle=angle-90;
	radius = hyp*pow(10.0,11.0);
	float Ms = getGlobal("Ms");
	velocity = sqrt(G*Ms/radius)/500;
	//float velocity = getLocal("velocity");
	int movexSun = direction*intValue(velocity*cos(mangle));
	int moveySun = direction*intValue(velocity*sin(mangle))*(-1);
	if(y>ys){
		//debug("altered for below axis");
		movexSun=movexSun*(-1);
		moveySun=moveySun*(-1);
		//movey=movey+1;
	}
	//if(intValue(mangle)==0)
	//	movey=1;
	int movex=movexEarth+movexSun;
	int movey=moveyEarth+moveySun;
	//debug(movex+"   "+movey);
	setX(x+movex);
	setY(y+movey);
	if(explode==0){
		/*if(show>8)
			setImage(13);
		else
			setImage(12);*/
		int current = getFrame();
		int new = current;
		if(frame%10==0)
			new = new+1;
		if(new==8)
			new=0;
		int newShow = show+1;
		if(newShow==16)
			newShow=0;
		setLocal("show",newShow);
        setZRotation(getZRotation()+3);
 
 
		while(getMessageCount()>0){
			if(getFlag()=="damage"){
				int damage=getMessage();
				health=health-damage;
			}
 
			if(health<0){
				setLocal("explode",frame);
                setRenderType(0);
                setZOffset(10);
                setWidth(32);
                setHeight(32);
				setImage(14);
				setGlobal("score",getGlobal("score")+20);
			}
			setLocal("health",health);
 
			if(getFlag()=="damagedone"){
				setLocal("dealdamage",0);
			}
			nextMessage();
		}
 
		while(getCollidedCount()>0&&dealdamage==0){
 
			int target=collidedWith();
			string type=getLocal(target,"type");
			if(type=="player"){
 
				int s=createSprite(11,7,x+16,y+16,2);
				setFrame(s,2);
				setLocal(s,"damage",0);
				setLocal(s,"movey",movey);
				setLocal(s,"movex",movex);
				setLocal(s,"life",0);
				setLocal(s,"explode",3);
				setLocal(s,"parent",getID());
				setLocal("dealdamage",1);
				setLocal(s,"type","asteroidexplode");	
				messageSprite(target,"damage",20);
 
				dealdamage=1;
			}
			nextCollided();
		}
 
	}
	else{
		int image = getImage();
		if(image==14)
			explode(frame,explode,false);
		else
			explode(frame,explode,true);
	}
 
}
 
int explode(int life,int explodestart,boolean destroy){
	if(destroy==false){
		drawTextWorld("20","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);
	}
}
}