#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 ranX=0;
        let ranY=0;
        let ranA=0;
	let angle=0;
	let Animation=0;
	let Motion=0;
	let shotseA=csd~"se\ShotSE02.wav";

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

        SetLife(700);
        SetTimer(60);
        SetScore(2000000);
        SetDamageRate(20,20);

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

        @MainLoop
        {
	if(count==150){
		Concentration01(60);
		}
	if(count>=200&&count<=245&&count%5==0){
		PlaySE(shotseA);
		FiraShotA(-45+angle);
		FiraShotA(-225+angle);
		angle+=30;
		}
	if(count==250){
		SetMovePositionRandom01(rand(20,40),rand(20,40),3,GetClipMinX()+150,100,GetClipMaxX()-150,175);
        	SetShotDirectionType(PLAYER);
        	CreateShotA(1,GetX,GetY,0);
        	SetShotDataA(1,0,2,0,0,0,2,37);
        	FireShot(1);
		}
	if(count>=300&&count<=345&&count%5==0){
		PlaySE(shotseA);
		FiraShotB(-45-angle);
		FiraShotB(-225-angle);
		angle-=30;
		}
	if(count==350){
		SetMovePositionRandom01(rand(20,40),rand(20,40),3,GetClipMinX()+150,100,GetClipMaxX()-150,175);
        	SetShotDirectionType(PLAYER);
        	CreateShotA(1,GetX,GetY,0);
        	SetShotDataA(1,0,2,0,0,0,2,37);
        	FireShot(1);
		}
	if(count>=400&&count<=445&&count%5==0){
		PlaySE(shotseA);
		FiraShotA(-45+angle);
		FiraShotB(-225+angle);
		angle+=30;
		}
	if(count>=450&&count<=495&&count%5==0){
		PlaySE(shotseA);
		FiraShotA(-45-angle);
		FiraShotB(-225-angle);
		angle-=30;
		}
	if(count==500){
		SetMovePositionRandom01(rand(20,40),rand(20,40),3,GetClipMinX()+150,100,GetClipMaxX()-150,175);
        	SetShotDirectionType(PLAYER);
        	CreateShotA(1,GetX,GetY,0);
        	SetShotDataA(1,0,3,0,0,0,3,37);
        	FireShot(1);
		}
	if(count==525){
        	SetShotDirectionType(PLAYER);
        	CreateShotA(1,GetX,GetY,0);
        	SetShotDataA(1,0,4,0,0,0,4,37);
        	FireShot(1);
		}
	if(count==550){
		Motion=1;
		Concentration01(60);
		}
	if(count>=600&&count<=650&&count%5==0){
		PlaySE(shotseA);
        	SetShotDirectionType(PLAYER);
		let i=0;
		while(i<5)
		{
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,1.5,i*20-40,0,0,1.5,67);
			FireShot(shotA);
			i++;
			}
		FiraShotA(rand(0,360));
		FiraShotB(rand(0,360));
		}
	if(count==650){
		Motion=0;
		SetMovePositionRandom01(rand(20,40),rand(20,40),3,GetClipMinX()+150,100,GetClipMaxX()-150,175);
		count=100;
		}
        SetCollisionB(GetX(),GetY(),18);
	SetCollisionA(GetX(),GetY(),18);
        count++;
	yield;
        }

	@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);
	}

        @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());
	}

