#東方弾幕風
#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/DoubleSpoilerData.txt"

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

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


   @Initialize {
	SetBulletScorePoint(12,120);
	SetShotAutoDeleteClip(8,8,8,8);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,123,277,149);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(xIni);
	SetY(yIni);
        TMain;
    }

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

let appearecount=0;
    @DrawLoop {
	SetAlpha(255/30*appearecount);
	SetColor(255/30*appearecount,255,127);
	if(appearecount<30)
	{
	appearecount+=1;
	}
	DrawBoss( imgBoss );
    }

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

	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,0,255,127);
	standBy;
	step;
	Shot;
}

sub standBy//初期位置へ
{
	SetAction(ACT_TURN,30);
	wait(30);
}


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,2.0,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.75;
	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;

	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);

	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle)+aspeed*cos(angle2), Obj_GetY(obj)+speed*sin(angle)+aspeed*sin(angle2));
		aspeed+=0.015;
		wait(1);
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
			BulletColor("RED");
				EffectSet(X,Y,"RED");
				EffectSet(X,Y,"RED");
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		EffectSet(X,Y,"RED");
		EffectSet(X,Y,"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 aspeed=0;
	let count=0;

	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);

	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(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*4/3;	
		if(count>=70)
		{
			graphic=12;
			ObjShot_SetGraphic(obj, graphic);
		}
		if(DistanceToPlayer(Obj_GetX(obj),Obj_GetY(obj))<=50 && count>=90)
		{
		let FlowerAngle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
		loop(2)
		{
			ascent(let i in -1..2)
			{
			CreateFlower(Obj_GetX(obj),Obj_GetY(obj),FlowerAngle+i*45,FlowerAngle);
			}
		wait(3);
		}
			Obj_Delete(obj);
		}
		count+=1;
		wait(1);
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		if(graphic==15)
		{
			BulletColor("PURPLE");
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
		}
		if(graphic==12)
		{
			BulletColor("GREEN");
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
		}
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		if(graphic==15)
		{
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
		}
		if(graphic==12)
		{
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
		}
	}
}

#include_function ".\..\txt/Data.txt"
#include_function ".\..\lib/lib_anime_Yuka.txt"
}
