#東方弾幕風
#Title[花砲「サンフラワースパーク」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "花砲「サンフラワースパーク」";
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(56);

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

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        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(56);
	loop(10)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@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(60);
loop
{
	loop(5)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,2,0, 1);
		wait(120);
	}
	wait(570);
	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;
			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=10;
let angle=0;
	loop
	{
		ascent(let i in 0..way)
		{
			CreateShot01(GetX,GetY,2.0,angle+i*360/way,10,10);
		}
		angle+=5;
		wait(15);
		while(MSPON==true){yield;}
	}
}

task Shot2
{
let way=10;
let angle=0;
	loop
	{
		ascent(let i in 0..way)
		{
			CreateShot01(GetX,GetY,2.0,angle+i*360/way,11,10);
		}
		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);
}


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);
}

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);
			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);
		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);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
	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;
}

task shot
{
	wait(60);
	SPARK;
}

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,3);
	LASER(angle,50,color,-3);
}

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);
		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);
}

    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 0, 64, 64); }
function wait(w)
{
loop(w){yield;}
}
}