#Title[西行寺幽々子]
#Text[西行寺幽々子の通常１]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let angle=0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_yuyuko.png";
	let shotseA = csd~"se\ShotSE02.wav";

	@Initialize
	{
	SetLife(3000);
	SetTimer(50);
        SetDamageRate(100,100);
        SetInvincibility(200);
	LoadGraphic(imgBoss);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	SetEnemyMarker(true);
        TAnime;
	}
	
        @MainLoop
        {
	if(count==150){
		Concentration01(60);
		}
	if(count>=200&&count%20==0){
		PlaySE(shotseA);
		angle=rand(0,360);
        	SetShotDirectionType(ABSOLUTE);
			let i=0;
			while(i<15){
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),0);
			SetShotDataA(shotA,0,1,i*24+angle,1,0,0,226);
			SetShotDataA(shotA,100,NULL,NULL,0,0.01,1.5,226);
			FireShot(shotA);
			i++;
			}
		}
	if(count>=200&&count%20==10){
		PlaySE(shotseA);
		angle=rand(0,360);
        	SetShotDirectionType(ABSOLUTE);
			let i=0;
			while(i<15){
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),0);
			SetShotDataA(shotA,0,1,i*24+angle,-1,0,0,221);
			SetShotDataA(shotA,100,NULL,NULL,0,0.01,1.5,221);
			FireShot(shotA);
			i++;
			}
		}
	if(count>=250&&count%100==50){
		SetMovePositionRandom01(rand(20,40),rand(20,40),1,GetClipMinX()+150,100,GetClipMaxX()-150,175);
		}
        SetCollisionB(GetX(),GetY(),18);
	SetCollisionA(GetX(),GetY(),18);
        count++;
	yield;
        }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		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());
	}
        
        @Finalize
        {
		DeleteGraphic(imgBoss);
        }

	task TAnime{
		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(50){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}

task move{
	let wMove = 60;
	moveToPlayer(rand(40,120),rand(-40,40),wMove,GetClipMinX+48,GetClipMinY+32,GetClipMaxX-48,GetClipMinY+128);
	wait(wMove);
	}

function moveToPlayer(xMove,yAdd,frame,left,top,right,bottom){
	let x;
	let y;

	if(GetPlayerX<GetX){//プレイヤーより右に敵がいれば、敵は左に動きます。
		x=GetX-xMove;

		//但し、敵が可動領域の左端よりも左にいくようなら、右に動きます。
			if(x<left){
				x=GetX+xMove;
 			}
		} else {
		//さもなくば、敵は右に動きます。
		x=GetX+xMove;

		// 但し、敵が可動領域の右端よりも右にいくようなら、左に動きます。
		if(right<x){
			x=GetX-xMove;
			}
		}
	y=GetY+yAdd;
	if(y<top) {
		y=top;
	} else if(bottom<y){
		y=bottom;
		}
	SetMovePosition02(x,y,frame);
	}
function wait(w) {
	loop(w){yield;}
	}
}