#東方弾幕風
#Title[花砲「サンフラワースパーク-Extra」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "花砲「サンフラワースパーク-Extra」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_yuka.png"; 
    let imgFam  = csd ~ "..\img\FlowerShot.png";
    let imgBG  = csd ~ "..\img\st4bg1.png";
    let imgBG2  = csd ~ "..\img\st4bg2.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;

let MSPON=false;
let MarisaWin=false;
let MarisaLose=false;
let YukaWin=false;
let MSPEnd=false;
let MSPLength=0;
let WinnerJudg="NONE";
	let wIni=60;
	let DrawY=330;
	let count=-wIni;

	#include_function ".\..\txt\SpellCardBonusDefine.txt"
	let SpellTimer=50;

	let bgy=0;
	let BGangle=0;
    @Initialize {

       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\ShotData.txt");
	StartSpellHistory(119);

        SetLife(900);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        LoadGraphic(imgBG);
        LoadGraphic(imgBG2);
	InitializeAction();
        TMain;
    }

    @MainLoop {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 64);
        SetCollisionB(GetX, GetY, 16);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;

    }

    @DrawLoop {
	DrawBossShadow( imgBoss,150,0,255,255);
	SetGraphicAngle(0,0,0);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
        DeleteGraphic(imgBoss);
        DeleteGraphic(imgFam);
        DeleteGraphic(imgBG);
        DeleteGraphic(imgBG2);
		EndSpellHistory(119);
	loop(10)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
	SetCommonData("FLOWERSPARK",false);
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,0,1280,1920+bgy);
		SetGraphicAngle(0,0,0);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
		SetTexture(imgBG2);
		SetGraphicRect(0,0,640,640);
		SetGraphicAngle(0,0,BGangle);
		SetColor(150,150,150);
		SetAlpha(50);
		DrawGraphic(224, 240);	
		bgy+=2;
		BGangle+=0.2;
	}
    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	summon;
	Shot1;
	Shot2;
	LaserShot;
	MSPJUDG;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
	loop
	{
		if(!OnBomb)
		{
			SetDamageRate(25, 25);
		}
		else
		{
	//		SetDamageRate(10, 10);
		}
		yield;
	}
}

task summon
{
wait(30);
loop
{
	loop(7)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,2,0, 1);
		wait(90);
	}
	wait(540);
	while(MSPON==true){yield;}
}
}


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

sub spell//発動モーション
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(SpellTimer);
        SetScore(SpellBonus);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task MSPJUDG
{
loop
{
loop
{
		if(MSPON==true)
		{
			MasterSpark;
			break;
		}
yield;
}
MoveStop;
loop
{
		if(MarisaWin==true)
		{
			loop(60)
			{
				MSPLength+=2;
				yield;
			}
			loop(30)
			{
				MSPLength+=20;
				yield;
			}
			loop
			{
				wait(80);
				AddLife(-1000);
				yield;
			}
		}

		if(YukaWin==true)
		{
			loop(120)
			{
				MSPLength+=2;
				yield;
			}
			loop(30)
			{
				MSPLength+=20;
				yield;
			}
			wait(30);
			MSPEnd=true;
			SetCommonData("FLOWERSPARK",false);
			break;
		}
yield;
}
MSPON=false;
MarisaWin=false;
MarisaLose=false;
YukaWin=false;
MSPEnd=false;
MSPLength=0;
WinnerJudg="NONE";
yield;
}
}

task MoveStop
{
let DefaultX=GetPlayerX;
let DefaultY=GetPlayerY;
loop(450)
{
	SetPlayerX(DefaultX);
	SetPlayerY(DefaultY);
	yield;
}
}

task Shot1
{
let way=20;
let angle=0;
	loop
	{
		ascent(let i in 0..way)
		{
		//	CreateShot01(GetX,GetY,3.0,angle+i*360/way,10,10);
		//	CreateShotFromScript( "shot1",GetX, GetY, 3.0,angle+i*360/way, 10, 10);
			CreateShot01ToItem(GetX,GetY,3.0,angle+i*360/way,10,10);
		}
		angle+=5;
		wait(15);
		while(MSPON==true){yield;}
	}
}

