#東方弾幕風
#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";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;
	let Bonus;
	let DBonusItem;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","Normal"))
	case("Easy")
	{
		DBonusItem=1;
	}
	case("Normal")
	{
		DBonusItem=2;
	}
	case("Hard")
	{
		DBonusItem=3;
	}
	case("Lunatic")
	{
		DBonusItem=4;
	}
	let StandardSpellBonus=GetCommonDataDefault("BONUSPOINT",10000)*(20*DBonusItem+20*GetCommonDataDefault("STAGEPROGRESS",2));
	let SpellTimer=50;
	let SpellBonus=StandardSpellBonus/3;

    @Initialize {
	SetShotAutoDeleteClip(32,32,32,32);
	StartSpellHistory(15);
    LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(1600);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
	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);
	}
    }

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

task Trate
{
	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,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; }
}
}