
script_enemy_main {
	#include_function ".\lib\lib_anime_mokou.txt"
	#include_function ".\Draw.txt"
	#include_function ".\lib_Functions.txt"
	let imgBoss	=csd ~ "img\dot_mokou.png";
	let imgback	=csd~"img\back2.png";

	@Initialize {
        	SetLife(860);
		SetTimer(70);
		SetScore(900000);
		SetDamageRate(0, 0);
		InitializeAction();
		LoadUserShotData(shotData);
		LoadGraphic(imgBoss);
		LoadGraphic(imgback);
		Load;
        	CutIn(YOUMU,"時効「月光のいはかさの呪縛」", NULL, 0, 0, 0, 0);
        	Main;
	}

    	@MainLoop {
        	SetCollisionA(GetX, GetY, 32);
        	SetCollisionB(GetX, GetY, 16);
		if(GetTimer==10&&counter==0){
			Timer;
			counter++;
		}
        	yield;
    	}

	@DrawLoop {
		SetColor(255,255,255);
		SetGraphicScale(1,1);
		SetAlpha(255);
		DrawBoss(imgBoss);
	}

	@BackGround {
		SetColor(100,100,255);
		SetAlpha(150);
		SetTexture(imgback);
		SetGraphicRect(0, 0, 384, 457);
		SetGraphicAngle(0, 0, 0);
		DrawGraphic(224, 240);
		if(drawcount==1){
			DrawHououZ(200, 200, 100, 100);
		}
		if(drawcount>0){
			DrawHouou(200, 200, 100, 100);
			DrawIrusion(GetX, GetY,100,255,100,100);
		}
	}

	sub standBy {
		SetMovePosition03(cenX,cenY-120, 10, 7);
		SetAction(ACT_MOVE, 60);
		wait(120);
	}


   	task Main {
        	yield;
		standBy;
		Charge;
		PlaySE(seCharge1);
		wait(30);
		drawcount++;
		wait(30);
		drawcount++;
		wait(60);
		SetDamageRate(20, 0);
		BombBarrier;
		Sum;	
		Att;
	}

	task Att{
		shotA;
	}

	task shotA{
		let B=0;
		loop{
		wait(10);
		let angleA=0;
		while(angleA<360){
		CreateShot01(GetX,GetY,2.5,angleA-B,45,0);
		angleA+=45;
		}
		PlaySE(seShot5);
		B+=4;
		}
	}

	task Sum{
		let angle=0;
		while(angle<360){
		CreateEnemyFromScript("BARD1", GetX+120+30*cos(angle), GetY+40+30*sin(angle), 1, angle-90, 0);
		CreateEnemyFromScript("BARD2", GetX-120-30*cos(-angle), GetY+40-30*sin(-angle), 1, -angle-90, 0);
		angle+=120;
		}
	}

	@Finalize{
		DeleteGraphic(imgBoss);
		Delete;
		Spell;
	}

}


