let MainSTG = GetMainStgScriptDirectory;

task TEnemyHitboxStart(obj,n){
	ObjEnemy_SetDamageRate(obj,0,0);
	loop(n){yield;}
	ObjEnemy_SetDamageRate(obj,100,100);
	while(ObjEnemy_GetInfo(obj,INFO_LIFE)>0){
		yield;
	}
}

function angleToPlayer{
	let angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
	return angle;
}

let objPlayer;
objPlayer=GetPlayerObjectID();

function getAtanAngle(obj,obj2){
	let angle=atan2(ObjMove_GetY(obj2)-ObjMove_GetY(obj),ObjMove_GetX(obj2)-ObjMove_GetX(obj));
	return angle;
}

function GetEnemyX{
	return ObjMove_GetX(objBoss);
}

function GetEnemyY{
	return ObjMove_GetY(objBoss);
}

function wait(n){loop(n){yield;}}

task PlayDelaySE(se,delay){
        loop(delay){yield;}
        PlaySE(se);
}

function GetClipMinX{
	return 0;
}

function GetClipMinY{
	return 0;
}

function GetClipMaxX{
	return GetStgFrameWidth;
}

function GetClipMaxY{
	return GetStgFrameHeight;
}

function ShootShape(spawnX, spawnY, v, angle, num, bside, graphic, delay) {
	ascent(i in 0..num) {
		let sx = spawnX+cos(angle+i*360/num); let sy = spawnY+sin(angle+i*360/num); let sxN = spawnX+cos(angle+(i+1)*360/num); let syN = spawnY+sin(angle+(i+1)*360/num);
		CreateShotA1(spawnX, spawnY, v*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), atan2(sy-spawnY,sx-spawnX), graphic, delay);
		ascent(j in 0..bside) {
			let toAngle = atan2(syN-sy,sxN-sx); let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5); let sx2 = sx+toDist/bside*j*cos(toAngle); let sy2 = sy+toDist/bside*j*sin(toAngle);
			CreateShotA1(spawnX, spawnY, v*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.5), atan2(sy2-spawnY,sx2-spawnX), graphic, delay);
		}
	}
}

task SetBulletTrailDelay(obj,time,delay,c,c2,alp,fade,shrink){
	let img=GCSD~"img/trail.png";
	loop(delay){ yield; }
	TObj;
	task TObj{
		while(!Obj_IsDeleted(obj)){
			let d=ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(d,BLEND_ADD_RGB);
			ObjPrim_SetTexture(d,img);
			ObjSprite2D_SetSourceRect(d,0,0,32,32);
			ObjSprite2D_SetDestCenter(d);
			ObjRender_SetPosition(d,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
			SetColor(d,c,c2);
			if(fade!=true){
				ObjRender_SetAlpha(d,alp);
				}
			TAction(d);
			yield;
			}
		}
	task TAction(o){
		let scale=1;
		let s=1;
		let alpha=255;
		let a=1;
		loop(time){
			if(fade==true){
				ObjRender_SetAlpha(o,alpha);
				alpha-=(a/time);
				}
			if(shrink==true){
			ObjRender_SetScaleXYZ(o,scale,scale,0);
			scale-=(s/time);
				}
			yield;
			}
		Obj_Delete(o);
		}
	}

task LoadSoundEffects{
	LoadSound(MainSTG~"sound/Shot1.wav");
	LoadSound(MainSTG~"sound/Shot2.wav");
	LoadSound(MainSTG~"sound/Shot3.wav");
	LoadSound(MainSTG~"sound/Shot4.wav");
	LoadSound(MainSTG~"sound/Shot5.wav");
	LoadSound(MainSTG~"sound/Shot6.wav");
	LoadSound(MainSTG~"sound/Laser1.wav");
	LoadSound(MainSTG~"sound/Laser2.wav");
	LoadSound(MainSTG~"sound/Laser3.wav");
	LoadSound(MainSTG~"sound/Laser4.wav");
	LoadSound(MainSTG~"sound/Laser5.wav");
	LoadSound(MainSTG~"sound/Charge1.wav");
	LoadSound(MainSTG~"sound/Charge2.wav");
	LoadSound(MainSTG~"sound/Charge3.wav");
	LoadSound(MainSTG~"sound/Charge4.wav");
	LoadSound(MainSTG~"sound/Weird1.wav");
	LoadSound(MainSTG~"sound/Weird2.wav");
	LoadSound(MainSTG~"sound/Weird3.wav");
	LoadSound(MainSTG~"sound/bright.wav");
	LoadSound(MainSTG~"sound/BulletWave.wav");
	LoadSound(MainSTG~"sound/Eff1.wav");
	LoadSound(MainSTG~"sound/Eff2.wav");
	LoadSound(MainSTG~"sound/Eff3.wav");
	LoadSound(MainSTG~"sound/Eff4.wav");
	LoadSound(MainSTG~"sound/fam.wav");
	LoadSound(MainSTG~"sound/stars.wav");
	LoadSound(MainSTG~"sound/Enep1.wav");
}

let se;

task PlaySound(str,w){
	//Boss sounds
	loop(w){yield;}
	if(str == "Shot1"){PlaySE(MainSTG~"sound/Shot1.wav");}
	if(str == "Shot2"){PlaySE(MainSTG~"sound/Shot2.wav");}
	if(str == "Shot3"){PlaySE(MainSTG~"sound/Shot3.wav");}
	if(str == "Shot4"){PlaySE(MainSTG~"sound/Shot4.wav");}
	if(str == "Shot5"){PlaySE(MainSTG~"sound/Shot5.wav");}
	if(str == "Shot6"){PlaySE(MainSTG~"sound/Shot6.wav");}
	if(str == "Laser1"){PlaySE(MainSTG~"sound/Laser1.wav");}
	if(str == "Laser2"){PlaySE(MainSTG~"sound/Laser2.wav");}
	if(str == "Laser3"){PlaySE(MainSTG~"sound/Laser3.wav");}
	if(str == "Laser4"){PlaySE(MainSTG~"sound/Laser4.wav");}
	if(str == "Laser5"){PlaySE(MainSTG~"sound/Laser5.wav");}
	if(str == "Charge1"){PlaySE(MainSTG~"sound/Charge1.wav");}
	if(str == "Charge2"){PlaySE(MainSTG~"sound/Charge2.wav");}
	if(str == "Charge3"){PlaySE(MainSTG~"sound/Charge3.wav");}
	if(str == "Charge4"){PlaySE(MainSTG~"sound/Charge4.wav");}
	if(str == "Weird1"){PlaySE(MainSTG~"sound/Weird1.wav");}
	if(str == "Weird2"){PlaySE(MainSTG~"sound/Weird2.wav");}
	if(str == "Weird3"){PlaySE(MainSTG~"sound/Weird3.wav");}
	if(str == "BulletWave"){PlaySE(MainSTG~"sound/BulletWave.wav");}
	if(str == "bright"){PlaySE(MainSTG~"sound/bright.wav");}
	if(str == "Eff1"){PlaySE(MainSTG~"sound/Eff1.wav");}
	if(str == "Eff2"){PlaySE(MainSTG~"sound/Eff2.wav");}
	if(str == "Eff3"){PlaySE(MainSTG~"sound/Eff3.wav");}
	if(str == "Eff4"){PlaySE(MainSTG~"sound/Eff4.wav");}
	if(str == "fam"){PlaySE(MainSTG~"sound/fam.wav");}
	if(str == "stars"){PlaySE(MainSTG~"sound/stars.wav");}
	if(str == "Enep1"){PlaySE(MainSTG~"sound/Enep1.wav");}
}