#東方弾幕風
#Title[蛍符「誘いの夜光-Hard」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "蛍符「誘いの夜光-Hard」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_wriggle.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;
	let Bonus;
	let DBonusItem;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","Normal"))
	case("Easy")
	{
		DBonusItem=1;
	}
	case("Normal")
	{
		DBonusItem=2;
	}
	case("Hard")
	{
		DBonusItem=3;
	}
	case("Lunatic")
	{
		DBonusItem=4;
	}
	let StandardSpellBonus=GetCommonDataDefault("BONUSPOINT",10000)*(20*DBonusItem+20*GetCommonDataDefault("STAGEPROGRESS",2));
	let SpellTimer=50;
	let SpellBonus=StandardSpellBonus/3;

	let redlight=false;
	let bluelight=false;
    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	SetShotAutoDeleteClip(32,32,32,32);
	StartSpellHistory(37);
        SetLife(700);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(37);
	loop(20)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }

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

task Trate
{
	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(110);
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(110);
delay=20;
ObjShot_SetGraphic(obj, 241);
}
}

task shot
{
loop
{
pbug1;
pbug3;
wait(240);
pbug2;
pbug3;
wait(240);
}
}

task pbug1
{
ascent(let i in 0..90)
{
bugshot(GetX,GetY,rand(2,5),rand(0,360),105,5);
yield;
}
}


task pbug2
{
ascent(let i in 0..90)
{
bugshot(GetX,GetY,rand(2,5),rand(0,360),110,5);
yield;
}
}

task pbug3
{
	ascent(let j in 0..8)
	{
		ascent(let i in 0..6)
		{
			bugshot(GetX,GetY,0.5+i*0.2,j*45+22.5,112,5);
		}
	}
}

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.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.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"
}
