#Title[崩壊「ブレイクダウン」]
#Text[古明地こいしのスペルカード]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="崩壊「ブレイクダウン」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\ExKoishi.png";
	let imgEnemy=csd~"img\familiar.png";
        let ranX=0;
        let ranY=0;
        let ranA=0;
	let angle=0;
	let Animation=0;
	let Motion=0;
	let shotseA=csd~"se\ShotSE02.wav";
	let shotseD = csd~"se\BOM.wav";
	let Flag=false;

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

        SetLife(4000);
        SetTimer(60);
        SetScore(2000000);
        SetDamageRate(100,100);

        SetInvincibility(200);
        SetMovePosition02(GetCenterX(),150,60);
	LoadGraphic(imgBoss);
	LoadGraphic(imgEnemy);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	SetEffectForZeroLife(30,0,0);
	}

        @MainLoop
        {
	if(count==150){
		CreateEnemyFromScript("DOLL01",GetX,GetY,0,0,1);
		CreateEnemyFromScript("DOLL02",GetX,GetY,0,0,1);
		}
	if(count>=300&&count%200==0){
		SetMovePositionRandom01(rand(20,40),rand(20,40),3,GetClipMinX()+150,100,GetClipMaxX()-150,175);
		}
	if(count>=400&&count%5==0){
		PlaySE(shotseA);
		ranX=rand(-5,5);
		ranY=rand(-5,5);
		ranA=rand(-10,10);
		let i=0;
		while(i<5)
		{
			let shotA=0;
			CreateShotA(shotA,GetX+ranX,GetY+ranY,5);
			SetShotDataA(shotA,0,rand(2,3),angle+i*72+ranA,0,0,0,83);
			FireShot(shotA);
			i++;
			}
		angle-=4;
		}
        if(GetEnemyLife<1&&!Flag){
		Flag=true;
		Explosion01(GetX(),GetY(),1/60*255,0.3,60);
		PlaySE(shotseD);
        	}
        SetCollisionB(GetX(),GetY(),18);
	SetCollisionA(GetX(),GetY(),18);
        count++;
        }

	@Finalize {
		PlaySE(shotseD);
		DeleteGraphic(imgBoss);
		DeleteGraphic(imgEnemy);
	}

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicAngle(0,0,0);
	if(Motion==0){
		if(int(GetSpeedX())==0)
		{SetGraphicRect(128,0,255,127);}
		else if(GetSpeedX()>0){SetGraphicRect(384,0,511,127);}
		else if(GetSpeedX()<0){SetGraphicRect(256,0,383,127);}
		}
	if(Motion==1){
		SetGraphicRect(0,0,127,127);
		}
		DrawGraphic(GetX(),GetY());
	}
}

script_enemy DOLL01 {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
	let MAnimation=0;
	let imgEnemy=csd~"img\familiar.png";
	let imgAngle=0;
	let angle=0;
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(1000);
        SetInvincibility(0);
	SetMovePositionHermite(GetEnemyX-100,GetEnemyY-100,200,130,200,320,100);
    }

        @MainLoop
        {
	imgAngle+=4;
	if(imgAngle>360){imgAngle=0;}
	MAnimation-=10;
	if(MAnimation<-360){MAnimation=0;}
	if(count>=100&&count%200==100){
	SetMovePositionHermite(GetEnemyX+100,GetEnemyY+100,200,-50,200,140,100);
	}
	if(count>=200&&count%200==0){
	SetMovePositionHermite(GetEnemyX-100,GetEnemyY-100,200,130,200,320,100);
	}
	if(count>=100&&count%2==0){
	PlaySE(shotseA);
	FiraShot(angle);
	angle+=2;
	}
        count++;
        yield;
        }

        @DrawLoop {
		SetGraphicRect(288,48,336,96);
		SetTexture(imgEnemy);
		SetGraphicScale(1,1);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());
		SetGraphicAngle(0,0,-imgAngle);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }

task FiraShot(angle){
	let obj = Obj_Create(OBJ_SHOT);
	let sp = ((GetEnemyX()-Obj_GetX(obj))^2+(GetEnemyY()-Obj_GetY(obj))^2)^0.5*0.01;
	Obj_SetPosition(obj,GetX,GetY);
	Obj_SetSpeed(obj,0);
	Obj_SetAngle(obj,atan2(GetEnemyY-Obj_GetY(obj),GetEnemyX-Obj_GetX(obj))+angle);
	ObjShot_SetGraphic(obj,61);
	ObjShot_SetDelay(obj,0);
	loop(210){yield;}
		Obj_SetSpeed(obj,((GetEnemyX()-Obj_GetX(obj))^2+(GetEnemyY()-Obj_GetY(obj))^2)^0.5*0.01);
        }
}

script_enemy DOLL02 {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
	let MAnimation=0;
	let imgEnemy=csd~"img\familiar.png";
	let imgAngle=0;
	let angle=0;

    @Initialize {
        SetLife(1000);
        SetInvincibility(0);
	SetMovePositionHermite(GetEnemyX+100,GetEnemyY-100,200,50,200,220,100);
	}

        @MainLoop
        {
	imgAngle+=4;
	if(imgAngle>360){imgAngle=0;}
	MAnimation-=10;
	if(MAnimation<-360){MAnimation=0;}
	if(count>=100&&count%200==100){
	SetMovePositionHermite(GetEnemyX-100,GetEnemyY+100,200,230,200,40,100);
	}
	if(count>=200&&count%200==0){
	SetMovePositionHermite(GetEnemyX+100,GetEnemyY-100,200,50,200,220,100);
	}
	if(count>=100&&count%2==0){
	FiraShot(angle);
	angle-=2;
	}
        count++;
        yield;
        }

        @DrawLoop {
		SetGraphicRect(288,48,336,96);
		SetTexture(imgEnemy);
		SetGraphicScale(1,1);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());
		SetGraphicAngle(0,0,-imgAngle);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }

task FiraShot(angle){
	let obj = Obj_Create(OBJ_SHOT);
	let sp = ((GetEnemyX()-Obj_GetX(obj))^2+(GetEnemyY()-Obj_GetY(obj))^2)^0.5*0.01;
	Obj_SetPosition(obj,GetX,GetY);
	Obj_SetSpeed(obj,0);
	Obj_SetAngle(obj,atan2(GetEnemyY-Obj_GetY(obj),GetEnemyX-Obj_GetX(obj))+angle);
	ObjShot_SetGraphic(obj,66);
	ObjShot_SetDelay(obj,0);
	loop(210){yield;}
		Obj_SetSpeed(obj,((GetEnemyX()-Obj_GetX(obj))^2+(GetEnemyY()-Obj_GetY(obj))^2)^0.5*0.01);
        }
}