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

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(33);
	loop(20)
	{
		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(360);
        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(48);
roundshot(GREEN05,YELLOW05,-1,8);
wait(48);
}
}

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 dicspeed=speed;
	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-=dicspeed/120;
		yield;
    	}
	if(graphic==YELLOW05)
	{
		wait(w);
		Obj_SetSpeed(obj, 3.0);
		Obj_SetAngle(obj,angle-150+rangle);
		ObjShot_SetGraphic(obj, 107);
	}
	
	if(graphic==GREEN05)
	{
		wait(w+64);
		Obj_SetSpeed(obj, 3.0);
		Obj_SetAngle(obj, angle+150+rangle);
		ObjShot_SetGraphic(obj, 108);
	}

	if(graphic==BLUE05)
	{
		wait(w);
		Obj_SetSpeed(obj, 3.0);
		Obj_SetAngle(obj,angle-150+rangle);
		ObjShot_SetGraphic(obj, 110);
	}
	
	if(graphic==RED05)
	{
		wait(w+64);
		Obj_SetSpeed(obj, 3.0);
		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"
}
