#東方弾幕風
#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 {
    LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(13);
        SetLife(800);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        LoadGraphic(imgBlind);
        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,0,0);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

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

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

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

task Blind
{
		let x=GetPlayerX;
		let y=GetPlayerY;
		let scax=22;
		let scay=22;

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


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 Shot
{
wait(60);
loop
{
	let angle=GetAngleToPlayer;
	ascent(let i in 0..7)
	{
		CreateShot01(GetX,GetY,1.5+i*0.5,angle,PURPLE02,10);
		CreateShot01(GetX,GetY,1.5+i*0.5,angle+30,PURPLE02,10);
		CreateShot01(GetX,GetY,1.5+i*0.5,angle-30,PURPLE02,10);
		wait(15);
	}
	wait(120);
}
}

task SubShot
{
wait(60);
let r=15;
loop
{
	let angle=GetAngleToPlayer+rand(-3,3);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle-45, 1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle+45, 1);
	wait(60);

	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle-60, -1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle+60, -1);
	wait(60);
}
}


#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;
	let color1=GREEN21;
	let color2=PURPLE21;
    @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
{
wait(5);
	
loop
{
	ascent(let i in -1..2)
	{
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,angle+90,0,0,0,RED02);
		SetShotDataA(1,120+10*i,1.5,NULL,0,0,0,81);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,angle-90,0,0,0,BLUE02);
		SetShotDataA(1,120+10*i,1.5,NULL,0,0,0,86);
		FireShot(1);
	}
wait(20);
}
}


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