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

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


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(210);
}
}

task SubShot
{
loop
{
ascent(let i in 0..8)
{
//CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*45,PURPLE03,30);
CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+i*45, 30, PURPLE03);
}
wait(150);
}
}

#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=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(15);
let i=0;
loop(17)
{
/*		CreateShotA(1,GetX,GetY,30);
		SetShotDirectionType(PLAYER);
		SetShotDataA(1,0,0,0,0,0,0,RED05);
		SetShotDataA(1,150-i-absolute(num)*10,2,0,0,0,0,RED21);
		SetShotDirectionType(ABSOLUTE);
		FireShot(1);
*/		ShotCage(GetX,GetY,2,RED05,RED21,30,150-i-absolute(num)*10);
i+=7;

wait(7);
}
wait(20);
loop
{
//CreateShot01(GetX,GetY,rand(2,3),rand(0,360),PURPLE01,5);
CreateShotFromScript( "shot1",GetX, GetY, rand(2,3), rand(0,360), 5, PURPLE01);
wait(1);
}
}

task ShotCage(let x,let y,let speed,let graphic,let graphic2,let delay,let stopframe)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, 0);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	loop(stopframe+delay)
	{
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, speed);
	ObjShot_SetGraphic(obj, graphic2);
	Obj_SetAngle(obj, atan2(GetPlayerY-y,GetPlayerX-x));
	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"

}