
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(800);
		SetTimer(70);
		SetScore(1300000);
		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;
		moveA;
		Att1;
		Att2;
	}

	task Att1{
		let angle=0;
		loop{
			CreateEnemyFromScript("BARD", GetX, GetY, 1.5, angle, 0);
			CreateEnemyFromScript("BARD", GetX, GetY, 1.5, angle+180, 0);
			angle+=180;
			wait(240);
		}		
	}

	task Att2{
		let angle=90;
		wait(120);
		loop{
			CreateEnemyFromScript("BARD", GetX, GetY, 1.5, angle, 0);
			CreateEnemyFromScript("BARD", GetX, GetY, 1.5, angle+180, 0);
			angle+=180;
			wait(240);
		}		
	}

	task moveA {
		loop{
      		wait(240);
		if(GetX<=GetPlayerX&&GetX<360||GetX<120){
			if(GetY>140){
			SetAction(ACT_MOVE,60);
			SetMovePosition02(GetX+50,GetY-30,30);
			}
			else if(GetY<100){
			SetAction(ACT_MOVE,60);
			SetMovePosition02(GetX+50,GetY+30,30);
			}
			else{
			SetAction(ACT_MOVE,60);
			SetMovePosition02(GetX+50,GetY+rand(-30,30),30);
			}
		}
		else{
			if(GetY>140){
			SetAction(ACT_MOVE,60);
			SetMovePosition02(GetX-50,GetY-30,30);
			}
			else if(GetY<100){
			SetAction(ACT_MOVE,60);
			SetMovePosition02(GetX-50,GetY+30,30);
			}
			else{
			SetAction(ACT_MOVE,60);
			SetMovePosition02(GetX-50,GetY+rand(-30,30),30);
			}
		}
		yield;
		}
	}

	@Finalize{
		DeleteGraphic(imgBoss);
		Delete;
	}

}


script_enemy BARD{
	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, 40);
		ObjEffect_SetVertexUV(Obj, 1, 0, 80);
		ObjEffect_SetVertexUV(Obj, 2, 40, 40);
		ObjEffect_SetVertexUV(Obj, 3, 40, 80);

		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;
	}

	task shotA{
		loop{
			if(GetY>GetClipMinY&&GetY<GetClipMaxY&&GetX>GetClipMinX&&GetX<GetClipMaxX){
			CreateReflectShot(GetX,GetY,2.3,angle+90,94,0);
			CreateReflectShot(GetX,GetY,2.3,angle-90,94,0);
			}
			PlaySE(seShot5);
			wait(20);
			yield;
		}
	}

	task CreateReflectShot(let x, let y, let speed,let angle, let graphic, let delay) {
    		let Obj = Obj_Create(OBJ_SHOT);
		let count=1;
    
    		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_GetY(Obj)<GetClipMinY){
            			Obj_SetY(Obj, GetClipMinY*2 - Obj_GetY(Obj));
            			Obj_SetAngle(Obj, Obj_GetAngle(Obj)-180);
	    			ObjShot_SetGraphic(Obj,95);
	    			Obj_SetSpeed(Obj, 2.7);
            			count--;
        		}
        		if(Obj_GetY(Obj)>GetClipMaxY){
            			Obj_SetY(Obj, GetClipMaxY*2 - Obj_GetY(Obj));
            			Obj_SetAngle(Obj, Obj_GetAngle(Obj)-180);
	    			ObjShot_SetGraphic(Obj,95);
	   		 	Obj_SetSpeed(Obj, 2.7);
            			count--;
        		}
        		if(Obj_GetX(Obj)<GetClipMinX){
            			Obj_SetX(Obj, GetClipMinX*2 - Obj_GetX(Obj));
            			Obj_SetAngle(Obj, Obj_GetAngle(Obj)-180);
	    			ObjShot_SetGraphic(Obj,95);
	    			Obj_SetSpeed(Obj, 2.7);
            			count--;
        		}
        		if(Obj_GetX(Obj)>GetClipMaxX){
            			Obj_SetX(Obj,GetClipMaxX*2 - Obj_GetX(Obj));
            			Obj_SetAngle(Obj, Obj_GetAngle(Obj)-180);
	    			ObjShot_SetGraphic(Obj,95);
	   		 	Obj_SetSpeed(Obj, 2.7);
            			count--;
        		}

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

	@Finalize{
	}

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