#Title[人形「魂のないフォークダンス」]
#Text[アリスのスペルカード]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="人形「魂のないフォークダンス」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\dot_EXalice.png";
        let imgBoss2=csd~"img\dot_yousei.png";
        let angle=0;
	let Motion=0;
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let shotseD = csd~"se\BOM.wav";
	let Flag=false;

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

        SetLife(3000);
        SetTimer(40);
        SetScore(1500000);
        SetDamageRate(100,100);
        SetInvincibility(300);
        SetMovePosition02(GetCenterX(),150,50);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBoss2);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	SetEffectForZeroLife(30,0,0);
        TAnime1;
    }

        @MainLoop
        {
	if(count==150){
		Concentration01(60);
		}
	if(count>=200&&count%600==200){
		let i=0;
		while(i<2){
			CreateEnemyFromScript("DOLLA",GetX,GetY,2,i*180+60,2);
			CreateEnemyFromScript("DOLLB",GetX,GetY,2,i*180,2);
			CreateEnemyFromScript("DOLLC",GetX,GetY,2,i*180-60,2);
			i++;
			}
		}
	if(count>=200&&count%600==500){
		let i=0;
		while(i<2){
			CreateEnemyFromScript("DOLLA",GetX,GetY,2,i*180+60,-2);
			CreateEnemyFromScript("DOLLB",GetX,GetY,2,i*180,-2);
			CreateEnemyFromScript("DOLLC",GetX,GetY,2,i*180-60,-2);
			i++;
			}
		}
	if(count>=200&&count%300==0){
		let i=0;
        	while(i<8){
        		SetShotDirectionType(PLAYER);
        		CreateShotA(1,GetX,GetY,0);
        		SetShotDataA(1,0,1.5,45*i,0,0,1.5,33);
        		FireShot(1);
        		i++;
			}
		}
	if(count>=400&&count%150==100){
                TAnime2;
		move;
		}
        if(GetEnemyLife<1&&!Flag){
		Flag=true;
		Explosion01(GetX(),GetY(),1/60*255,0.3,60);
		PlaySE(shotseD);
        	}
        SetCollisionA(GetX(),GetY(),18);
        SetCollisionB(GetX(),GetY(),18);
        count++;
        yield;
}
	@Finalize {
		PlaySE(shotseD);
		DeleteGraphic(imgBoss);
		DeleteGraphic(imgBoss2);
	}

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

    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(16){yield;}
			AnimationB=1;
        		loop(56){yield;}
			AnimationB=0;
        		loop(8){yield;}
		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(40){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}

task move {
    let wMove = 60;

    moveToPlayer(rand(60,120),rand(-80,80),wMove,GetClipMinX+48,GetClipMinY+64,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 DOLLA{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei.png";
	let angle=GetAngle;
	let angleX=GetEnemyX;
	let angleY=GetEnemyY;
	let angleZ=GetArgument;
	let r=0;
	let imgAngle=0;
	let imgAlpha=255;
	let deathse=csd~"se\DEATH.wav";
	let shotseA=csd~"se\ShotSE02.wav";
	let Flag=false;

    @Initialize {
        SetLife(400);
        SetDamageRateEx(100,100,75,10);
        SetInvincibility(50);
        TAnime;
	}

	@MainLoop {
	if(count==49){
		r=((GetX-GetEnemyX)^2+(GetY-GetEnemyY)^2)^0.5;
		}
	if(count>=50&&count%5==0&&Flag==false){
		SetMovePosition02(angleX+cos(angle)*r,angleY+sin(angle)*r,10);
		angle+=angleZ;
		}
	if(count>=750&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(GetLife<=100&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			PlaySE(deathse);
			Flag=true;
			}
	if(Flag==true){
		imgAngle+=15;
		imgAlpha-=5;
		if(imgAlpha<=0){VanishEnemy();}
		} else {
		SetCollisionA(GetX(),GetY(),10);
		SetCollisionB(GetX(),GetY(),10);
		}
	if(count>=50&&count%5==0&&Flag==false){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		let shotA=0;
		CreateShotA(shotA,GetX,GetY,0);
		SetShotDataA(shotA,0,2,angle+rand(-20,20),0,0,2,216);
		FireShot(shotA);
		}
	count++;
	yield;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,64,31+Animation*32,95)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation*32,96,159+Animation*32,127);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation*32,96,31+Animation*32,127);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        } 

    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}

