#東方弾幕風
#Title[No.144 「レイフォール・ファンタジア　-Hard-」]
#Text[]
#Image[]
#BackGround[]
#PlayLevel[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\弾幕集.txt"

	let name    = "「レイフォール・ファンタジア　-Hard-」";
	let count   = 0;

	//初期位置
	let xini    =GetCenterX;
	let yini    =GetCenterY + 160;

	@Initialize{
	CutIn(YOUMU,name,"",0,0,0,0);
	SetX(GetCenterX);
	SetY(GetClipMinY + 120);
	SetLife(20000);
	SetTimer(200);
	SetScore(24000000 + spellbonus * 2);
	SetDamageRate(100,0);

	LoadGraphic(imgboss73);
	SetTexture(imgboss73);
	SetGraphicRect(0,0,127,127);
	SetInvincibility(310);
	Shot(2);
	Move();
	LoadUserShotData(GetCurrentScriptDirectory~"11-221Shot_データ.txt");
	}

	@MainLoop{
	ChackBonus;
	SetCollisionA(GetX,GetY,48);
	SetCollisionB(GetX,GetY,24);

	//EX風ボムバリア
	if(OnBomb() == true){SetInvincibility(2);}
	yield;
	}

	@DrawLoop{
	DrawGraphic(GetX,GetY);
	}


	@Finalize{
	DeleteGraphic(imgboss73);
	MasicPointAddSpellCard;
	SetCommonData("ON_SPELL",0);
	}
	task Move(){
	loop{
	loop(300){yield;}
	if(GetX >= GetPlayerX){
	SetMovePositionRandom01(rand_int(-8,0)*8,rand(-16,16),1,GetClipMinX + 128,GetCenterY-40,GetClipMaxX - 128,GetCenterY);
	}
	if(GetX < GetPlayerX){
	SetMovePositionRandom01(rand_int(0,8)*8,rand(-16,16),1,GetClipMinX + 128,GetCenterY-40,GetClipMaxX - 128,GetCenterY);
	}
	}
	}

	task Shot(level){
	task LayFallShot(speed,angle,wait,rank,level){
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetX(obj, GetX);
	Obj_SetY(obj, GetY);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);	
	ObjShot_SetGraphic(obj, BLUE12);
	ObjShot_SetDelay(obj, 30);
	ObjShot_SetBombResist(obj,true);

	loop(90){yield;}
	Obj_SetSpeed(obj , 0);
	loop(wait){yield;}
	let x = Obj_GetX(obj);
	let y = Obj_GetY(obj);
	let speedA = 1.5 + level / 6;
	let angleA = angle + 90;
	let angleB = angle - 90;
	while(speedA > 1){
	CreateShot01(x,y,speedA,angleA,BLUE32,20);
	CreateShot01(x,y,speedA,angleB,AQUA32,20);
	CreateShot01(x,y,speedA / 2,angleA,26,20);
	CreateShot01(x,y,speedA / 2,angleB,25,20);
	speedA -= 0.08 - level * 0.01;
	angleA -= 4.763 * (7 - level * 2);
	angleB += 4.763 * (7 - level * 2);
	loop(3){yield;}
	}

	Obj_Delete(obj);
	}

	task LayFallShotCommand(level){
	let rate = [7,26,192,63,169,51,103,134,13,38,116,147,10,44,184,162,100,72,155,85,141,89,15,129,57,121,118,160,0,32,77,187,128,91,30,96,69,53,176,94,125,49,172,173,197,153,23,41,8,94,114,97,191,105,91,110,80,140,112,73,189,144,64,67,36,165,137,142,163,87,19,193,106,47,21,66,151,180,2,198,132,108,88,136,29,43,55,54,82,93,123,140,39,18,76,131,126,43,92,145,62,1,27,115,153,181,24,74,101,31,195,167,117,5,157,177,48,178,17,133,186,135,45,99,111,199,9,59,71,156,120,20,42,166,65,56,182,138,159,61,178,174,22,68,104,148,130,60,175,4,11,171,81,161,28,83,143,168,37,58,170,152,124,75,14,194,132,139,90,46,164,109,84,6,79,200,158,78,12,146,86,33,102,198,149,185,52,183,127,95,196,70,3,113,122,35,117,190,98,16,188,30,107,154,179,25,188,50,119];
	let a = 40;
	let b = 120;
	loop{

	loop(rank + level + 3){
	let angle = 140 + 1.35 * rate[a];
	let speed = 1 + 0.01 * rate[b];
	let wait = GetTimer;
	let rank = GetCommonDataDefault("RANK",1);
	LayFallShot(speed,angle,wait,rank,level);
	a++;if(a >= length(rate)){a = 0;}
	b++;if(b >= length(rate)){b = 0;}
	}
	loop(320 - rank * 20){yield;}
	}
	}

	task HeartShotA(level){
	let mx = GetClipMinX;
	let xadd = (GetClipMaxX - GetClipMinX) / (4 + level * 3);
	let my = GetClipMinY;
	let a = 0;
	let bulletA = 1;
	let bulletB = 11;
	let rank = GetCommonDataDefault("RANK",1);
	loop{
	CreateShot01(mx + a * xadd,my,1 + level * 0.5,90,bulletA,20);
	loop(9 - level - rank){rank = GetCommonDataDefault("RANK",1);yield;}
	a++;
	CreateShot01(mx + a * xadd,my,1 + level * 0.5,90,bulletB,20);
	loop(9 - level - rank){rank = GetCommonDataDefault("RANK",1);yield;}
	a++;
	bulletA++;
	bulletB++;
	if(a > 14 + level * 12){a = 0;}
	if(bulletA > 8){bulletA = 1;}
	if(bulletB > 18){bulletB = 11;}
	}
	}

	task HeartShotB(level){
	let mx = GetClipMinX;
	let xadd = (GetClipMaxX - GetClipMinX) / (4 + level * 3);
	let my = GetClipMinY;
	let a = 14 + level * 12;
	let bulletA = 8;
	let bulletB = 18;
	let rank = GetCommonDataDefault("RANK",1);
	loop{
	CreateShot01(mx + a * xadd,my,1.5 + level * 0.5,90,bulletA,20);
	loop(12 - level * 2 - rank){rank = GetCommonDataDefault("RANK",1);yield;}
	a--;
	CreateShot01(mx + a * xadd,my,1.5 + level * 0.5,90,bulletB,20);
	loop(12 - level * 2 - rank){rank = GetCommonDataDefault("RANK",1);yield;}
	a--;
	bulletA--;
	bulletB--;
	if(a < 0){a = 14 + level * 12;}
	if(bulletA < 1){bulletA = 8;}
	if(bulletB < 11){bulletB = 18;}
	}
	}

	task YouShotA(x,y,bullet,level){
	let angle = 0;
	let speed = 0.5 + 0.1 * level;
	loop{
	let rank = GetCommonDataDefault("RANK",1);
	CreateShotA(1,x,y,30);
	SetShotDataA(1,0,speed,angle,-0.25,0.01,1.25 + level / 4,bullet);
	FireShot(1);
	loop(10 - level){yield;}
	angle += 23.7 - level * 2 - rank;
	}
	}

	task YouShotB(x,y,bullet,level){
	let angle = 180;
	let speed = 1 + 0.1 * level;
	loop{
	let rank = GetCommonDataDefault("RANK",1);
	CreateShotA(1,x,y,30);
	SetShotDataA(1,0,speed,angle,-0.35,0.05,1.25 + level / 4,bullet);
	FireShot(1);
	loop(10 - level){yield;}
	angle += 23.7 - level * 2 - rank;
	}
	}

	let rank = 1;
	let angle;
	let mx = GetClipMinX;
	let Mx = GetClipMaxX;
	let my = GetClipMinY;
	let cx = GetCenterX;
	let cy = GetCenterY;
	let angleA = 0;
	let angleB = 0;
	loop(300){yield;}
	LayFallShotCommand(level);
	rank = trunc(5 - GetLife / 4000)+1;
	SetCommonData("RANK",rank);
	while(rank == 1){yield;
	rank = trunc(5 - GetLife / 4000)+1;
	SetCommonData("RANK",rank);}
	if(level == 3){
	YouShotA(cx - 200,cy,PURPLE22,level);
	YouShotB(cx + 200,cy,GREEN22,level);
	YouShotA(cx - 100,cy + 120,PURPLE22,level);
	YouShotB(cx + 100,cy + 120,GREEN22,level);
	YouShotA(cx - 100,cy - 120,PURPLE22,level);
	YouShotB(cx + 100,cy - 120,GREEN22,level);
	}
	while(rank <= 2){yield;
	rank = trunc(5 - GetLife / 4000)+1;
	SetCommonData("RANK",rank);}
	HeartShotA(level);
	while(rank <= 3){yield;
	rank = trunc(5 - GetLife / 4000)+1;
	SetCommonData("RANK",rank);}
	if(level >= 2){
	HeartShotB(level);
	}
	while(rank <= 4){yield;
	rank = trunc(5 - GetLife / 4000)+1;
	SetCommonData("RANK",rank);}
	YouShotA(cx,cy,RED22,level);
	YouShotB(cx,cy,BLUE22,level);
	YouShotA(mx + 60,my,RED22,level);
	YouShotB(mx + 60,my,BLUE22,level);
	YouShotA(Mx - 60,my,RED22,level);
	YouShotB(Mx - 60,my,BLUE22,level);
	loop{yield;
	rank = trunc(5 - GetLife / 4000)+1;
	SetCommonData("RANK",rank);}
	}
}