#Title[死鎌「ダブルハーケン」]
#Text[小野塚小町のスペルカード]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="死鎌「ダブルハーケン」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\dot_komachi.png";
	let angle=0;
	let r=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;

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

        SetLife(800);
        SetTimer(60);
        SetScore(2500000);
        SetDamageRate(20,20);
        SetInvincibility(200);
	SetMovePosition02(cx,150,60);
	LoadGraphic(imgBoss);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
        TAnime1;
        }

        @MainLoop
        {
	if(count==150){
		Concentration01(60);
		}
	if(count==200){
		angle=GetAngleToPlayer-180;
		r=((GetPlayerX-GetX)^2+(GetPlayerY-GetY)^2)^0.5;
		CreateEnemyFromScript("DOLL01",GetX,GetY,-10,angle,r);
		CreateEnemyFromScript("DOLL01",GetX,GetY,10,angle,r);
		}
	if(count==370){
        	TAnime2;
		move;
		}
	if(count==610){
        	count=149;
		}
        SetCollisionB(GetX(),GetY(),18);
	SetCollisionA(GetX(),GetY(),18);
        count++;
        yield;
        }

        @DrawLoop {
		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(896,256+128*AnimationA,1023,383+128*AnimationA);}
		else if(GetSpeedX()<0){SetGraphicRect(896,128*AnimationA,1023,127+128*AnimationA);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
		if(!IsTimeOut){
			loop(50){
				angle=rand(0,360);
				CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,45),GetY+sin(angle)*rand(35,45));
			}
		}
		DeleteGraphic(imgBoss);
        }

    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(16){yield;}
			AnimationB=1;
        		loop(56){yield;}
			AnimationB=0;
        		loop(8){yield;}
		loop(2){
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			}
		loop{
			AnimationC=5;
			AnimationB=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(40){yield;}
			AnimationB=2;
        		loop(10){yield;}
			AnimationB=3;
			AnimationC=4;
        		loop(170){yield;}
		loop(7){
			AnimationB=0;
			AnimationC=6;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			}
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			}
		}

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

task move{
	let wMove = 60;
	moveToPlayer(rand(60,150),rand(-50,50),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;}
	}
}

script_enemy DOLL01 {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
	let MAnimation=0;
        let angle=GetAngle;
        let l=GetArgument/18;
        let r=0;
	let s=GetSpeed;
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\dot_komachi.png";
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(50);
        SetScore(0);
        SetDamageRateEx(0,0,0,0);
	}

    @MainLoop {
	MAnimation-=40;
	if(MAnimation<-360){MAnimation=0;}
        if(count<=180&&count%10==0)
        	{
		SetMovePosition02(GetEnemyX+cos(angle)*r,GetEnemyY+sin(angle)*r,10);
        	angle+=s;
        	r+=l;
        	}
        if(count>=20&&count<=190)
        	{
		PlaySE(shotseA);
		SetShotDirectionType(ABSOLUTE);
		let shot01=1;
		CreateShotA(shot01,GetX,GetY,5);
		SetShotDataA(shot01,0,1,rand(0,360),0,0,1,51);
		FireShot(shot01);
        	}
        if(count==190)
        	{
		PlaySE("seSuperNaturalBorder1.wav");
		let i=0;
		while(i<30){
			SetShotDirectionType(ABSOLUTE);
			let shot01=1;
			CreateShotA(shot01,GetX,GetY,0);
			SetShotDataA(shot01,0,rand(0.5,7),rand(0,360),0,-0.01,0.5,1);
			FireShot(shot01);
			CreateShotA(shot01,GetX,GetY,0);
			SetShotDataA(shot01,0,rand(0.5,6),rand(0,360),0,-0.01,0.5,31);
			FireShot(shot01);
			CreateShotA(shot01,GetX,GetY,0);
			SetShotDataA(shot01,0,rand(0.5,5),rand(0,360),0,-0.01,0.5,21);
			FireShot(shot01);
			i++;
			}
        	}
        if(count>180&&count%10==0)
        	{
		SetMovePosition02(GetEnemyX+cos(angle)*r,GetEnemyY+sin(angle)*r,10);
        	angle+=s;
        	r-=l;
        	}
        if(count>380)
        	{
		VanishEnemy;
        	}
	count++;
	yield;
	}

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(s/10,1);
		SetAlpha(255);
		SetGraphicRect(768,384,895,511);
		SetGraphicAngle(0,0,MAnimation);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }
}