#東方弾幕風
#Title[蝶符「バタフライテンペスト」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "蝶符「バタフライテンペスト」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_wriggle.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st3bg1.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 {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(36);
        SetLife(800);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        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,255,0);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(36);
	loop(20)
	{
		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+bgx,960);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
	}

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

task Trate
{
	while(OnBomb==true){yield;}
	wait(420);
        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=60;
loop
{
roundshot(RED05,BLUE05,1,8);
wait(64);
roundshot(GREEN05,YELLOW05,-1,8);
wait(64);
}
}

task roundshot(grf1,grf2,dir,w)
{
let rangle=rand(-2,2);
	ascent(let i in 0..16)
	{
	bugshot(GetX,GetY,2,0+i*7.5*dir,grf1,5,140-i*8,rangle);
	bugshot(GetX,GetY,2,60+i*7.5*dir,grf2,5,140-i*8,rangle);
	bugshot(GetX,GetY,2,120+i*7.5*dir,grf1,5,140-i*8,rangle);
	bugshot(GetX,GetY,2,180+i*7.5*dir,grf2,5,140-i*8,rangle);
	bugshot(GetX,GetY,2,240+i*7.5*dir,grf1,5,140-i*8,rangle);
	bugshot(GetX,GetY,2,300+i*7.5*dir,grf2,5,140-i*8,rangle);
	wait(w);
	}
}

task bugshot(let x, let y, let speed,let angle, let graphic, let delay,let w,let rangle)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	ObjShot_SetBombResist(obj,true);
	loop(120)
	{
		Obj_SetSpeed(obj, speed);
		speed-=2/120;
		yield;
    	}
	if(graphic==YELLOW05)
	{
		wait(w);
		Obj_SetSpeed(obj, 1.25);
		Obj_SetAngle(obj,angle-150+rangle);
		ObjShot_SetGraphic(obj, 107);
	}
	
	if(graphic==GREEN05)
	{
		wait(w+96);
		Obj_SetSpeed(obj, 1.25);
		Obj_SetAngle(obj, angle+150+rangle);
		ObjShot_SetGraphic(obj, 108);
	}

	if(graphic==BLUE05)
	{
		wait(w);
		Obj_SetSpeed(obj, 1.25);
		Obj_SetAngle(obj,angle-150+rangle);
		ObjShot_SetGraphic(obj, 110);
	}
	
	if(graphic==RED05)
	{
		wait(w+96);
		Obj_SetSpeed(obj, 1.25);
		Obj_SetAngle(obj, angle+150+rangle);
		ObjShot_SetGraphic(obj, 105);
	}
	ObjShot_SetBombResist(obj,false);
}

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