#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 imgEnemy2=csd~"img\familiar.png";
        let imgEnemy=csd~"img\familiar3.png";
        let angle=0;
        let angleB=0;
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let Flag=false;
	let imgALP2=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let shotseA=csd~"se\ShotSE02.wav";
	let shotseB=csd~"se\Powar.wav";
	let shotseD=csd~"se\BOM.wav";
	let imgAngle=0;
	let imgALP1=255;
	let imgALP2=0;

    @Initialize {
        CutIn(YOUMU,name,0,0,0,0,0);
        SetLife(10000);
        SetTimer(150);
        SetScore(3000000);
        SetInvincibility(200);
        SetMovePosition02(cx,120,60);
	SetEffectForZeroLife(60,0,1);
        SetMovePosition02(GetCenterX(),180,50);
	LoadGraphic(imgBoss);
	LoadGraphic(imgEnemy);
	LoadGraphic(imgEnemy2);
	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(100,0);
        SetEnemyMarker(true);}
        else {
        imgALP2=0;
        imgALP1=255;
	SetDamageRate(0,0);
	SetEnemyMarker(false);}

	if(count==150){
		Concentration01(60);
		}
	if(count>=200&&count%400==200){
        	SetShotDirectionType(ABSOLUTE);
		angle=GetAngleToPlayer;
		let i=0;
		while(i<8)
			{
			CreateEnemyFromScript("DOLL01",GetEnemyX+cos(angle+i*45),GetEnemyY+sin(angle+i*45),2,angle+i*45,i);
			i++;
			}
		}
	if(count>=200&&count%400==325){
		PlaySE(shotseB);
		}
	if(GetEnemyLife<6000||GetTimer<=49&&count>=200&&count%400==0){
        	SetShotDirectionType(ABSOLUTE);
		angle=GetAngleToPlayer;
		let i=0;
		while(i<8)
			{
			CreateEnemyFromScript("DOLL01",GetEnemyX+cos(angle+i*45),GetEnemyY+sin(angle+i*45),2,angle+i*45,i);
			i++;
			}
		}
	if(GetEnemyLife<6000||GetTimer<=49&&count>=200&&count%400==125){
		PlaySE(shotseB);
		}

	if(GetEnemyLife<7500||GetTimer<=89&&count>=250&&count%4==0){
		PlaySE(shotseA);
        	let shot01=1;
        	SetShotDirectionType(ABSOLUTE);
        	CreateShotA(shot01,GetX(),GetY(),5);
        	SetShotDataA(shot01,0,2,angleB+rand(-20,20),0,-0.01,0.5,61);
        	FireShot(shot01);
        	CreateShotA(shot01,GetX(),GetY(),5);
        	SetShotDataA(shot01,0,2,angleB+90+rand(-20,20),0,-0.01,0.5,64);
        	FireShot(shot01);
        	CreateShotA(shot01,GetX(),GetY(),5);
        	SetShotDataA(shot01,0,2,angleB+180+rand(-20,20),0,-0.01,0.5,66);
        	FireShot(shot01);
        	CreateShotA(shot01,GetX(),GetY(),5);
        	SetShotDataA(shot01,0,2,angleB+270+rand(-20,20),0,-0.01,0.5,68);
        	FireShot(shot01);
		angleB=angleB+10;
		}
        if(GetEnemyLife<1&&!Flag){
			Flag=true;
			Explosion01(GetX(),GetY(),1/60*255,0.3,60);
			PlaySE(shotseD);
        	}
        count++;
        yield;

}
	@Finalize {
		PlaySE(shotseD);
		DeleteGraphic(imgBoss);
		DeleteGraphic(imgEnemy);
		DeleteGraphic(imgEnemy2);
	}

        @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);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(128*AnimationC,128*AnimationB,127+128*AnimationC,127+128*AnimationB);}
		else if(GetSpeedX()>0){SetGraphicRect(256,256+128*AnimationA,383,383+128*AnimationA);}
		else if(GetSpeedX()<0){SetGraphicRect(256,128*AnimationA,383,127+128*AnimationA);}
		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 TAnime2{
			AnimationA=0;
        		loop(10){yield;}
			AnimationA=1;
        		loop(50){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}
}

script_enemy DOLL01 {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
	let MAnimation=0;
	let imgEnemy2=csd~"img\familiar.png";
	let imgAngle=0;
        let angle=GetAngle;
        let Type=GetArgument;
	let r=0;
	let shotseA = csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(1000);
        SetInvincibility(0);
    }

        @MainLoop
        {
	imgAngle+=4;
	if(imgAngle>360){imgAngle=0;}
	MAnimation-=10;
	if(MAnimation<-360){MAnimation=0;}
	if(count==50){
		r=((GetX-GetEnemyX)^2+(GetY-GetEnemyY)^2)^0.5;
		SetMovePosition02(GetEnemyX+cos(angle+90)*r,GetEnemyY+sin(angle+90)*r,50);
		}
	if(count>50&&count<=100){
		PlaySE(shotseA);
		if(Type%2==0){
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,0,angle-180,0,0,0,67);
			SetShotDataA(shotA,126-count,2,NULL,0,-0.02,1,151+Type);
			SetShotDataA(shotA,175-count,1,NULL,0.1,0,1,151+Type);
			FireShot(shotA);
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,0,angle,0,0,0,67);
			SetShotDataA(shotA,126-count,2,NULL,0,-0.01,1,151+Type);
			SetShotDataA(shotA,175-count,NULL,NULL,0.1,0,1,151+Type);
			FireShot(shotA);
			} else {
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,0,angle-180,0,0,0,67);
			SetShotDataA(shotA,126-count,2,NULL,0,-0.02,1,151+Type);
			SetShotDataA(shotA,175-count,1,NULL,-0.1,0,1,151+Type);
			FireShot(shotA);
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,0,angle,0,0,0,67);
			SetShotDataA(shotA,126-count,2,NULL,0,-0.01,1,151+Type);
			SetShotDataA(shotA,175-count,NULL,NULL,-0.1,0,1,151+Type);
			FireShot(shotA);
			}
		angle+=25;
		}
	if(count==100){
		r=((GetX-GetEnemyX)^2+(GetY-GetEnemyY)^2)^0.5;
		SetMovePosition02(GetEnemyX+cos(angle+90)*r*4,GetEnemyY+sin(angle+90)*r*4,100);
		}
	if(count>200){
		VanishEnemy();
		}
        count++;
        }

        @DrawLoop {
		SetGraphicRect(288,48,336,96);
		SetTexture(imgEnemy2);
		SetGraphicScale(1,1);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());
		SetGraphicAngle(0,0,-imgAngle);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }
}