#Title[「廃獄のレクイエム」]
#Text[火焔猫燐のスペルカード]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="「廃獄のレクイエム」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss =csd~"img\ExOrin.png";
	let angle=0;
	let Flag=false;
	let imgALP2=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let shotseA=csd~"se\ShotSE02.wav";
	let shotseD = csd~"se\BOM.wav";

    @Initialize {
    CutIn(YOUMU,name,0,0,0,0,0);

        SetLife(10000);
        SetTimer(150);
        SetScore(3000000);
        SetDamageRate(100,0);

        SetInvincibility(200);
        SetMovePosition02(cx,120,60);
	LoadGraphic(imgBoss);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	SetEffectForZeroLife(60,0,1);
    }

        @MainLoop
        {
        if(!OnBomb){
	if(GetEnemyLife>=1){
		Flag=false;
		}
        SetCollisionB(GetX(),GetY(),18);
	SetCollisionA(GetX(),GetY(),18);
        imgALP2=255;
	SetDamageRate(100,0);
        SetEnemyMarker(true);}
        else {
	if(count>=200&&GetEnemyLife>=1&&!Flag){
		Flag=true;
		SetMovePosition02(rand(98,350),120,100);
		}
        imgALP2=75;
	SetDamageRate(0,0);
	SetEnemyMarker(false);}

	if(count>=200&&count%40==20){
		angle=rand(16,224);
		}
	if(count>=200&&count%40==0){
		angle=rand(224,432);
		}
	if(count>=200&&count%20==0){
		PlaySE(shotseA);
        		let i=0;
        		while(i<15)
        		{
        		let shot01 = 1;
        		SetShotDirectionType(ABSOLUTE);
        		CreateShotA(shot01,angle,0,5);
        		SetShotDataA(shot01, 0,1,24*i+90,0,0,0,61);
        		FireShot(shot01);
        		i++
        		}
		}
	if(GetEnemyLife<7500||GetTimer<=50&&count>=200&&count%20==0){
        		let i=0;
        		while(i<15)
        		{
        		let shot01=1;
        		SetShotDirectionType(ABSOLUTE);
        		CreateShotA(shot01,angle,0,5);
        		SetShotDataA(shot01, 0,1,24*i+102,0,0,0,61);
        		FireShot(shot01);
        		i++
        		}
		}
	if(GetEnemyLife<6000||GetTimer<=49&&count>=200&&count%20==0){
        		let shot01=1;
        		SetShotDirectionType(ABSOLUTE);
        		CreateShotA(shot01,angle,-16,5);
        		SetShotDataA(shot01, 0,0.5,90,0,0.01,rand_int(1,5),31);
        		FireShot(shot01);
		}
	if(GetEnemyLife<4000||GetTimer<=48&&count>=200&&count%80==0){
        		let shot01=1;
        		SetShotDirectionType(PLAYER);
        		CreateShotA(shot01,rand(16,432),-16,5);
        		SetShotDataA(shot01, 0,0.5,0,0,0.01,2,36);
        		FireShot(shot01);
		}
	if(GetEnemyLife<4000||GetTimer<=48&&count>=200&&count%20==0){
        		let i=0;
        		while(i<30)
        		{
        		let shot01=1;
        		SetShotDirectionType(ABSOLUTE);
        		CreateShotA(shot01,angle,0,5);
        		SetShotDataA(shot01, 0,1,12*i+96,0,0,0,61);
        		FireShot(shot01);
        		i++
        		}
		}
        if(GetEnemyLife<1&&!Flag){
			Flag=true;
			Explosion01(GetX(),GetY(),1/60*255,0.3,60);
			PlaySE(shotseD);
        	}
        count++;
        yield;
        }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(imgALP2);
		SetColor(imgALP2,imgALP2,imgALP2);
		SetGraphicAngle(0,0,0);
		if(GetSpeedX()==0){SetGraphicRect(128,0,255,127);}
		else if(GetSpeedX()>0){SetGraphicRect(384,0,511,127);}
		else if(GetSpeedX()<0){SetGraphicRect(256,0,383,127);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
		PlaySE(shotseD);
		if(!IsTimeOut&&GetPlayerLife>=2&&!Continued){
			CreateItem(ITEM_1UP,GetX,GetY);
		}
		if(!IsTimeOut&&!Continued){
			loop(200){
				angle=rand(0,360);
				CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(45,55),GetY+sin(angle)*rand(45,55));
			}
		}
		DeleteGraphic(imgBoss);
        }
}