#東方弾幕風
#Title[No.063　魅了・幽剣「ホールド・チャーム -妖夢-　-Hard-」]
#Text[]
#Image[]
#BackGround[]
#PlayLevel[]
#Player[FREE]
#ScriptVersion[2]

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

	let name    = "魅了・幽剣「ホールド・チャーム -妖夢-　-Hard-」";

	//初期位置
	let xini    =GetCenterX;
	let yini    =GetCenterY;
	let arrayLaser = [];

	@Initialize{
	SetCommonData("ON_SPELL",1);
	CutIn(YOUMU,name,"",0,0,0,0);
	SetX(GetClipMinX);
	SetY(GetCenterY);
	SetLife(2000);
	SetTimer(59);
	SetScore(5000000 + spellbonus * 2);
	SetDamageRate(50,10);
	SetInvincibility(120);

	LoadGraphic(imgboss52);
	SetTexture(imgboss52);
	SetGraphicRect(0,0,127,127);
	Shot(0);
	DeleteEnemyShotToItem(ALL);
	}

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

	yield;
	}

	@DrawLoop{
	DrawGraphic(GetX,GetY);
	}

	@Finalize{
	DeleteGraphic(imgboss52);
	MasicPointAddSpellCard;
	CreateItem(ITEM_1UP,GetX,GetY);
	SetCommonData("ON_SPELL",0);
	}

	task CreateLaserP(let num){//弾の軌道を変えるレーザー
	//レーザータスク初期化
	let angle=180*num;
	let mx =GetClipMinX();
	let Mx =GetClipMaxX();
	let obj = Obj_Create(OBJ_LASER);
	arrayLaser = arrayLaser~[obj];//オブジェクトをarrayLaserに登録
	Obj_SetX(obj, GetX);
	Obj_SetY(obj, GetY);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, WHITE12);
	ObjShot_SetDelay(obj, 10);//遅延時間：60フレーム
	ObjLaser_SetLength(obj,Mx - mx);
	ObjLaser_SetWidth(obj, 18);//レーザーの幅：18
	loop(240){yield;}
	let i=0;
	loop(length(arrayLaser))
	{//オブジェクトを削除
	if(arrayLaser[i] == obj){arrayLaser = erase(arrayLaser, i);break;}
	i++;}
	Obj_Delete(obj);
	}

	task CreateShotLP(y,speed,angle,bullet,delay,level){
	let mx =GetClipMinX();
	let Mx =GetClipMaxX();

	task ShotObject(x,y,speed,angle,bullet,delay){//レーザーに当たったら軌道を変える弾
	//弾タスク初期化
	function GetGapAngle(xA,yA,xB,yB)
	{return atan2( yB - yA, xB - xA );}

	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetX(obj, x);
	Obj_SetY(obj, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, bullet);
	ObjShot_SetDelay(obj, delay);
			
	while( !Obj_BeDeleted(obj) ){//削除されるまでループを実行	
	let i=0;
	loop(length(arrayLaser)){//レーザーとの当り判定を調査
	if(Collision_Obj_Obj(arrayLaser[i], obj)){//Laserと接触したら
	//連続で判定されないよう普通の弾と入れ替える
	x = Obj_GetX(obj);
	y = Obj_GetY(obj);
	CreateShot02(x, y, 0, GetGapAngle(x,y,GetPlayerX,GetPlayerY), 0.04, 2.3 ,bullet, 0);
	Obj_Delete(obj);break;}
	i++;}		
	yield;}
	}


	loop{
	loop(level + 1){
	let x = rand(mx,Mx);
	ShotObject(x,y,speed,angle,bullet,delay);}
	loop(7){yield;}
	}
	}



	task Shot(level){
	function Wait(time){loop(time){yield;}}
	let angle = 0;
	let mx =GetClipMinX();
	let Mx =GetClipMaxX();
	let y = GetY;
	CreateShotLP(GetClipMaxY+16,1,-90,RED04,20,level);
	CreateShotLP(GetClipMinY-16,1,90,BLUE04,20,level);
	loop{
	SetMovePosition02(mx+32,y,6);
	if(level >= 2){Allshot(3,90,20,RED21,20);}
	Wait(30);
	CreateLaserP(0);
	Wait(300);
	Concentration01(60);
	Slow(1);
	Wait(60);
	Slow(0);
	SetMovePosition02(Mx-32,y,6);
	if(level >= 2){Allshot(3,90,20,RED21,20);}
	Wait(30);
	CreateLaserP(1);
	Wait(300);
	Concentration01(60);
	Slow(1);
	Wait(60);
	Slow(0);
	}
	}
}