let ang = 0;
#include"./Functions/EventList.Txt"
task SetBoss(name,tspell){
	LoadAll;
	//SetCommonData("Difficulty","Normal"); // test only
	//SetCommonData("Difficulty","Hard"); // test only
	//SetCommonData("Difficulty","Lunatic"); // test only
	if(GetCommonData("ItemStart",0)==0){StartItemScript(GCSD ~"Item.txt");}
	if(name=="Doremy"){SetCommonData("BossName","Doremy Sweet");}
	SetCommonData("IsSpell",tspell);
	SetCommonData("Bomb",0);
	SetCommonData("Life",0);
	SetCommonData("Fight",1);
	SetCommonData("Score",0);
	SetCommonData("shot",0);
	SetCommonData("bomb",0);
	SetCommonData("Effect",2);
	SetShotAutoDeleteClip(64,64,64,64);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	mainTask;
	DrawBoss(objBoss,name);
	BulletHitEffect;
	TEnd;
	DrawAll;
	if(tspell==true){
	SetCommonData("Score",40);
	}
	SetAutoDeleteObject(true);
	yield;
	SetAutoDeleteObject(false);
	}
	
task BulletHitEffect
{
	let startlife = ObjEnemy_GetInfo(objBoss, INFO_LIFE);
	while(!Obj_IsDeleted(objBoss)){
		if(ObjEnemy_GetInfo(objBoss, INFO_SHOT_HIT_COUNT) > 0 && ObjEnemy_GetInfo(objBoss, INFO_LIFE)<startlife/6)
		{
				PlaySound("Shot9",80,0);
		}
		yield;
	}
}
	
task BombShield{
		while(!Obj_IsDeleted(objBoss)){
			if(IsPlayerSpellActive){ObjEnemy_SetDamageRate(objBoss, 0,0);}
			else{ObjEnemy_SetDamageRate(objBoss, GetCommonData("shot",0),GetCommonData("bomb",0));}
			yield;
		}
	}

task EndBoss(let type){
		let dis = 0;
		SetCommonData("ItemEnd",type);
		SetCommonData("BossX",GetEnemyX);
		SetCommonData("BossY",GetEnemyY);
		NotifyEventAll(EV_FAM_DIE,objBoss);
		Obj_Delete(objBoss);
			if(type==1){
			if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0)
			{
				AddScore(ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE));
			}
			}
			//-----------------Delete Sound-------------------------//
			DeleteAllSound;
	}
	
task DeleteAllSound
{
			ascent(i in 0..length(soundarr))
			{
				Obj_Delete(soundarr[i]);
			}
}
		
		
task ClearBullet(time,speed){
		let dis = 0;
		let px = GetEnemyX;
		let py = GetEnemyY;
		loop(time){
		let arr = GetShotIdInCircleA2(stgx,stgy,1000,TARGET_ENEMY);
		ascent(i in 0..length(arr)){
			if(!Obj_IsDeleted(arr[i]) && GetDistance(ObjMove_GetX(arr[i]),ObjMove_GetY(arr[i]),px,py) <dis && IsPlayerSpellActive == false){
			effbreak(arr[i],0,10);
			Obj_Delete(arr[i]);
			}
		}
		dis += speed;
		yield;
			}
}


task DrawBoss(obj,name){
	let img;
	img = GetCurrentScriptDirectory~"img/enm3.png";
	let f = 0;
	let t = 0;
	let px = 64;
	let py = 96;
	let c = 0;
		ObjPrim_SetTexture(obj, img);
		ObjRender_SetAlpha(obj,255);
		ObjRender_SetScaleXYZ(obj,1.1,1,1);
	while(!Obj_IsDeleted(obj))
	{
		let angle = ObjMove_GetAngle(obj);
		let speed = ObjMove_GetSpeed(obj);
		if(speed>0 && idle == true){MarisaTail(obj,name,0,0,px,py,ang);}
		if(speed <= 1 && idle == true && atk == false){
		if(f<8){		  SetImageAndTail(obj, name,px*0, py*0, px*1, py*1,ang);}
		if(f>=8 && f<16) {SetImageAndTail(obj, name,px*1, py*0, px*2, py*1,ang);}
		if(f>=16 && f<24){SetImageAndTail(obj, name,px*2, py*0, px*3, py*1,ang);}
		if(f>=24 && f<32){SetImageAndTail(obj, name,px*3, py*0, px*4, py*1,ang);}
		if(f>=32){f=0;}
		f++;
		c++;
		ObjRender_SetY(obj,ObjMove_GetY(obj)+0.1*sin(c*5));
		t = 0;
		}
		else if(cos(angle) > 0 || cos(angle) < 0 && t == 0){
		idle = false;
		manageSprite(obj,cos(angle),name);
		t = 1;
		}
		ObjSprite2D_SetDestCenter(obj);
		yield;
	}
}

