#東方弾幕風
#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\FlowerShot.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(80);

        SetLife(900);
        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(80);
	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,1920+bgy);
		SetGraphicAngle(0,0,0);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	


	}

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

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

task summon
{
let rangle=rand(0,360);
loop(1)
{
	ascent(let i in 0..6)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,3,i*60, 1);
	}
	wait(120);
	ascent(let i in 0..6)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,3,i*60, 1);
	}
}
}


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


#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\FlowerShot.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
	let IniX=GetPlayerX;
	let IniY=GetPlayerY;

    @Initialize {
        SetLife(10000);
	SetDamageRateEx(100,100,100,1);
	TMain;
    }

    @MainLoop {
        yield;
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 1);
    }

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

    task TMain {
        yield;
	shot;
	move;
	Effect;
    }

task move
{
SetAngle(angle);
SetSpeed(speed);
wait(30);

let r=0;
loop
{
r=0;
IniX=GetPlayerX;
IniY=GetPlayerY;
SetMovePositionHermite(GetPlayerX,GetPlayerY,300,angle,0,0,120);
wait(120);
loop(120)
{
	SetX(IniX+r*cos(angle));
	SetY(IniY+r*sin(angle));
	if(r<120)
	{
	r+=1;
	}
	yield;
	angle+=1*num;
}
}
VanishEnemy;
}

task shot
{
wait(30);
loop
{
wait(120);
loop(30)
{

//	CreateShot01(GetX,GetY,1,atan2(IniY-GetY,IniX-GetX),164,10);
	CreateShot01ToItem(GetX,GetY,1,atan2(IniY-GetY,IniX-GetX),164,10);
	wait(4);
}
}
}

task Effect
{
loop
{
	Lshot(GetX,GetY,47);
	wait(2);
}
}

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, 5);
		yield;
	}
	Obj_Delete(obj);
}

#include_function ".\..\txt/StageEnemydata.txt"
}
