#Title[小悪魔通常１]
#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 cx=GetCenterX();
        let cy=GetCenterY();
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
        let r = 0;
	let shotseA = csd~"se\ShotSE02.wav";

    @Initialize {

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

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

        @MainLoop
        {
	if(count==150){
		Motion=1;
		Concentration01(60);
        	}
	if(count>=200&&count%20==0){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		let i=0;
		while(i<6)
		{
        	let shot01 = 1;
        	CreateShotA(shot01,GetX+cos(i*60+angle)*40,GetY+sin(i*60+angle)*40,10);
        	SetShotDataA(shot01,0,3,i*60+angle,0,0,0,BLUE03);
        	FireShot(shot01);
		i++;
		}
		angle=angle+15;
		}
	if(count>=400&&count%10==0){
        	SetShotDirectionType(PLAYER);
		PlaySE(shotseA);
		let i=0;
		while(i<6)
		{
        	let shot01 = 1;
        	CreateShotA(shot01,GetX+cos(i*60+angle)*40,GetY+sin(i*60+angle)*40,10);
        	SetShotDataA(shot01,0,4,i*60-angle,0,0,0,PURPLE03);
        	FireShot(shot01);
		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;}
		}
}