script_enemy DOLLB{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei.png";
	let angle=GetAngle;
	let angleX=GetEnemyX;
	let angleY=GetEnemyY;
	let angleZ=GetArgument;
	let r=0;
	let imgAngle=0;
	let imgAlpha=255;
	let deathse=csd~"se\DEATH.wav";
	let shotseA=csd~"se\ShotSE02.wav";
	let Flag=false;

    @Initialize {
        SetLife(400);
        SetDamageRateEx(100,100,75,10);
        SetInvincibility(50);
        TAnime;
	}

	@MainLoop {
	if(count==49){
		r=((GetX-GetEnemyX)^2+(GetY-GetEnemyY)^2)^0.5;
		}
	if(count>=50&&count%5==0&&Flag==false){
		SetMovePosition02(angleX+cos(angle)*r,angleY+sin(angle)*r,10);
		angle+=angleZ;
		}
	if(count>=750&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(GetLife<=100&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			PlaySE(deathse);
			Flag=true;
			}
	if(Flag==true){
		imgAngle+=15;
		imgAlpha-=5;
		if(imgAlpha<=0){VanishEnemy();}
		} else {
		SetCollisionA(GetX(),GetY(),10);
		SetCollisionB(GetX(),GetY(),10);
		}
	if(count>=50&&count%5==0&&Flag==false){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		let shotA=0;
		CreateShotA(shotA,GetX,GetY,0);
		SetShotDataA(shotA,0,2,angle+rand(-20,20),0,0,2,214);
		FireShot(shotA);
		}
	count++;
	yield;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,128,31+Animation*32,159)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation*32,160,159+Animation*32,191);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation*32,160,31+Animation*32,191);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        } 

    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}

script_enemy DOLLC{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei.png";
	let angle=GetAngle;
	let angleX=GetEnemyX;
	let angleY=GetEnemyY;
	let angleZ=GetArgument;
	let r=0;
	let imgAngle=0;
	let imgAlpha=255;
	let deathse=csd~"se\DEATH.wav";
	let shotseA=csd~"se\ShotSE02.wav";
	let Flag=false;

    @Initialize {
        SetLife(400);
        SetDamageRateEx(100,100,75,10);
        SetInvincibility(50);
        TAnime;
	}

	@MainLoop {
	if(count==49){
		r=((GetX-GetEnemyX)^2+(GetY-GetEnemyY)^2)^0.5;
		}
	if(count>=50&&count%5==0&&Flag==false){
		SetMovePosition02(angleX+cos(angle)*r,angleY+sin(angle)*r,10);
		angle+=angleZ;
		}
	if(count>=750&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(GetLife<=100&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			PlaySE(deathse);
			Flag=true;
			}
	if(Flag==true){
		imgAngle+=15;
		imgAlpha-=5;
		if(imgAlpha<=0){VanishEnemy();}
		} else {
		SetCollisionA(GetX(),GetY(),10);
		SetCollisionB(GetX(),GetY(),10);
		}
	if(count>=50&&count%5==0&&Flag==false){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		let shotA=0;
		CreateShotA(shotA,GetX,GetY,0);
		SetShotDataA(shotA,0,2,angle+rand(-20,20),0,0,2,211);
		FireShot(shotA);
		}
	count++;
	yield;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,0,31+Animation*32,31)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation*32,32,159+Animation*32,63);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation*32,32,31+Animation*32,63);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        } 

    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}