#Title[怨霊「死念魔蝶」]
#Text[西行寺幽々子のスペルカード]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="怨霊「死念魔蝶」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\dot_yuyuko.png";
        let imgEnemy=csd~"img\familiar3.png";
        let angle=0;
	let angleB=0;
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let shotseA=csd~"se\ShotSE02.wav";
	let imgAngle=0;
	let imgALP1=255;
	let imgALP2=0;

    @Initialize {
        CutIn(YOUMU,name,0,0,0,0,0);
        SetLife(1400);
        SetTimer(75);
        SetScore(3000000);
        SetDamageRate(40,0);
        SetInvincibility(200);
        SetMovePosition02(GetCenterX(),150,50);
	LoadGraphic(imgBoss);
	LoadGraphic(imgEnemy);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
        TAnime1;
	}

        @MainLoop
        {
	imgAngle+=0.5;
	if(imgAngle>=360){imgAngle=0;}

        if(!OnBomb){
        SetCollisionB(GetX(),GetY(),22);
	SetCollisionA(GetX(),GetY(),22);
        imgALP2=255;
        imgALP1=100;
	SetDamageRate(40,0);
        SetEnemyMarker(true);}
        else {
        imgALP2=0;
        imgALP1=255;
	SetDamageRate(0,0);
	SetEnemyMarker(false);}

        if(count>=400&&count%50==0){
		PlaySE(shotseA);
		angle=rand(0,360);
		let i=0;
		while(i<10){
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,0.5,i*36+angle,0,0.01,1,226);
			FireShot(shotA);
			i++;
			}
		}
		if(count>=200&&count%100==0){
			PlaySE(shotseA);
			FiraShotA;
			if(GetEnemyLife<600||GetTimer<=30){FiraShotB;}
		}
        count++;
        yield;

}
	@Finalize {
		if(!IsTimeOut){
			CreateItem(ITEM_BOMB,GetX,GetY);
			loop(50){
				angle=rand(0,360);
				CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,45),GetY+sin(angle)*rand(35,45));
			}
		}
		DeleteGraphic(imgBoss);
		DeleteGraphic(imgEnemy);
	}

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgEnemy);
		SetGraphicRect(0,0,192,192);
		SetAlpha(imgALP1);
		SetColor(255,255,255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());

		SetTexture(imgBoss);
		SetAlpha(255);
		SetColor(imgALP2,imgALP2,imgALP2);
		SetGraphicAngle(0,0,0);
		SetGraphicRect(128*AnimationC,128*AnimationB,127+128*AnimationC,127+128*AnimationB);
		DrawGraphic(GetX(),GetY());
		}

    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(16){yield;}
			AnimationB=1;
        		loop(46){yield;}
			AnimationB=0;
        		loop(8){yield;}
		loop(2){
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			}
			AnimationB=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=0;
			AnimationC=5;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
		}

task FiraShotA{
	let obj = Obj_Create(OBJ_SHOT);
	let shotseC = csd~"se\ShotSE01.wav";
	Obj_SetPosition(obj,GetX,GetY);
	Obj_SetSpeed(obj,2);
	ObjShot_SetGraphic(obj,227);
	ObjShot_SetDelay(obj,5);
	ObjShot_SetBombResist(obj,true);

	while(!Obj_BeDeleted(obj)){
		loop(100){
			Obj_SetAngle(obj,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj)));
			yield;}
			PlaySE(shotseC);
			let i=0.5;
			while(i<5){
			let id=0;
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,i,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))-20,0,0,0,227);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,i,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))-10,0,0,0,227);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,i,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj)),0,0,0,227);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,i,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+10,0,0,0,227);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,i,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+20,0,0,0,227);
			FireShot(id);
			i+=0.5;
			}
		Obj_Delete(obj);
		}
	}

task FiraShotB{
	let obj = Obj_Create(OBJ_SHOT);
	let shotseC = csd~"se\ShotSE01.wav";
	Obj_SetPosition(obj,GetX,GetY);
	Obj_SetSpeed(obj,2);
	ObjShot_SetGraphic(obj,221);
	ObjShot_SetDelay(obj,5);
	ObjShot_SetBombResist(obj,true);

	while(!Obj_BeDeleted(obj)){
		loop(100){
			Obj_SetAngle(obj,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj)));
			yield;}
			PlaySE(shotseC);
			let i=0;
			while(i<20){
			let id=0;
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,1,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+i*18,0,0,0,221);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,1.5,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+i*18,0,0,0,221);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,2,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+i*18,0,0,0,221);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,2.5,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+i*18,0,0,0,221);
			FireShot(id);
			CreateShotA(id,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA(id,0,3,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+i*18,0,0,0,221);
			FireShot(id);
			i++;
			}
		Obj_Delete(obj);
		}
	}
}