#東方弾幕風
#Title[命符「北斗星君の書-Extra」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "命符「北斗星君の書-Extra」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_eiki.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
    let imgBG  = csd ~ "..\img\st6bg1.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 bgy=0;

    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(126);
        SetLife(1000);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

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


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

	DrawSpellHistory;
    }

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

	}

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

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




sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, wIni);
	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(240);
loop
{
let angle=rand(0,360);
	ascent(let i in 0..45)
	{
	//	CreateShot01(GetX,GetY,1.5,angle+GetAngleToPlayer+i*10,164,5);
		CreateShot01ToItem(GetX,GetY,2.5,angle+GetAngleToPlayer+i*9,164,5);
	}
	wait(5);
}
}

task Summon
{
let w=15;
	ascent(let i in 0..7)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,i,0,200-w*i);
		if(i==5)
		{
		CreateEnemyFromScript("Familiar", GetX,GetY,i+2,0,200-w*i);
		}
		wait(w);
	}
}


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

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let star=GetSpeed;
	let x=[];
	let y=[];
	let x=[GetX-150,GetX-120,GetX-80,GetX-70,GetX+0,GetX+70,GetX+150,GetX+75];
	let y=[GetY,GetY-50,GetY-45,GetY+20,GetY+60,GetY+90,GetY+70,GetY+95];
    @Initialize {
        SetLife(100);
	SetDamageRateEx(100,100,50,10);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
	SetGraphicAngle(0,0,angle);
	SetGraphicScale(0.8,0.8)
    }

    task TMain {
        yield;
	shot;
	move;
    }

task move
{
	SetMovePositionHermite(x[star],y[star],100,0,100,0,60)
}

task shot
{
LshotFire;
wait(num);
loop
{
let angle=rand(0,360);
	ascent(let i in 0..8)
	{
		CreateLaserA(0,GetX,GetY,500,30,161,60);		
		SetLaserDataA(0,0,angle+45*i,0,0,0,0);
		SetShotKillTime(0,180);
		FireShot(0);
	}
wait(180);
}
wait(60);
VanishEnemy;
}

task LshotFire
{
let t=0;
loop
{
	Lshot(GetX,GetY,t%7+41);
	wait(3);
	t++;
}
}

task Lshot(x,y,color)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	//Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, color);
	ObjShot_SetDelay(obj, 5);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,150);
	ObjShot_SetBombResist(obj,true);
	loop(5)
	{
		ObjShot_SetDelay(obj, 3);
		yield;
	}
	Obj_Delete(obj);
}


function wait(w)
{
loop(w){yield;}
}
}