task Shot2
{
let way=20;
let angle=0;
	loop
	{
		ascent(let i in 0..way)
		{
		//	CreateShot01(GetX,GetY,3.0,angle+i*360/way,11,10);
			CreateShotFromScript( "shot1",GetX, GetY, 3.0,angle+i*360/way, 10, 11);
		}
		angle-=5;
		wait(15);
		while(MSPON==true){yield;}
	}
}

task LaserShot
{
wait(840);

loop
{
	SPARK;
	wait(330);
	while(MSPON==true){yield;}
	wait(840);
}
}

task SPARK
{
let x=GetX;
let y=GetY;
let angle=GetAngleToPlayer;
if(GetCommonDataDefault("MASTERSPARK",false)==true)
{
	WinnerJudg="Yuka";
	Interference2;
}
if(WinnerJudg!="Yuka")
{
	Interference(angle);
}

loop(3)
{	
	PriSpark(angle,15);
	wait(5);
	PriSpark(angle,14);
	wait(5);
	PriSpark(angle,12);
	wait(5);
	PriSpark(angle,11);
	wait(5);
	PriSpark(angle,10);
	wait(5);
	PriSpark(angle,9);
	wait(5);
}
	loop(6)
	{
	StartSpark(angle,15);
	wait(5);
	StartSpark(angle,14);
	wait(5);
	StartSpark(angle,12);
	wait(5);
	StartSpark(angle,11);
	wait(5);
	StartSpark(angle,10);
	wait(5);
	StartSpark(angle,9);
	wait(5);
	}
if(WinnerJudg=="Marisa")
{
	MarisaWin=true;
}
if(WinnerJudg=="Yuka")
{
	YukaWin=true;
	loop(8)
	{
	StartSpark(angle,15);
	wait(5);
	StartSpark(angle,14);
	wait(5);
	StartSpark(angle,12);
	wait(5);
	StartSpark(angle,11);
	wait(5);
	StartSpark(angle,10);
	wait(5);
	StartSpark(angle,9);
	wait(5);
	}
}
if(WinnerJudg=="NONE")
{
	loop(2)
	{
	StartSpark(angle,15);
	wait(5);
	StartSpark(angle,14);
	wait(5);
	StartSpark(angle,12);
	wait(5);
	StartSpark(angle,11);
	wait(5);
	StartSpark(angle,10);
	wait(5);
	StartSpark(angle,9);
	wait(5);
	}
}
wait(600);
WinnerJudg="NONE";
}

task PriSpark(angle,color)
{
	LASER(angle,3,color,0);
	LASER(angle,3,color,8);
	LASER(angle,3,color,-8);
	LASER(angle,3,color,16);
	LASER(angle,3,color,-16);
	LASER(angle,3,color,24);
	LASER(angle,3,color,-24);
	LASER(angle,3,color,32);
	LASER(angle,3,color,-32);
}


task StartSpark(angle,color)
{
	LASER(angle,120,color,0);
	LASER(angle,110,color,8);
	LASER(angle,110,color,-8);
	LASER(angle,110,color,16);
	LASER(angle,110,color,-16);
	LASER(angle,110,color,24);
	LASER(angle,110,color,-24);
	LASER(angle,110,color,32);
	LASER(angle,110,color,-32);
}

task LASER(let angle,let wid,let color,let exangle){
		let length=800;
		let obj= Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,GetX-50*cos(angle),GetY-50*sin(angle));
		ObjLaser_SetWidth(obj,wid);
		ObjLaser_SetLength(obj,length);
		ObjLaser_SetSource(obj,false);
        	ObjShot_SetGraphic(obj,color);   
		Obj_SetAngle(obj, angle+exangle);
		ObjShot_SetDelay(obj,0);
		Obj_SetAlpha(obj,255);
			if(YukaWin==true)
			{
				length+=MSPLength;
			}
		if(MSPON==true)
		{
			Obj_SetCollisionToPlayer(obj,false);
		}
		if(wid<10)
		{
			Obj_SetCollisionToPlayer(obj,false);
		}

		if(exangle==0)
		{
				loop(15)
				{
					if(MSPON==true)
					{
						break;
					}
					yield;
				}
		}
		else
		{
				loop(5)
				{
					Obj_SetAlpha(obj,0);
					if(MSPON==true)
					{
						break;
					}
					yield;
				}
			
				loop(10)
				{
					Obj_SetAlpha(obj,255);
					if(MSPON==true)
					{
						break;
					}
					yield;
				}
		}
		if(MSPON==false)
		{
			Obj_Delete(obj);
		}
		Obj_SetAngle(obj, GetAngleToPlayer+exangle);
		Obj_SetPosition(obj,GetX-50*cos(GetAngleToPlayer),GetY-50*sin(GetAngleToPlayer));
		ObjLaser_SetWidth(obj,110);
		Obj_SetAlpha(obj,255);
		let distance=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
		length=distance+MSPLength;
		let r=distance/5-20;
		if(YukaWin==true)
		{
			Obj_SetCollisionToPlayer(obj,true);
		}
			if(MSPEnd==true)
			{
				Obj_SetAlpha(obj,0);
				Obj_SetCollisionToPlayer(obj,false);
			}
		loop(100)
		{
			length-=distance/100;
			
			ObjLaser_SetLength(obj,length);
			Obj_SetPosition(obj,GetX-r*cos(GetAngleToPlayer),GetY-r*sin(GetAngleToPlayer));
			r-=0.6;
			yield;
		}
		Obj_Delete(obj);
}