task manageSprite(obj,ang,name){ // Manage movement sprite
		let f = 0;
		let mx = 0;
		let px = 64; 
		let py = 96;
		let plusy = 0;
		idle = false;  
		if(ang>=0){plusy+=py;}
		while(f<40 && idle == false  && atk == false){
		if(f<8){		SetImageAndTail(obj, name,px*0, py*1+plusy, px*1, py*2+plusy,0);}
		if(f>=8 && f<16){SetImageAndTail(obj, name,px*1, py*1+plusy, px*2, py*2+plusy,0);}
		if(f>=16 && f<24){SetImageAndTail(obj, name,px*2, py*1+plusy, px*3, py*2+plusy,0);}
		if(f>=24 && f<32){SetImageAndTail(obj, name,px*3, py*1+plusy, px*4, py*2+plusy,0);}
		if(f>=32 && f<40){SetImageAndTail(obj, name,px*4, py*1+plusy, px*5, py*2+plusy,0);}
		f+=1;
		yield;
		}
		/*while(ObjMove_GetSpeed(obj)>9999){
		SetImageAndTail(obj, name,px*4, py*1+plusy, px*5, py*2+plusy,0);
		yield;
		}*/
		while(f>=0 && idle == false  && atk == false){
		if(f<8){		SetImageAndTail(obj, name,px*0, py*1+plusy, px*1, py*2+plusy,0);}
		if(f>=8 && f<16){SetImageAndTail(obj, name,px*1, py*1+plusy, px*2, py*2+plusy,0);}
		if(f>=16 && f<24){SetImageAndTail(obj, name,px*2, py*1+plusy, px*3, py*2+plusy,0);}
		if(f>=24 && f<32){SetImageAndTail(obj, name,px*3, py*1+plusy, px*4, py*2+plusy,0);}
		if(f>=32 && f<40){SetImageAndTail(obj, name,px*4, py*1+plusy, px*5, py*2+plusy,0);}
		f-=1;
		yield;
		}
		idle = true;
	}
	
task attack(delay,type){ // Manage attack pose
	let f2 = 0;
	let px = 64;
	let py = 96;
	atk = true;
	idle = false;
		if(type==1)
		{
			loop(6){SetImageAndTail(objBoss,"Doremi",px*0, py*3, px*1, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*1, py*3, px*2, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*2, py*3, px*3, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*3, py*3, px*4, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*4, py*3, px*5, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*5, py*3, px*6, py*4,0);yield;}
			loop(6+delay){SetImageAndTail(objBoss,"Doremi", px*5, py*3, px*6, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*5, py*3, px*6, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*4, py*3, px*5, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*3, py*3, px*4, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*2, py*3, px*3, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*1, py*3, px*2, py*4,0);yield;}
			loop(6){SetImageAndTail(objBoss,"Doremi", px*0, py*3, px*1, py*4,0);yield;}
			atk = false;
			idle = true;
		}
	}
	
task LoadAll{
	LoadTexture(GCSD~"img/Cutin.png");
	LoadTexture(GCSD~"img/effbreak.png");
	LoadTexture(GCSD~"img/Marisa1.png");
	LoadTexture(GCSD~"img/stg3bg1.png");
	LoadTexture(GCSD~"img/boss.png");
	LoadTexture(GCSD~"Shot/AllStarShot.png");
	LoadTexture(GCSD~"system/img/front01.png");
	LoadTexture(GCSD~"system/img/front00.png");
	LoadTexture(GCSD~"img/Dot.png");
	LoadTexture(GCSD~"img/Cutin.png");
	LoadTexture(GCSD~"img/cdbg05a.png");
	LoadTexture(GCSD~"img/cdbg05b.png");
}