#東方弾幕風
#Title[命符「北斗星君の書」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "命符「北斗星君の書」";
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(84);
        SetLife(800);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

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


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

	DrawSpellHistory;
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(84);
	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);	
		bgy+=3;
	}

    // メインタスク
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..36)
	{
		CreateShot01(GetX,GetY,1.5,angle+GetAngleToPlayer+i*10,164,5);
	}
	wait(20);
}
}

task Summon
{
let w=15;
	ascent(let i in 0..7)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,i,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];
	let y=[GetY,GetY-50,GetY-45,GetY+20,GetY+60,GetY+90,GetY+70];
    @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..6)
	{
		CreateLaserA(0,GetX,GetY,500,30,161,60);		
		SetLaserDataA(0,0,angle+60*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);
	loop(5)
	{
		ObjShot_SetDelay(obj, 3);
		yield;
	}
	Obj_Delete(obj);
}


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

