#Title[ʏQ]
#Text[̒ʏ]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_devil.png";
	let Motion=0;
	let angle=0;
	let angleA=0;
	let angleB=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
        let r = 0;
	let shotseA = csd~"se\ShotSE01.wav";
	let BGM_A = csd~"BGM\BGM1";

    @Initialize {

        SetLife(2000);
        SetTimer(50);
        SetDamageRate(100,100);
	SetEnemyMarker(true);

        SetInvincibility(200);
        SetMovePosition02(GetCenterX(),150,60);
	LoadGraphic(imgBoss);
	LoadMusic(BGM_A);
        TAnime1;
    }

        @MainLoop
        {
	if(count==1){
		PlayMusic(BGM_A);
		}
	if(count==150){
		Motion=1;
		Concentration01(60);
        	}
	if(count>=200&&count%50==0){
		angle=GetAngleToPlayer;
		PlaySE(shotseA);
		let i=0;
		while(i<6)
		{
			let shotA=0;
			CreateShotA(shotA,GetX+cos(i*60+angle)*40,GetY+sin(i*60+angle)*40,0);
			SetShotDataA(shotA,0,2,i*60+angle,0,0.01,5,BLUE03);
			let j=5;
			while(j<360)
			{
			angleA=rand(-15,15);
			angleB=rand(-15,15);
			let ta=1;
			CreateShotA(ta,angleA,angleB,10);
			SetShotDataA(ta,0,rand(0.5,1.5),rand(0,360),0,0,0,BLUE31);
			SetShotKillTime(ta,50);
			AddShot(j,shotA,ta,0);
			j++;
			}
		FireShot(shotA);
		i++;
		}
		}
	if(count>=400&&count%400==0){
		TAnime2;
		SetMovePosition02(rand(cx-75,cx+75),rand(80,180),50);
		}
        SetCollisionB(GetX(),GetY(),18);
	SetCollisionA(GetX(),GetY(),18);
        count++;
        yield;
        }

        @DrawLoop {
	if(Motion==0){
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		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,384,383,511);}
		else if(GetSpeedX()<0){SetGraphicRect(256,128,383,255);}
		DrawGraphic(GetX(),GetY());
		}
	if(Motion==1){
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicAngle(0,0,0);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(0,128*AnimationB,127,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());
		}
	}

        @Finalize
        {
        }

    	task TAnime1{
		loop{
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			}
		}

    	task TAnime2{
			AnimationA=0;
        		loop(10){yield;}
			AnimationA=1;
        		loop(30){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}
}