task Interference(angle)
{
SetCommonData("FLOWERSPARK",true);
loop(90)
{
	if(GetCommonDataDefault("MASTERSPARK",false)==true && angle+30>GetAngleToPlayer && angle-30<GetAngleToPlayer)
	{
		MSPON=true;
		WinnerJudg="Marisa";
		break;
	}
	yield;
}
wait(450);
SetCommonData("FLOWERSPARK",false);
}

task Interference2
{
SetCommonData("FLOWERSPARK",true);
loop(90)
{
	if(GetCommonDataDefault("MASTERSPARK",false)==true)
	{
		MSPON=true;
		WinnerJudg="Yuka";
		break;
	}
	yield;
}
wait(450);
SetCommonData("FLOWERSPARK",false);
}

task MasterSpark
{
let angle=GetAngleToPlayer+180;
	loop(8)
	{
	StartMasterSpark(angle,15);
	wait(5);
	StartMasterSpark(angle,14);
	wait(5);
	StartMasterSpark(angle,12);
	wait(5);
	StartMasterSpark(angle,11);
	wait(5);
	StartMasterSpark(angle,10);
	wait(5);
	StartMasterSpark(angle,9);
	wait(5);
	}
if(WinnerJudg=="Marisa")
{
	loop(8)
	{
	StartMasterSpark(angle,15);
	wait(5);
	StartMasterSpark(angle,14);
	wait(5);
	StartMasterSpark(angle,12);
	wait(5);
	StartMasterSpark(angle,11);
	wait(5);
	StartMasterSpark(angle,10);
	wait(5);
	StartMasterSpark(angle,9);
	wait(5);
	}
}
MarisaLose=true;
}

task StartMasterSpark(angle,color)
{
	MasterLASER(angle,120,color,0);
	MasterLASER(angle,110,color,8);
	MasterLASER(angle,110,color,-8);
	MasterLASER(angle,110,color,16);
	MasterLASER(angle,110,color,-16);
	MasterLASER(angle,110,color,24);
	MasterLASER(angle,110,color,-24);
}

task MasterLASER(let angle,let wid,let color,let exangle){
		let distance=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
		let r=distance/5-20;
		let length=distance;
			if(MarisaWin==true)
			{
				length+=MSPLength;
			}
		let obj= Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,GetPlayerX-r*cos(angle),GetPlayerY-r*sin(angle));
		ObjLaser_SetWidth(obj,wid);
		ObjLaser_SetLength(obj,length);
		ObjLaser_SetSource(obj,false);
        	ObjShot_SetGraphic(obj,color);   
		Obj_SetAngle(obj, angle+exangle);
		ObjShot_SetDelay(obj,0);
		Obj_SetAutoDelete(obj,false);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_ToItem(obj,false);
		Obj_SetAlpha(obj,255);
		if(wid<10)
		{
			Obj_SetCollisionToPlayer(obj,false);
		}

		if(exangle==0)
		{
				loop(15)
				{
					if(MSPON==true)
					{
						break;
					}
					yield;
				}
		}
		else
		{
				loop(5)
				{
					Obj_SetAlpha(obj,0);
					if(MSPON==true)
					{
						break;
					}
					yield;
				}
			
				loop(10)
				{
					Obj_SetAlpha(obj,255);
					if(MSPON==true)
					{
						break;
					}
					yield;
				}
		}
		loop(100)
		{
			length-=distance/100;
			ObjLaser_SetLength(obj,length);
			Obj_SetPosition(obj,GetPlayerX-r*cos(angle),GetPlayerY-r*sin(angle));
			r-=0.6;
			yield;
		}
		Obj_Delete(obj);
}

