#東方弾幕風
#Title[宵鳥「闇夜の鳥葬-Hard」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "宵鳥「闇夜の鳥葬-Hard」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mystia.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
    let imgBlind  = csd ~ "..\img\blind.png";
    let imgBG  = csd ~ "..\img\st2bg1.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 bgx=0;
	let bgy=0;
    @Initialize {
	SetShotAutoDeleteClip(32,32,32,32);
    LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(21);
        SetLife(900);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        LoadGraphic(imgBlind);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

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

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

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(21);
	loop(15)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(bgx,bgy,1280,960);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
	}

    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	Shot;
	Blind;
}

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


sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 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 Blind
{
		let x=GetPlayerX;
		let y=GetPlayerY;
		let scax=22;
		let scay=22;
		let angle=180;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBlind);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0,    0,    0);
		ObjEffect_SetVertexUV(obj, 1,    0,  448);
		ObjEffect_SetVertexUV(obj, 2,  384,    0);
		ObjEffect_SetVertexUV(obj, 3,  384,  448);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1, -192,  224);
		ObjEffect_SetVertexXY(obj, 2,  192, -224);
		ObjEffect_SetVertexXY(obj, 3,  192,  224);

		ObjEffect_SetLayer(obj,5);
		ObjEffect_SetRenderState(obj, MULTIPLY);
		ObjEffect_SetScale(obj, scax,scay);

		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ObjEffect_SetScale(obj, scax,scay);
			if(scax>=4)
			{
			scax-=0.1;
			scay-=0.1;
			}
			if(scax<4)
			{
				break;
			}
			yield;
		}
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ObjEffect_SetScale(obj, scax,scay);
			scax=5+cos(angle);
			scay=5+cos(angle);
			angle+=2;
			yield;
		}
}

task Shot
{
loop
{
	CreateEnemyFromScript("Familiar", rand(GetClipMinX+30,GetCenterX), GetClipMinY,2,rand(90,110), 0);
	CreateEnemyFromScript("Familiar", rand(GetCenterX,GetClipMaxX-30), GetClipMaxY,2,rand(270,290), 0);
	CreateEnemyFromScript("Familiar", GetClipMinX, rand(GetClipMinY+30,GetCenterY),2,rand(-20,0), 0);
	CreateEnemyFromScript("Familiar", GetClipMaxX,rand(GetCenterY,GetClipMaxY-30),2,rand(160,180), 0);
	wait(180);
	CreateEnemyFromScript("Familiar", rand(GetClipMaxX-30,GetCenterX), GetClipMinY,2,rand(70,90), 0);
	CreateEnemyFromScript("Familiar", rand(GetCenterX,GetClipMinX+30), GetClipMaxY,2,rand(250,270), 0);
	CreateEnemyFromScript("Familiar", GetClipMinX, rand(GetClipMaxY-30,GetCenterY),2,rand(0,20), 0);
	CreateEnemyFromScript("Familiar", GetClipMaxX,rand(GetCenterY,GetClipMinY+30),2,rand(180,200), 0);
	wait(180);
}
}


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


script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
    @Initialize {
        SetLife(2000);
        SetScore(10000);
        SetDamageRate(50, 50);
        SetTexture(imgFam);
        setGraphic;
	SetSpeed(speed);
	SetAngle(angle);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
	shot;
    }



task shot
{
loop
{
if(((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5>20)
{
/*		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,30,0,angle-90,0,0.01,1.5,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,30,0,angle+90,0,0.01,1.5,RED21);
		FireShot(1);

		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,40,0,angle-90,0,0.01,1.5,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,40,0,angle+90,0,0.01,1.5,RED21);
		FireShot(1);

		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,50,0,angle-90,0,0.01,1.5,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,50,0,angle+90,0,0.01,1.5,RED21);
		FireShot(1);
*/	ShotSky(GetX,GetY,0.01,1.5,angle-90,30,RED01,RED21,30);
	ShotSky(GetX,GetY,0.01,1.5,angle+90,30,RED01,RED21,30);
	ShotSky(GetX,GetY,0.01,1.5,angle-90,30,RED01,RED21,40);
	ShotSky(GetX,GetY,0.01,1.5,angle+90,30,RED01,RED21,40);
	ShotSky(GetX,GetY,0.01,1.5,angle-90,30,RED01,RED21,50);
	ShotSky(GetX,GetY,0.01,1.5,angle+90,30,RED01,RED21,50);
}

wait(15);
}
}

task ShotSky(let x,let y,let aspeed,let stopspeed,let angle,let delay,let graphic,let graphic2,let shotstop)
{
	let itemx=x;
	let itemy=y;
	let speed=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);

	loop(delay)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	loop(shotstop)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	ObjShot_SetGraphic(obj, graphic2);
	while(!Obj_BeDeleted(obj))
	{
		if(speed<stopspeed)
		{
		speed+=aspeed;
		}
		Obj_SetSpeed(obj, speed);
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"

}