#Title[ʏR]
#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\ShotSE05.wav";

    @Initialize {

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

        SetInvincibility(200);
	LoadGraphic(imgBoss);
        TAnime1;
    }

        @MainLoop
        {
	if(count==150){
		Motion=1;
		Concentration01(60);
        	}
	if(count>=200&&count%20==0){
		angle=GetAngleToPlayer;
		PlaySE(shotseA);
		let i=0;
		while(i<10)
		{
			let shotA=0;
			CreateShotA(shotA,GetX+rand(-100,100),GetY+rand(-100,100),5);
			SetShotDataA(shotA,0,0,angle,0,0.02,5,BLUE01);
			FireShot(shotA);
			CreateShotA(shotA,GetX+rand(-100,100),GetY+rand(-100,100),5);
			SetShotDataA(shotA,0,0,angle+60,0,0.02,5,PURPLE01);
			FireShot(shotA);
			CreateShotA(shotA,GetX+rand(-100,100),GetY+rand(-100,100),5);
			SetShotDataA(shotA,0,0,angle+120,0,0.02,5,RED01);
			FireShot(shotA);
			CreateShotA(shotA,GetX+rand(-100,100),GetY+rand(-100,100),5);
			SetShotDataA(shotA,0,0,angle-120,0,0.02,5,RED01);
			FireShot(shotA);
			CreateShotA(shotA,GetX+rand(-100,100),GetY+rand(-100,100),5);
			SetShotDataA(shotA,0,0,angle-60,0,0.02,5,PURPLE01);
			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;}
		}
}