#東方弾幕風
#Title[蛍符「誘いの夜光」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "蛍符「誘いの夜光」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_wriggle.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st3bg1.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;

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

	let redlight=false;
	let bluelight=false;

	let bgx=0;
	let bgy=0;
    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	SetShotAutoDeleteClip(32,32,32,32);
	StartSpellHistory(32);
        SetLife(700);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;
	bgx+=1;
	bgy-=1;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(32);
	loop(20)
	{
		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,bgy,1280+bgx,960);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
	}

    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	shot;
	light;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
        SetDamageRate(25, 25);
}




sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	let wIni = 60;
	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 light
{
	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, 241);
	Obj_SetAlpha(obj,0);
	Obj_SetCollisionToPlayer(obj,false);
	ObjShot_SetBombResist(obj,true);
	let delay=20;
	wait(120);
loop
{
	redlight=true;
	loop(40)
	{
		ObjShot_SetDelay(obj, delay);
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		yield;
		delay+=0.5;
	}
	loop(60)
	{
		ObjShot_SetDelay(obj, 40);
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		yield;
    	}
redlight=false;
	loop(30)
	{
		ObjShot_SetDelay(obj, 40);
		yield;
    	}
wait(140);
delay=20;
ObjShot_SetGraphic(obj, 246);
	bluelight=true;
	loop(40)
	{
		ObjShot_SetDelay(obj, delay);
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		yield;
		delay+=0.5;
	}
	loop(60)
	{
		ObjShot_SetDelay(obj, 40);
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		yield;
    	}
bluelight=false;
	loop(30)
	{
		ObjShot_SetDelay(obj, 40);
		yield;
    	}
wait(140);
delay=20;
ObjShot_SetGraphic(obj, 241);
}
}

task shot
{
loop
{
ascent(let i in 0..90)
{
bugshot(GetX,GetY,rand(2,5),rand(0,360),105,5);
yield;
}
wait(180);
ascent(let i in 0..90)
{
bugshot(GetX,GetY,rand(2,5),rand(0,360),110,5);
yield;
}
wait(180);
}
}

task bugshot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count2=0;
	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);
	while(!Obj_BeDeleted(obj) && graphic==105)
	{
	while(redlight==true)
	{
		speed=0;
		loop(60)
		{
			angle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetAngle(obj,angle);
			Obj_SetSpeed(obj, speed);
			speed+=0.5/60;
			yield;
		}
		break;
	}
	while(redlight==true)
	{
		speed=0.5;
		angle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
		Obj_SetAngle(obj,angle);
		Obj_SetSpeed(obj, speed);
		count=1;
		yield;
	}
	if(count==1)
	{
		if(count2==0)
		{
			wait(30);
			count2=1;
		}
		Obj_SetSpeed(obj, speed);
		speed+=0.03;
	}
	yield;
	}

	while(!Obj_BeDeleted(obj) && graphic==110)
	{
	while(bluelight==true)
	{
		speed=0;
		loop(60)
		{
			angle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetAngle(obj,angle);
			Obj_SetSpeed(obj, speed);
			speed+=0.5/60;
			yield;
		}
		break;
	}
	while(bluelight==true)
	{
		speed=0.5;
		angle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
		Obj_SetAngle(obj,angle);
		Obj_SetSpeed(obj, speed);
		count=1;
		yield;
	}
	if(count==1)
	{
		if(count2==0)
		{
			wait(30);
			count2=1;
		}
		Obj_SetSpeed(obj, speed);
		speed+=0.03;
	}
	yield;
	}

}


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