script_enemy BARD1{
	let imgeff   = GetCurrentScriptDirectory ~ "img\effect2.png";
	let seShot5  = GetCurrentScriptDirectory ~ "se\sha00.wav";
	let angle=GetAngle;
	let A=0;

	@Initialize{
        SetLife(500);
	LoadGraphic(imgeff);
	LoadSE(seShot5);
	Main;
	}

	@DrawLoop{
	AuraEffect;
	BardEffect;
	}

	task BardEffect{
		let x=GetX;let y=GetY;
		let Obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(Obj,imgeff);
		ObjEffect_SetLayer(Obj,1);
		ObjEffect_SetRenderState(Obj,ADD);
		ObjEffect_SetPrimitiveType(Obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(Obj,4);
		ObjEffect_SetAngle(Obj,0,0,angle+90-A);

		ObjEffect_SetVertexXY(Obj, 0, -20, -20);
		ObjEffect_SetVertexXY(Obj, 1, -20,  20);
		ObjEffect_SetVertexXY(Obj, 2,  20, -20);
		ObjEffect_SetVertexXY(Obj, 3,  20, 20);

		ObjEffect_SetVertexUV(Obj, 0, 0, 80);
		ObjEffect_SetVertexUV(Obj, 1, 0, 120);
		ObjEffect_SetVertexUV(Obj, 2, 40, 80);
		ObjEffect_SetVertexUV(Obj, 3, 40, 120);

		let scale=1;let alpha=128;
		while(alpha>10)
		{
			Obj_SetPosition(Obj,x,y);
			ObjEffect_SetScale(Obj,scale,scale);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(Obj,a,alpha,255,255,255);
			}
			alpha-=20;
			scale+=0.01;
			yield;
		}
		Obj_Delete(Obj);
	}

	task AuraEffect{
		let x=GetX;let y=GetY;
		let Obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(Obj,imgeff);
		ObjEffect_SetLayer(Obj,1);
		ObjEffect_SetRenderState(Obj,ADD);
		ObjEffect_SetPrimitiveType(Obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(Obj,4);
		ObjEffect_SetAngle(Obj,0,0,angle+90-A);

		ObjEffect_SetVertexXY(Obj, 0, -20, -20);
		ObjEffect_SetVertexXY(Obj, 1, -20,  20);
		ObjEffect_SetVertexXY(Obj, 2,  20, -20);
		ObjEffect_SetVertexXY(Obj, 3,  20, 20);

		ObjEffect_SetVertexUV(Obj, 0, 0, 0);
		ObjEffect_SetVertexUV(Obj, 1, 0, 40);
		ObjEffect_SetVertexUV(Obj, 2, 40, 0);
		ObjEffect_SetVertexUV(Obj, 3, 40, 40);

		let scale=1.3;let alpha=48;
		while(alpha>10)
		{
			Obj_SetPosition(Obj,x,y);
			ObjEffect_SetScale(Obj,scale,scale);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(Obj,a,alpha,255,255,255);
			}
			alpha-=5;
			scale+=0.01;
			yield;
		}
		Obj_Delete(Obj);
	}

	@MainLoop{
		yield;
	}

	task Main{
		yield;
		shotA;
		moveA;
	}

	task shotA{
		loop{
		CreateReflectShot(GetX,GetY,2.5,angle-A-180,150,0,1);
		PlaySE(seShot5);
		wait(40);
		yield;
		}
	}

	task CreateReflectShot(let x, let y, let speed,
        	let angle, let graphic, let delay, let count) {
    
    		let Obj = Obj_Create(OBJ_SHOT);
    
   		Obj_SetPosition(Obj, x, y);
   	 	Obj_SetSpeed(Obj, speed);
    		Obj_SetAngle(Obj, angle);
    		ObjShot_SetGraphic(Obj, graphic);
    		ObjShot_SetDelay(Obj, delay);

    
    		while(!Obj_BeDeleted(Obj)) {
        		if(((Obj_GetX(Obj)-GetX)^2+(Obj_GetY(Obj)-GetY)^2)^0.5>300){
	    		let a=0;
	    		loop(1){
	    		loop(11){
	    		Obj_SetSpeed(Obj,speed-a);
	    		a+=2.5/10;
	    		wait(4)
	    		}
	    		wait(10);
	    		let mi=GetPlayerX;
	    		let me=GetPlayerY;
            		Obj_SetAngle(Obj, atan2(me-Obj_GetY(Obj),mi-Obj_GetX(Obj)));
	    		Obj_SetSpeed(Obj, 0.6);
	    		ObjShot_SetGraphic(Obj, graphic-5);    
            		count--;
	    		}
        	}

        	if(count<=0){ break; }
    
        	yield;
    		}
	}

	task moveA{
		loop{
			SetAngle(angle-A);
			wait(1);
			A+=3;
			yield;
		}
	}

	@Finalize{
	}

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


script_enemy BARD2{
	let imgeff   = GetCurrentScriptDirectory ~ "img\effect2.png";
	let seShot5  = GetCurrentScriptDirectory ~ "se\sha00.wav";
	let angle=GetAngle;
	let A=0;

	@Initialize{
        SetLife(500);
	LoadGraphic(imgeff);
	LoadSE(seShot5);
	Main;
	}

	@DrawLoop{
	AuraEffect;
	BardEffect;
	}

	task BardEffect{
		let x=GetX;let y=GetY;
		let Obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(Obj,imgeff);
		ObjEffect_SetLayer(Obj,1);
		ObjEffect_SetRenderState(Obj,ADD);
		ObjEffect_SetPrimitiveType(Obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(Obj,4);
		ObjEffect_SetAngle(Obj,0,0,angle+90-A);

		ObjEffect_SetVertexXY(Obj, 0, -20, -20);
		ObjEffect_SetVertexXY(Obj, 1, -20,  20);
		ObjEffect_SetVertexXY(Obj, 2,  20, -20);
		ObjEffect_SetVertexXY(Obj, 3,  20, 20);

		ObjEffect_SetVertexUV(Obj, 0, 80, 80);
		ObjEffect_SetVertexUV(Obj, 1, 80, 120);
		ObjEffect_SetVertexUV(Obj, 2, 120, 80);
		ObjEffect_SetVertexUV(Obj, 3, 120, 120);

		let scale=1;let alpha=128;
		while(alpha>10)
		{
			Obj_SetPosition(Obj,x,y);
			ObjEffect_SetScale(Obj,scale,scale);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(Obj,a,alpha,255,255,255);
			}
			alpha-=20;
			scale+=0.01;
			yield;
		}
		Obj_Delete(Obj);
	}

	task AuraEffect{
		let x=GetX;let y=GetY;
		let Obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(Obj,imgeff);
		ObjEffect_SetLayer(Obj,1);
		ObjEffect_SetRenderState(Obj,ADD);
		ObjEffect_SetPrimitiveType(Obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(Obj,4);
		ObjEffect_SetAngle(Obj,0,0,angle+90-A);

		ObjEffect_SetVertexXY(Obj, 0, -20, -20);
		ObjEffect_SetVertexXY(Obj, 1, -20,  20);
		ObjEffect_SetVertexXY(Obj, 2,  20, -20);
		ObjEffect_SetVertexXY(Obj, 3,  20, 20);

		ObjEffect_SetVertexUV(Obj, 0, 0, 0);
		ObjEffect_SetVertexUV(Obj, 1, 0, 40);
		ObjEffect_SetVertexUV(Obj, 2, 40, 0);
		ObjEffect_SetVertexUV(Obj, 3, 40, 40);

		let scale=1.3;let alpha=48;
		while(alpha>10)
		{
			Obj_SetPosition(Obj,x,y);
			ObjEffect_SetScale(Obj,scale,scale);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(Obj,a,alpha,255,255,255);
			}
			alpha-=5;
			scale+=0.01;
			yield;
		}
		Obj_Delete(Obj);
	}

	@MainLoop{
		yield;
	}

	task Main{
		yield;
		shotA;
		moveA;
	}

	task shotA{
		loop{
		CreateReflectShot(GetX,GetY,2.5,angle-A-180,150,0,1);
		PlaySE(seShot5);
		wait(40);
		yield;
		}
	}

	task CreateReflectShot(let x, let y, let speed,
        	let angle, let graphic, let delay, let count) {
    
    		let Obj = Obj_Create(OBJ_SHOT);
    
   		Obj_SetPosition(Obj, x, y);
   	 	Obj_SetSpeed(Obj, speed);
    		Obj_SetAngle(Obj, angle);
    		ObjShot_SetGraphic(Obj, graphic);
    		ObjShot_SetDelay(Obj, delay);

    
    		while(!Obj_BeDeleted(Obj)) {
        		if(((Obj_GetX(Obj)-GetX)^2+(Obj_GetY(Obj)-GetY)^2)^0.5>300){
	    		let a=0;
	    		loop(1){
	    		loop(11){
	    		Obj_SetSpeed(Obj,speed-a);
	    		a+=2.5/10;
	    		wait(4)
	    		}
	    		wait(10);
	    		let mi=GetPlayerX;
	    		let me=GetPlayerY;
            		Obj_SetAngle(Obj, atan2(me-Obj_GetY(Obj),mi-Obj_GetX(Obj)));
	    		Obj_SetSpeed(Obj, 0.6);
	    		ObjShot_SetGraphic(Obj, graphic-5);    
            		count--;
	    		}
        	}

        	if(count<=0){ break; }
    
        	yield;
    		}
	}

	task moveA{
		loop{
			SetAngle(angle-A);
			wait(1);
			A-=3;
			yield;
		}
	}

	@Finalize{
	}

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