#include"./EventList.Txt"

function fam(x,y,life,size,collision){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	let shot;
	let c = 0;
	let color = [0,0,0];
	let colorstring = GetCharColor(0);
	color = GetFamColor(0);
	ObjEnemy_Regist(obj);
	ObjMove_SetPosition(obj,x,y);
	ObjEnemy_SetLife(obj,life);
	ObjEnemy_SetDamageRate(obj,100,100);
	Control;
	DrawFam(1);
	Obj_SetValue(obj,"FamColor",colorstring);
	return obj;
		task Control{	
			while(!Obj_IsDeleted(obj)){
			c++;
			if(ObjEnemy_GetInfo(obj,INFO_LIFE) <=0)
			{
			//PlaySound("Enep2",100,0);
			FamExplode(ObjMove_GetX(obj),ObjMove_GetY(obj),0.7,colorstring);
			Obj_Delete(obj);
			}
			if(collision==true){
			ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),18*size);
			ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),12*size);
				if(!IsPlayerSpellActive)
				{
				ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(obj),ObjMove_GetY(obj),18*size);
				ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(obj),ObjMove_GetY(obj),12*size);
				ObjEnemy_SetDamageRate(obj,100,100);
				}
				else{
				ObjEnemy_SetDamageRate(obj,10,10);
				}
			}
			yield;
			}
			Obj_Delete(obj);
		}
		task DrawFam(p){
			let fam=ObjPrim_Create(OBJ_SPRITE_2D);
			let img= GCSD~"img/dot_sumireko.png";
			ObjPrim_SetTexture(fam,img);
			ObjSprite2D_SetSourceRect(fam,1024-16,0,1024,16);
			ObjRender_SetPosition(fam,x,y,0);
			ObjRender_SetScaleXYZ(fam,size,size,0);
			ObjSprite2D_SetDestCenter(fam);
			ObjRender_SetBlendType(fam,BLEND_ALPHA);
			if(p==1)
			{
				while(!Obj_IsDeleted(obj) && !Obj_IsDeleted(objBoss)){
				ObjRender_SetPosition(fam,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
				ObjRender_SetAngleXYZ(fam,0,0,c*3);
				yield;
				}
				Obj_Delete(fam);
			}
		}
	}
	
function Drum(x,y,angle,life,size,collision){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	let shot;
	let c = 0;
	let color = [0,0,0];
	let colorstring = GetCharColor(6);
	color = GetFamColor(0);
	ObjEnemy_Regist(obj);
	ObjMove_SetPosition(obj,x,y);
	ObjEnemy_SetLife(obj,life);
	ObjEnemy_SetDamageRate(obj,100,100);
	Control;
	DrawFam;
	Obj_SetValue(obj,"FamColor",colorstring);
	return obj;
		task Control{	
			while(!Obj_IsDeleted(obj)){
			c++;
			if(ObjEnemy_GetInfo(obj,INFO_LIFE) <=0)
			{
			PlaySound("Enep1",100,0);
			FamExplode(ObjMove_GetX(obj),ObjMove_GetY(obj),0.5,colorstring);
			Obj_Delete(obj);
			}
			if(collision==true){
			ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),24*size);
			ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),18*size);
				if(!IsPlayerSpellActive)
				{
				ObjEnemy_SetDamageRate(obj,100,100);
				}
				else{
				ObjEnemy_SetDamageRate(obj,10,10);
				}
			}
			yield;
			}
			Obj_Delete(obj);
		}
		task DrawFam{
			let fam=ObjPrim_Create(OBJ_SPRITE_2D);
			let img= GCSD~"img/raiko.png";
			let bcount = 0;
			let s = 0;
			ObjPrim_SetTexture(fam,img);
			ObjSprite2D_SetSourceRect(fam,128,384,192,432);
			ObjRender_SetPosition(fam,x,y,0);
			ObjSprite2D_SetDestCenter(fam);
			ObjRender_SetBlendType(fam,BLEND_ALPHA);
			Obj_SetRenderPriorityI(fam,40);
			BigBooby;
				while(!Obj_IsDeleted(obj) && !Obj_IsDeleted(objBoss))
				{
					ObjRender_SetColor(fam,255,255,255);
					ObjRender_SetPosition(fam,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
					ObjRender_SetScaleXYZ(fam,s,s,0);
					if(bcount%2==0 && ObjEnemy_GetInfo(obj, INFO_SHOT_HIT_COUNT) > 0)
					{
						ObjRender_SetColor(fam,0,0,255);
					}
					ObjRender_SetAngleZ(fam,180+angle+Obj_GetValueD(obj,"DrumAngleP",0));
					bcount++;
					yield;
				}
				Obj_Delete(fam);
			task BigBooby
			{
				ascent(i in 0..15)
				{
					s = 1.25*size*sin(i*6);
					yield;
				}
				ascent(i in 0..15)
				{
					s = size*(1.25-0.25*sin(i*6));
					yield;
				}
			}
		}
	}
	
function FamExpan(px,py,maxv,t,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/charge.png";
	let scale = 0;
	let v = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,px,py,0);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,25);
	Expan;
		task Expan{
			descent(i in 0..t)
			{
			if(Obj_IsDeleted(objBoss)){break;}
			ObjRender_SetAlpha(obj,malpha*i);
			v = (i*maxv/2)/(t*t);
			scale += v;
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			yield;
			}
			Obj_Delete(obj);
		}
	}
	
function GetFamColor(type){
	if(type==0){return [255,255,255];}
	if(type==1){return [255,32,32];}
	if(type==2){return [32,255,32];}
	if(type==3){return [32,32,255];}
	if(type==4){return [255,255,32];}
	if(type==5){return [128,32,255];}
	if(type==6){return [255,128,32];}
	}
	
function GetCharColor(type){
	if(type==0){return "WHITE";}
	if(type==1){return "RED";}
	if(type==2){return "GREEN";}
	if(type==3){return "BLUE";}
	if(type==4){return "YELLOW";}
	if(type==5){return "PINK";}
	if(type==6){return "ORANGE";}
	}