#東方弾幕風
#Title[鳥符「ヒューマンケージ-Easy」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "鳥符「ヒューマンケージ-Easy」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mystia.png"; 
    let imgFam  = csd ~ "..\img\familiar.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);
	StartSpellHistory(15);
    LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(1600);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        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(15);
	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;
}

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


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
{
let r=15;
loop
{
	CreateEnemyFromScript("Familiar", GetX, GetY,0,GetAngleToPlayer+180, 3);
	CreateEnemyFromScript("Familiar", GetX, GetY,0,GetAngleToPlayer+180, 2);
	CreateEnemyFromScript("Familiar", GetX, GetY,0,GetAngleToPlayer+180, 1);
	CreateEnemyFromScript("Familiar", GetX, GetY,0,GetAngleToPlayer+180, -3);
	CreateEnemyFromScript("Familiar", GetX, GetY,0,GetAngleToPlayer+180, -2);
	CreateEnemyFromScript("Familiar", GetX, GetY,0,GetAngleToPlayer+180, -1);
	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=2;
    @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;
	move;
	shot;
    }

task move
{
let x=GetX;
let y=GetY;
let px=GetPlayerX;
let py=GetPlayerY;
let r=((px-x)^2+(py-y)^2)^0.5;
let pangle=atan2(py-y,px-x)-90;
angle=-90;


loop(120)
{
SetX(px+r*-num/3*cos(pangle)*cos(angle)-r*sin(pangle)*sin(angle));
SetY(py+r*-num/3*sin(pangle)*cos(angle)+r*cos(pangle)*sin(angle));
angle+=1.5;
yield;
}
	SetSpeed(2);
	SetAngle(pangle+90+num*20);
}


task shot
{
wait(20);
let i=0;
loop(12)
{
		CreateShotA(1,GetX,GetY,30);
		SetShotDirectionType(PLAYER);
		SetShotDataA(1,0,0,0,0,0,0,RED05);
		SetShotDataA(1,120-i-absolute(num)*10,2,0,0,0,0,RED21);
		SetShotDirectionType(ABSOLUTE);
		FireShot(1);
i+=10;

wait(10);
}
loop
{
CreateShot01(GetX,GetY,rand(2,3),rand(0,360),PURPLE01,5);
wait(3);
}
}


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