#include_function ".\..\txt\data.txt"
#include_function ".\..\txt\Spelldata.txt"
#include_function ".\..\lib/lib_anime_Yuka.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\FlowerShot.png";
	let num = GetArgument;
	let angle=GetAngle;
	let dir=rand_int(0,1)*2-1;

    @Initialize {
        SetLife(2000);
	SetDamageRateEx(100,100,100,1);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
	SetCollisionA(GetX(),GetY(),32);
	angle+=6*dir;
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	SetGraphicAngle(0,0,angle);
	SetGraphicScale(0.8,0.8)
    }

    task TMain {
        yield;
	shot;
	move;
    }

task move
{
SetMovePosition02(rand(GetClipMinX+32,GetClipMaxX-32), rand(GetClipMinY+32,GetCenterY-64), 60);
wait(360);
VanishEnemy;
}

let CB;
task shot
{
	wait(60);
	SPARK;
let rangle=rand(0,360);
ascent(let j in 0..36)
{
CB=150;
	ascent(let i in -1..5)
	{
	SetShotColor(255,255,CB);
/*	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,1.5+i,angle+j*15+rangle,0,0,0,33);
	SetShotDataA(0,20,0,angle+j*15+rangle,0,0,0,33);
	SetShotDataA(0,60,2,angle+j*15+rangle,0,0.02,8,33);
	FireShot(0);
*/	ShotGen(GetX,GetY,1.5+i,1.5,0.03,angle+j*10+rangle,5,ORANGE12);
	CB+=20;
	}
}
}

task SPARK
{
let x=GetX;
let y=GetY;
let angle=GetAngleToPlayer;
loop(3)
{
	LASER(angle,3,15,0);
	wait(5);
	LASER(angle,3,14,0);
	wait(5);
	LASER(angle,3,12,0);
	wait(5);
	LASER(angle,3,11,0);
	wait(5);
	LASER(angle,3,10,0);
	wait(5);
	LASER(angle,3,9,0);
	wait(5);
}
	loop(5)
	{
	StartSpark(angle,15);
	wait(5);
	StartSpark(angle,14);
	wait(5);
	StartSpark(angle,12);
	wait(5);
	StartSpark(angle,11);
	wait(5);
	StartSpark(angle,10);
	wait(5);
	StartSpark(angle,9);
	wait(5);
	}
}

task StartSpark(angle,color)
{
	LASER(angle,60,color,0);
	LASER(angle,50,color,1);
	LASER(angle,50,color,-1);
}

task LASER(let angle,let wid,let color,let exangle){

		let obj= Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,GetX-50*cos(angle),GetY-50*sin(angle));
		ObjLaser_SetWidth(obj,wid);
		ObjLaser_SetLength(obj,800);
		ObjLaser_SetSource(obj,false);
        	ObjShot_SetGraphic(obj,color);   
		Obj_SetAngle(obj, angle+exangle);
		ObjShot_SetDelay(obj,0);
		Obj_SetAlpha(obj,255);
		if(wid<10)
		{
			Obj_SetCollisionToPlayer(obj,false);
		}

		if(exangle==0)
		{
				loop(15)
				{
					yield;
				}
		}
		else
		{
				loop(5)
				{
					Obj_SetAlpha(obj,0);
					yield;
				}
			
				loop(10)
				{
					Obj_SetAlpha(obj,255);
					yield;
				}
		}

		Obj_Delete(obj);
}

task ShotGen(let x,let y,let Pspeed,let speed,let aspeed,let angle,let delay,let graphic)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, Pspeed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);

	loop(delay)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	loop(20)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, 0);
	loop(40)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, speed);
	while(!Obj_BeDeleted(obj))
	{
		speed+=aspeed;
		Obj_SetSpeed(obj, speed);
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}
    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 0, 64, 64); }

#include_function ".\..\txt/StageEnemydata.txt"
}

#include_script ".\..\txt/EnemyShotData.txt"