task FiraShotA(Angle){
	let obj = Obj_Create(OBJ_SHOT);
	let shotseC = csd~"se\ShotSE01.wav";
	Obj_SetPosition(obj,GetX,GetY);
	Obj_SetSpeed(obj,4);
	Obj_SetAngle(obj,Angle);
	ObjShot_SetGraphic(obj,141);
	ObjShot_SetDelay(obj,5);
    
	while(!Obj_BeDeleted(obj)) {
		if(Obj_GetX(obj)<GetClipMinX){
			PlaySE(shotseC);
			FiraShotC(0,Obj_GetX(obj),Obj_GetY(obj));
			break;
			}
		if(Obj_GetX(obj)>GetClipMaxX){
			PlaySE(shotseC);
			FiraShotC(180,Obj_GetX(obj),Obj_GetY(obj));
			break;
			}
			let id=0;
			CreateShotA(id,Obj_GetX(obj)+rand(-20,20),Obj_GetY(obj)+rand(-20,20),0);
			SetShotDataA(id,0,0,0,0,0,0,61);
				let j=49;
				while(j<50){
				let id2=1;
				CreateShotA(id2,0,0,20);
				SetShotDataA(id2,0,0,0,0,0,0,61);
				SetShotKillTime(id2,0);
				AddShot(j,id,id2,20);
				j++;
			}
		SetShotKillTime(id,50);
		FireShot(id);
		yield;
		}
	}

task FiraShotB(Angle){
	let obj = Obj_Create(OBJ_SHOT);
	let shotseC = csd~"se\ShotSE01.wav";
	Obj_SetPosition(obj,GetX,GetY);
	Obj_SetSpeed(obj,4);
	Obj_SetAngle(obj,Angle);
	ObjShot_SetGraphic(obj,143);
	ObjShot_SetDelay(obj,5);
    
	while(!Obj_BeDeleted(obj)) {
		if(Obj_GetY(obj)<GetClipMinY){
			PlaySE(shotseC);
			FiraShotD(90,Obj_GetX(obj),Obj_GetY(obj));
			break;
			}
		if(Obj_GetY(obj)>GetClipMaxY){
			PlaySE(shotseC);
			FiraShotD(270,Obj_GetX(obj),Obj_GetY(obj));
			break;
			}
			let id=0;
			CreateShotA(id,Obj_GetX(obj)+rand(-15,15),Obj_GetY(obj)+rand(-15,15),0);
			SetShotDataA(id,0,0,0,0,0,0,66);
				let j=49;
				while(j<50){
				let id2=1;
				CreateShotA(id2,0,0,20);
				SetShotDataA(id2,0,0,0,0,0,0,66);
				SetShotKillTime(id2,0);
				AddShot(j,id,id2,20);
				j++;
			}
		SetShotKillTime(id,50);
		FireShot(id);
		yield;
		}
	}

task FiraShotC(Angle,X,Y){
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj,X,Y);
	Obj_SetSpeed(obj,4);
	Obj_SetAngle(obj,Angle);
	ObjShot_SetGraphic(obj,141);
	ObjShot_SetDelay(obj,5);
    
	while(!Obj_BeDeleted(obj)) {
		let id=0;
		CreateShotA(id,Obj_GetX(obj)+rand(-20,20),Obj_GetY(obj)+rand(-20,20),0);
		SetShotDataA(id,0,0,0,0,0,0,61);
			let j=49;
			while(j<50){
			let id2=1;
			CreateShotA(id2,0,0,20);
			SetShotDataA(id2,0,0,0,0,0,0,61);
			SetShotKillTime(id2,0);
			AddShot(j,id,id2,20);
			j++;
			}
		SetShotKillTime(id,50);
		FireShot(id);
		yield;
		}
	}

task FiraShotD(Angle,X,Y){
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj,X,Y);
	Obj_SetSpeed(obj,4);
	Obj_SetAngle(obj,Angle);
	ObjShot_SetGraphic(obj,143);
	ObjShot_SetDelay(obj,5);
    
	while(!Obj_BeDeleted(obj)) {
		let id=0;
		CreateShotA(id,Obj_GetX(obj)+rand(-20,20),Obj_GetY(obj)+rand(-20,20),0);
		SetShotDataA(id,0,0,0,0,0,0,66);
			let j=49;
			while(j<50){
			let id2=1;
			CreateShotA(id2,0,0,20);
			SetShotDataA(id2,0,0,0,0,0,0,66);
			SetShotKillTime(id2,0);
			AddShot(j,id,id2,20);
			j++;
			}
		SetShotKillTime(id,50);
		FireShot(id);
		yield;
		}
	}
}