#東方弾幕風
#Title[環符「フェアリーサークル-Extra」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "環符「フェアリーサークル-Extra」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_daiyousei.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st1bg1.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 {
	StartSpellHistory(105);

        SetLife(900);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
       LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

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

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

    @Finalize {
        DeleteGraphic(imgBoss);
        DeleteGraphic(imgBG);
	EndSpellHistory(105);
	loop(10)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,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(25, 25);
}




sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	let wIni = 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 w=3;
let r=90;
loop
{
r=90;
let angle=rand(0,360);
let angle2=angle-180;
	ascent(let bw in 0..24)
	{
		ascent(let i in 0..6)
		{
		ShotCircle(GetX+r*cos(angle)+r*cos(angle2),GetY+r*sin(angle)+r*sin(angle2),1,GetAngleToPlayer+rand(-120,120),30,210-w*bw,RED01);
		angle+=60;
		angle2+=60;
		}
		wait(w);
		angle2+=10;
	}
angle+=30;
angle2=angle-180;

	ascent(let bw in 0..24)
	{
		ascent(let i in 0..6)
		{
		ShotCircle(GetX+r*cos(angle)+r*cos(angle2),GetY+r*sin(angle)+r*sin(angle2),1,GetAngleToPlayer+rand(-120,120),30,138-w*bw,BLUE01);
		angle+=60;
		angle2+=60;
		}
		wait(w);
		angle2-=10;
	}
r=70;
let angle=rand(0,360);
let angle2=angle-180;
	ascent(let bw in 0..24)
	{
		ascent(let i in 0..6)
		{
		ShotCircle(GetX+r*cos(angle)+r*cos(angle2),GetY+r*sin(angle)+r*sin(angle2),1,GetAngleToPlayer+rand(-120,120),30,210-w*bw,RED01);
		angle+=60;
		angle2+=60;
		}
		wait(w);
		angle2+=10;
	}
angle+=30;
angle2=angle-180;

	ascent(let bw in 0..24)
	{
		ascent(let i in 0..6)
		{
		ShotCircle(GetX+r*cos(angle)+r*cos(angle2),GetY+r*sin(angle)+r*sin(angle2),1,GetAngleToPlayer+rand(-120,120),30,138-w*bw,BLUE01);
		angle+=60;
		angle2+=60;
		}
		wait(w);
		angle2-=10;
	}

}
}

task ShotCircle(let x,let y,let speed,let angle,let delay,let stopframe,let graphic)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	loop(stopframe+delay)
	{
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, speed);
	while(!Obj_BeDeleted(obj))
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);	
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

#include_function ".\..\txt\data.txt"
#include_function ".\..\txt\Spelldata.txt"
#include_function ".\..\lib/lib_anime_Daiyousei.txt"
}
