#東方弾幕風
#Title[夜符「ナイトプラトーン」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "夜符「ナイトプラトーン」";
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(12);
        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(12);
	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..5)
	{
	//	CreateShot01(GetX,GetY,2+i*0.5,angle,PURPLE02,10);
		CreateShotFromScript( "shot1",GetX, GetY,2+i*0.5, angle, 10, PURPLE02);
		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, 3);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle+45, 3);
	wait(120);
}
}


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

#include_script ".\..\txt/EnemyShotData.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
{
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);
*/		ShotPla(GetX,GetY,1.5,angle+90,30,RED02,81,120+10*i);
		ShotPla(GetX,GetY,1.5,angle-90,30,BLUE02,86,120+10*i);
	}
wait(20);
}
}

task ShotPla(let x,let y,let speed,let angle,let delay,let graphic,let graphic2,let shotdelay)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, 0);
	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(shotdelay)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, speed);
	ObjShot_SetGraphic(obj, graphic2);
	while(!Obj_BeDeleted(obj))
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

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

}