#東方弾幕風
#Title[恐花「古代の食人花」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

let Norma=5;//撮影枚数の設定
let SpellTimer=9000;//制限時間の設定（フレーム単位）
let StepUp=[1,2,3,4];//段階移行する枚数を設定（五つまで設定可能）。StepUp1〜5（boolean）まであり、入力枚数撮るとtrueになる

#include_function ".\..\txt/data.txt"

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_yuka.png"; 

    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 112;


   @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,123,277,149);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	FinalizeDoubleSpoiler;
    }
	@BackGround
	{

	}

    // メインタスク
task TMain 
{
	yield;
	standBy;
	step;
	Shot;
}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 30);
	let wIni = 30;
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}


let AngleStart=3;
let AngleEnd=3;
let AngleRange=270;

task step
{
	while(!StepUp1){yield;}
	AngleStart=4;
	AngleEnd=5;
	while(!StepUp2){yield;}
	AngleStart=5;
	AngleEnd=6;
	AngleRange=300;
	while(!StepUp3){yield;}
	AngleStart=6;
	AngleEnd=7;
	AngleRange=330;
	while(!StepUp4){yield;}
	AngleStart=7;
	AngleEnd=8;
	AngleRange=360;
}

task Shot
{
let angle=0;
let angleplus=100;
	loop
	{
		ascent(let i in -AngleStart..AngleEnd)
		{
			BunCreateShot01(GetX, GetY,1.5,angle+GetAngleToPlayer+180+(AngleRange/(AngleStart+AngleEnd))*i,GetAngleToPlayer,15,5);
		}
			wait(10);
			angle=30*cos(angleplus);
			angleplus+=10;
	}
}

task CreateFlower(let x,let y,let angle,let angle2)
{
let speed=0.5;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
//	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 9);
	ObjShot_SetDelay(obj, 10);
	//ObjShot_SetBombResist(obj,true);

	Obj_SetAutoDelete(obj,false);
	let X=Obj_GetX(obj);//毎フレーム座標を記録するための値
	let Y=Obj_GetY(obj);//毎フレーム座標を記録するための値
	let VanishJudg=false;//画面外にいって消えたかを判定。
	let aspeed=0;
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle)+aspeed*cos(angle2), Obj_GetY(obj)+speed*sin(angle)+aspeed*sin(angle2));
		aspeed+=0.01;	

		if(Obj_GetX(obj)<GetClipMinX-64)//左端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//右端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-128)//上端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//下端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		wait(1);
	}
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=50)
		{
			RiskShot(80);
		}
		if(DistanceToBoss(X,Y)<=50)
		{
			ClearShot;
		}
		BasePoint(80);
		BulletColor("RED");
	}
}

task BunCreateShot01(let x,let y,let speed,let angle,let angle2, let graphic,let delay)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
//	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);

	Obj_SetAutoDelete(obj,false);
	let X=Obj_GetX(obj);//毎フレーム座標を記録するための値
	let Y=Obj_GetY(obj);//毎フレーム座標を記録するための値
	let VanishJudg=false;//画面外にいって消えたかを判定。
	let aspeed=0;
	let count=0;
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle)+aspeed*cos(angle2), Obj_GetY(obj)+speed*sin(angle)+aspeed*sin(angle2));
		aspeed+=0.02;	
		if(count>=90)
		{
			graphic=12;
			ObjShot_SetGraphic(obj, graphic);
		}
		if(DistanceToPlayer(X,Y)<=50 && count>=90)
		{
		let FlowerAngle=atan2(GetPlayerY-Y,GetPlayerX-X);
		loop(3)
		{
			ascent(let i in -1..2)
			{
			CreateFlower(X,Y,FlowerAngle+i*30,FlowerAngle);
			}
		wait(3);
		}
			Obj_Delete(obj);
		}
		count+=1;
		if(Obj_GetX(obj)<GetClipMinX-64)//左端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//右端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-128)//上端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//下端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		wait(1);
	}
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=50)
		{
			RiskShot(80);
		}
		if(DistanceToBoss(X,Y)<=50)
		{
			ClearShot;
		}
		BasePoint(80);
		if(graphic==15)
		{
		BulletColor("PURPLE");
		}
		if(graphic==12)
		{
		BulletColor("GREEN");
		}
	}
}

#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
